Compare commits

..

1 Commits
master ... 1.15

Author SHA1 Message Date
TheBrokenRail e19486d926 1.15.2 Port
SorceryCraft/pipeline/head This commit looks good Details
2020-06-24 13:05:39 -04:00
33 changed files with 210 additions and 238 deletions

2
API.md
View File

@ -8,7 +8,7 @@
} }
dependencies { dependencies {
modImplementation 'com.thebrokenrail:sorcerycraft:VERSION' modImplementation 'com.thebrokenrail:sorcerycraft:VERSION'
// VERSION = "<Mod Version>+<MC Version>", for example "1.2.4+20w12a" // VERSION = "<Mod Version>+<MC Version>", for example "1.2.4+1.15.2"
} }
``` ```
2. Add Dependency to ```fabric.mod.json``` 2. Add Dependency to ```fabric.mod.json```

View File

@ -1,5 +1,8 @@
# Changelog # Changelog
**1.15.2 Port**
* Tweak Steadfast Spell
**1.2.9** **1.2.9**
* Fix Dedicated Server Crash * Fix Dedicated Server Crash

14
Jenkinsfile vendored
View File

@ -7,7 +7,7 @@ pipeline {
stages { stages {
stage('Build') { stage('Build') {
steps { steps {
sh './gradlew build javadoc' sh './gradlew build javadoc publish'
} }
post { post {
success { success {
@ -24,17 +24,5 @@ pipeline {
} }
} }
} }
stage('Publish') {
when {
expression {
return sh(returnStdout: true, script: 'git tag --contains').trim().length() > 0
}
}
steps {
withCredentials([string(credentialsId: 'curseforge_key', variable: 'CURSEFORGE_KEY')]) {
sh './gradlew -Pcurseforge.api_key="${CURSEFORGE_KEY}" curseforge publish'
}
}
}
} }
} }

View File

@ -1,4 +1,6 @@
# SorceryCraft # SorceryCraft
**1.15.2 Port**
Cast Spells in Minecraft! Cast Spells in Minecraft!
This mod currently supports the Minecraft 1.16 snapshots. This mod currently supports the Minecraft 1.16 snapshots.

View File

@ -1,5 +1,5 @@
plugins { plugins {
id 'fabric-loom' version '0.4-SNAPSHOT' id 'fabric-loom' version '0.2.7-SNAPSHOT'
id 'com.matthewprenger.cursegradle' version '1.4.0' id 'com.matthewprenger.cursegradle' version '1.4.0'
id 'maven-publish' id 'maven-publish'
} }
@ -38,12 +38,12 @@ dependencies {
} }
processResources { processResources {
inputs.property 'version', project.version inputs.property 'version', mod_version
inputs.property 'name', rootProject.name inputs.property 'name', rootProject.name
from(sourceSets.main.resources.srcDirs) { from(sourceSets.main.resources.srcDirs) {
include 'fabric.mod.json' include 'fabric.mod.json'
expand 'version': project.version, 'name': rootProject.name expand 'version': mod_version, 'name': rootProject.name
} }
from(sourceSets.main.resources.srcDirs) { from(sourceSets.main.resources.srcDirs) {
@ -102,7 +102,7 @@ if (project.hasProperty('curseforge.api_key')) {
apiKey = project.getProperty('curseforge.api_key') apiKey = project.getProperty('curseforge.api_key')
project { project {
id = project.curseforge_id id = project.curseforge_id
changelog = 'A changelog can be found at https://gitea.thebrokenrail.com/TheBrokenRail/SorceryCraft/src/branch/master/CHANGELOG.md' changelog = 'A changelog can be found at https://gitea.thebrokenrail.com/TheBrokenRail/SorceryCraft/src/branch/1.15/CHANGELOG.md'
releaseType = 'release' releaseType = 'release'
addGameVersion project.simple_minecraft_version addGameVersion project.simple_minecraft_version
addGameVersion 'Fabric' addGameVersion 'Fabric'

View File

@ -3,11 +3,11 @@ org.gradle.jvmargs = -Xmx1G
# Fabric Properties # Fabric Properties
# check these on https://fabricmc.net/use # check these on https://fabricmc.net/use
minecraft_version = 1.16.4 minecraft_version = 1.15.2
curseforge_id = 365308 curseforge_id = 365308
simple_minecraft_version = 1.16.4 simple_minecraft_version = 1.15.2
yarn_build = 7 yarn_build = 15
fabric_loader_version = 0.10.8 fabric_loader_version = 0.7.8+build.189
# Mod Properties # Mod Properties
mod_version = 1.2.9 mod_version = 1.2.9
@ -16,7 +16,7 @@ org.gradle.jvmargs = -Xmx1G
# Dependencies # Dependencies
# currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api # currently not on the main fabric site, check on the maven: https://maven.fabricmc.net/net/fabricmc/fabric-api/fabric-api
fabric_api_version = 0.28.1+1.16 fabric_api_version = 0.5.1+build.294-1.15
cloth_config_version = 4.8.3 cloth_config_version = 2.13.4
auto_config_version = 3.3.1 auto_config_version = 2.0.1
mod_menu_version = 1.14.13+build.19 mod_menu_version = 1.10.2+build.32

View File

@ -22,11 +22,11 @@ import net.fabricmc.fabric.api.registry.CommandRegistry;
import net.fabricmc.fabric.impl.networking.ServerSidePacketRegistryImpl; import net.fabricmc.fabric.impl.networking.ServerSidePacketRegistryImpl;
import net.minecraft.block.DispenserBlock; import net.minecraft.block.DispenserBlock;
import net.minecraft.block.dispenser.ProjectileDispenserBehavior; import net.minecraft.block.dispenser.ProjectileDispenserBehavior;
import net.minecraft.entity.EntityCategory;
import net.minecraft.entity.EntityDimensions; import net.minecraft.entity.EntityDimensions;
import net.minecraft.entity.EntityType; import net.minecraft.entity.EntityType;
import net.minecraft.entity.SpawnGroup;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.projectile.ProjectileEntity; import net.minecraft.entity.projectile.Projectile;
import net.minecraft.item.BlockItem; import net.minecraft.item.BlockItem;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup; import net.minecraft.item.ItemGroup;
@ -34,7 +34,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.loot.BinomialLootTableRange; import net.minecraft.loot.BinomialLootTableRange;
import net.minecraft.loot.LootTables; import net.minecraft.loot.LootTables;
import net.minecraft.loot.entry.ItemEntry; import net.minecraft.loot.entry.ItemEntry;
import net.minecraft.loot.function.LootFunctionType; import net.minecraft.loot.function.LootFunctions;
import net.minecraft.sound.SoundCategory; import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvent; import net.minecraft.sound.SoundEvent;
import net.minecraft.sound.SoundEvents; import net.minecraft.sound.SoundEvents;
@ -111,7 +111,7 @@ public class SorceryCraft implements ModInitializer {
CASTING_TABLE_BLOCK_ITEM = new BlockItem(CASTING_TABLE_BLOCK, new Item.Settings().group(ITEM_GROUP)); CASTING_TABLE_BLOCK_ITEM = new BlockItem(CASTING_TABLE_BLOCK, new Item.Settings().group(ITEM_GROUP));
SPELL_ITEM = new SpellItem(); SPELL_ITEM = new SpellItem();
SPELL_ENTITY = FabricEntityTypeBuilder.create(SpawnGroup.MISC, (EntityType.EntityFactory<SpellEntity>) SpellEntity::new).size(EntityDimensions.fixed(0.25f, 0.25f)).build(); SPELL_ENTITY = FabricEntityTypeBuilder.create(EntityCategory.MISC, (EntityType.EntityFactory<SpellEntity>) SpellEntity::new).size(EntityDimensions.fixed(0.25f, 0.25f)).build();
Registry.register(Registry.ITEM, new Identifier(NAMESPACE, "spell"), SPELL_ITEM); Registry.register(Registry.ITEM, new Identifier(NAMESPACE, "spell"), SPELL_ITEM);
Registry.register(Registry.BLOCK, new Identifier(NAMESPACE, "casting_table"), CASTING_TABLE_BLOCK); Registry.register(Registry.BLOCK, new Identifier(NAMESPACE, "casting_table"), CASTING_TABLE_BLOCK);
@ -121,7 +121,7 @@ public class SorceryCraft implements ModInitializer {
ContainerProviderRegistry.INSTANCE.registerFactory(new Identifier(NAMESPACE, "casting_table"), (syncId, identifier, player, buf) -> { ContainerProviderRegistry.INSTANCE.registerFactory(new Identifier(NAMESPACE, "casting_table"), (syncId, identifier, player, buf) -> {
final World world = player.world; final World world = player.world;
final BlockPos pos = buf.readBlockPos(); final BlockPos pos = buf.readBlockPos();
return Objects.requireNonNull(world.getBlockState(pos).createScreenHandlerFactory(player.world, pos)).createMenu(syncId, player.inventory, player); return Objects.requireNonNull(world.getBlockState(pos).createContainerFactory(player.world, pos)).createMenu(syncId, player.inventory, player);
}); });
CommandRegistry.INSTANCE.register(false, SpellCommand::register); CommandRegistry.INSTANCE.register(false, SpellCommand::register);
@ -131,18 +131,18 @@ public class SorceryCraft implements ModInitializer {
LootTableLoadingCallback.EVENT.register((resourceManager, lootManager, id, supplier, setter) -> { LootTableLoadingCallback.EVENT.register((resourceManager, lootManager, id, supplier, setter) -> {
if (isSelectedLootTable(id)) { if (isSelectedLootTable(id)) {
FabricLootPoolBuilder poolBuilder = FabricLootPoolBuilder.builder() FabricLootPoolBuilder poolBuilder = FabricLootPoolBuilder.builder()
.rolls(new BinomialLootTableRange(2, 0.5f)) .withRolls(new BinomialLootTableRange(2, 0.5f))
.withEntry(ItemEntry.builder(SPELL_ITEM).build()) .withEntry(ItemEntry.builder(SPELL_ITEM))
.withFunction(new RandomSpellLootTableFunction.Builder().build()); .withFunction(new RandomSpellLootTableFunction.Builder());
supplier.withPool(poolBuilder.build()); supplier.withPool(poolBuilder);
} }
}); });
Registry.register(Registry.LOOT_FUNCTION_TYPE, new Identifier(NAMESPACE, "random_spell"), new LootFunctionType(new RandomSpellLootTableFunction.Factory())); LootFunctions.register(new RandomSpellLootTableFunction.Factory());
DispenserBlock.registerBehavior(SorceryCraft.SPELL_ITEM, new ProjectileDispenserBehavior() { DispenserBlock.registerBehavior(SorceryCraft.SPELL_ITEM, new ProjectileDispenserBehavior() {
@Override @Override
protected ProjectileEntity createProjectile(World position, Position stack, ItemStack itemStack) { protected Projectile createProjectile(World position, Position stack, ItemStack itemStack) {
SpellEntity entity = new SpellEntity(position, stack.getX(), stack.getY(), stack.getZ()); SpellEntity entity = new SpellEntity(position, stack.getX(), stack.getY(), stack.getZ());
entity.setItem(itemStack); entity.setItem(itemStack);
return entity; return entity;

View File

@ -1,11 +1,10 @@
package com.thebrokenrail.sorcerycraft.advancement; package com.thebrokenrail.sorcerycraft.advancement;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.thebrokenrail.sorcerycraft.SorceryCraft; import com.thebrokenrail.sorcerycraft.SorceryCraft;
import net.minecraft.advancement.criterion.AbstractCriterion; import net.minecraft.advancement.criterion.AbstractCriterion;
import net.minecraft.advancement.criterion.AbstractCriterionConditions; import net.minecraft.advancement.criterion.AbstractCriterionConditions;
import net.minecraft.predicate.entity.AdvancementEntityPredicateDeserializer;
import net.minecraft.predicate.entity.EntityPredicate;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
@ -15,23 +14,23 @@ public class CreateSpellCriterion extends AbstractCriterion<CreateSpellCriterion
public CreateSpellCriterion() { public CreateSpellCriterion() {
} }
@Override
protected Conditions conditionsFromJson(JsonObject obj, EntityPredicate.Extended playerPredicate, AdvancementEntityPredicateDeserializer predicateDeserializer) {
return new CreateSpellCriterion.Conditions(playerPredicate);
}
@Override @Override
public Identifier getId() { public Identifier getId() {
return ID; return ID;
} }
@Override
public Conditions conditionsFromJson(JsonObject obj, JsonDeserializationContext context) {
return new CreateSpellCriterion.Conditions();
}
public void trigger(ServerPlayerEntity player) { public void trigger(ServerPlayerEntity player) {
test(player, (conditions) -> true); test(player.getAdvancementTracker(), (conditions) -> true);
} }
public static class Conditions extends AbstractCriterionConditions { public static class Conditions extends AbstractCriterionConditions {
public Conditions(EntityPredicate.Extended player) { public Conditions() {
super(ID, player); super(ID);
} }
} }
} }

View File

@ -1,5 +1,6 @@
package com.thebrokenrail.sorcerycraft.advancement; package com.thebrokenrail.sorcerycraft.advancement;
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.thebrokenrail.sorcerycraft.SorceryCraft; import com.thebrokenrail.sorcerycraft.SorceryCraft;
import com.thebrokenrail.sorcerycraft.spell.api.Spell; import com.thebrokenrail.sorcerycraft.spell.api.Spell;
@ -7,8 +8,6 @@ import com.thebrokenrail.sorcerycraft.spell.api.registry.SpellRegistry;
import com.thebrokenrail.sorcerycraft.spell.util.SpellPlayerEntity; import com.thebrokenrail.sorcerycraft.spell.util.SpellPlayerEntity;
import net.minecraft.advancement.criterion.AbstractCriterion; import net.minecraft.advancement.criterion.AbstractCriterion;
import net.minecraft.advancement.criterion.AbstractCriterionConditions; import net.minecraft.advancement.criterion.AbstractCriterionConditions;
import net.minecraft.predicate.entity.AdvancementEntityPredicateDeserializer;
import net.minecraft.predicate.entity.EntityPredicate;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
@ -26,12 +25,12 @@ public class DiscoverAllSpellsCriterion extends AbstractCriterion<DiscoverAllSpe
} }
@Override @Override
protected DiscoverAllSpellsCriterion.Conditions conditionsFromJson(JsonObject obj, EntityPredicate.Extended playerPredicate, AdvancementEntityPredicateDeserializer predicateDeserializer) { public Conditions conditionsFromJson(JsonObject obj, JsonDeserializationContext context) {
return new DiscoverAllSpellsCriterion.Conditions(playerPredicate); return new DiscoverAllSpellsCriterion.Conditions();
} }
public void trigger(ServerPlayerEntity player) { public void trigger(ServerPlayerEntity player) {
test(player, (conditions) -> { test(player.getAdvancementTracker(), (conditions) -> {
SpellPlayerEntity spellPlayer = (SpellPlayerEntity) player; SpellPlayerEntity spellPlayer = (SpellPlayerEntity) player;
Map<Identifier, Integer> spells = spellPlayer.getDiscoveredSpells(); Map<Identifier, Integer> spells = spellPlayer.getDiscoveredSpells();
Spell[] maxSpells = SpellRegistry.getMaxSpells(); Spell[] maxSpells = SpellRegistry.getMaxSpells();
@ -47,8 +46,8 @@ public class DiscoverAllSpellsCriterion extends AbstractCriterion<DiscoverAllSpe
} }
public static class Conditions extends AbstractCriterionConditions { public static class Conditions extends AbstractCriterionConditions {
public Conditions(EntityPredicate.Extended player) { public Conditions() {
super(ID, player); super(ID);
} }
} }
} }

View File

@ -8,10 +8,10 @@ import net.fabricmc.fabric.api.container.ContainerProviderRegistry;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.block.Material; import net.minecraft.block.Material;
import net.minecraft.container.BlockContext;
import net.minecraft.container.NameableContainerFactory;
import net.minecraft.container.SimpleNamedContainerFactory;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.screen.NamedScreenHandlerFactory;
import net.minecraft.screen.ScreenHandlerContext;
import net.minecraft.screen.SimpleNamedScreenHandlerFactory;
import net.minecraft.text.TranslatableText; import net.minecraft.text.TranslatableText;
import net.minecraft.util.ActionResult; import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand; import net.minecraft.util.Hand;
@ -36,12 +36,12 @@ public class CastingTableBlock extends Block {
} }
@Override @Override
public NamedScreenHandlerFactory createScreenHandlerFactory(BlockState state, World world, BlockPos pos) { public NameableContainerFactory createContainerFactory(BlockState state, World world, BlockPos pos) {
return new SimpleNamedScreenHandlerFactory((i, playerInventory, playerEntity) -> { return new SimpleNamedContainerFactory((i, playerInventory, playerEntity) -> {
if (!playerEntity.getEntityWorld().isClient()) { if (!playerEntity.getEntityWorld().isClient()) {
((SpellServerPlayerEntity) playerEntity).sync(); ((SpellServerPlayerEntity) playerEntity).sync();
} }
return new CastingTableScreenHandler(i, playerInventory, ScreenHandlerContext.create(world, pos)); return new CastingTableScreenHandler(i, playerInventory, BlockContext.create(world, pos));
}, new TranslatableText("container." + SorceryCraft.NAMESPACE + ".casting_table")); }, new TranslatableText("container." + SorceryCraft.NAMESPACE + ".casting_table"));
} }
} }

View File

@ -17,7 +17,6 @@ import net.fabricmc.fabric.api.client.rendereregistry.v1.EntityRendererRegistry;
import net.fabricmc.fabric.api.client.screen.ScreenProviderRegistry; import net.fabricmc.fabric.api.client.screen.ScreenProviderRegistry;
import net.fabricmc.fabric.impl.networking.ClientSidePacketRegistryImpl; import net.fabricmc.fabric.impl.networking.ClientSidePacketRegistryImpl;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
import net.minecraft.text.LiteralText;
import net.minecraft.text.TranslatableText; import net.minecraft.text.TranslatableText;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.MathHelper;
@ -32,7 +31,7 @@ public class SorceryCraftClient implements ClientModInitializer {
GuiRegistry guiRegistry = AutoConfig.getGuiRegistry(ModConfig.class); GuiRegistry guiRegistry = AutoConfig.getGuiRegistry(ModConfig.class);
guiRegistry.registerAnnotationProvider((s, field, config, defaults, guiRegistryAccess) -> { guiRegistry.registerAnnotationProvider((s, field, config, defaults, guiRegistryAccess) -> {
ModConfig.UsePercentage bounds = field.getAnnotation(ModConfig.UsePercentage.class); ModConfig.UsePercentage bounds = field.getAnnotation(ModConfig.UsePercentage.class);
return Collections.singletonList(ConfigEntryBuilder.create().startIntSlider(new TranslatableText(s), MathHelper.ceil(Utils.getUnsafely(field, config, 0.0) * 100), MathHelper.ceil(bounds.min() * 100), MathHelper.ceil(bounds.max() * 100)).setDefaultValue(() -> MathHelper.ceil((double) Utils.getUnsafely(field, defaults) * 100)).setSaveConsumer((newValue) -> Utils.setUnsafely(field, config, newValue / 100d)).setTextGetter(integer -> new LiteralText(String.format("%d%%", integer))).build()); return Collections.singletonList(ConfigEntryBuilder.create().startIntSlider(s, MathHelper.ceil(Utils.getUnsafely(field, config, 0.0) * 100), MathHelper.ceil(bounds.min() * 100), MathHelper.ceil(bounds.max() * 100)).setDefaultValue(() -> MathHelper.ceil((double) Utils.getUnsafely(field, defaults) * 100)).setSaveConsumer((newValue) -> Utils.setUnsafely(field, config, newValue / 100d)).setTextGetter(integer -> String.format("%d%%", integer)).build());
}, field -> field.getType() == Double.TYPE || field.getType() == Double.class, ModConfig.UsePercentage.class); }, field -> field.getType() == Double.TYPE || field.getType() == Double.class, ModConfig.UsePercentage.class);
EntityRendererRegistry.INSTANCE.register(SorceryCraft.SPELL_ENTITY, (entityRenderDispatcher, context) -> new SpellEntityRenderer(entityRenderDispatcher)); EntityRendererRegistry.INSTANCE.register(SorceryCraft.SPELL_ENTITY, (entityRenderDispatcher, context) -> new SpellEntityRenderer(entityRenderDispatcher));

View File

@ -8,19 +8,18 @@ import com.thebrokenrail.sorcerycraft.spell.api.Spell;
import com.thebrokenrail.sorcerycraft.spell.util.SpellHelper; import com.thebrokenrail.sorcerycraft.spell.util.SpellHelper;
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
import net.minecraft.client.gui.screen.ingame.HandledScreen; import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.screen.ingame.ContainerScreen;
import net.minecraft.client.gui.widget.ButtonWidget; import net.minecraft.client.gui.widget.ButtonWidget;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.entity.player.PlayerInventory; import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.text.LiteralText;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText; import net.minecraft.text.TranslatableText;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.MathHelper;
@Environment(EnvType.CLIENT) @Environment(EnvType.CLIENT)
public class CastingTableScreen extends HandledScreen<CastingTableScreenHandler> { public class CastingTableScreen extends ContainerScreen<CastingTableScreenHandler> {
private static final Identifier TEXTURE = new Identifier("textures/gui/container/villager2.png"); private static final Identifier TEXTURE = new Identifier("textures/gui/container/villager2.png");
private int selectedIndex = 0; private int selectedIndex = 0;
private int indexStartOffset = 0; private int indexStartOffset = 0;
@ -28,17 +27,17 @@ public class CastingTableScreen extends HandledScreen<CastingTableScreenHandler>
public CastingTableScreen(CastingTableScreenHandler container, PlayerInventory inventory, Text title) { public CastingTableScreen(CastingTableScreenHandler container, PlayerInventory inventory, Text title) {
super(container, inventory, title); super(container, inventory, title);
backgroundWidth = 276; containerWidth = 276;
} }
@Override @Override
protected void drawForeground(MatrixStack matrixStack, int i, int j) { protected void drawForeground(int mouseX, int mouseY) {
int titleY = backgroundHeight - 94; int titleY = containerHeight - 94;
textRenderer.draw(matrixStack, title, (float) (49 + this.backgroundWidth / 2 - textRenderer.getWidth(title) / 2), 6.0F, 4210752); font.draw(title.asFormattedString(), (float) (49 + this.containerWidth / 2 - font.getStringWidth(title.asFormattedString()) / 2), 6.0F, 4210752);
textRenderer.draw(matrixStack, playerInventory.getDisplayName(), 107.0F, (float) titleY, 4210752); font.draw(playerInventory.getDisplayName().asFormattedString(), 107.0F, (float) titleY, 4210752);
Text spells = new TranslatableText("container." + SorceryCraft.NAMESPACE + ".spells"); String spells = new TranslatableText("container." + SorceryCraft.NAMESPACE + ".spells").getString();
textRenderer.draw(matrixStack, spells, (float) (5 - textRenderer.getWidth(spells) / 2 + 48), 6.0F, 4210752); font.draw(spells, (float) (5 - font.getStringWidth(spells) / 2 + 48), 6.0F, 4210752);
renderXPCost(matrixStack); renderXPCost();
} }
public void resetIndex() { public void resetIndex() {
@ -47,87 +46,87 @@ public class CastingTableScreen extends HandledScreen<CastingTableScreenHandler>
} }
@Override @Override
protected void drawBackground(MatrixStack matrixStack, float delta, int mouseX, int mouseY) { protected void drawBackground(float delta, int mouseX, int mouseY) {
RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F); RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F);
assert client != null; assert minecraft != null;
client.getTextureManager().bindTexture(TEXTURE); minecraft.getTextureManager().bindTexture(TEXTURE);
int i = (width - backgroundWidth) / 2; int i = (width - containerWidth) / 2;
int j = (height - backgroundHeight) / 2; int j = (height - containerHeight) / 2;
drawTexture(matrixStack, i, j, getZOffset(), 0.0F, 0.0F, backgroundWidth, backgroundHeight, 256, 512); blit(i, j, getBlitOffset(), 0.0F, 0.0F, containerWidth, containerHeight, 256, 512);
} }
@Override @Override
public void render(MatrixStack matrixStack, int mouseX, int mouseY, float delta) { public void render(int mouseX, int mouseY, float delta) {
renderBackground(matrixStack); renderBackground();
super.render(matrixStack, mouseX, mouseY, delta); super.render(mouseX, mouseY, delta);
drawMouseoverTooltip(matrixStack, mouseX, mouseY); drawMouseoverTooltip(mouseX, mouseY);
renderScrollbar(matrixStack); renderScrollbar();
renderItems(); renderItems();
for (WidgetButtonPage button : buttons) { for (WidgetButtonPage button : buttons) {
if (button.isHovered()) { if (button.isHovered()) {
button.renderToolTip(matrixStack, mouseX, mouseY); button.renderToolTip(mouseX, mouseY);
} }
button.visible = button.index < handler.getRecipes().length; button.visible = button.index < container.getRecipes().length;
if (button.visible) { if (button.visible) {
Spell spell = handler.getRecipes()[button.getIndex() + indexStartOffset]; Spell spell = container.getRecipes()[button.getIndex() + indexStartOffset];
button.setMessage(SpellHelper.getTranslatedSpell(spell.getID(), spell.getLevel())); button.setMessage(SpellHelper.getTranslatedSpell(spell.getID(), spell.getLevel()).getString());
} }
} }
} }
private void renderScrollbar(MatrixStack matrixStack) { private void renderScrollbar() {
Spell[] spells = handler.getRecipes(); Spell[] spells = container.getRecipes();
assert client != null; assert minecraft != null;
client.getTextureManager().bindTexture(TEXTURE); minecraft.getTextureManager().bindTexture(TEXTURE);
int i = (width - backgroundWidth) / 2; int i = (width - containerWidth) / 2;
int j = (height - backgroundHeight) / 2; int j = (height - containerHeight) / 2;
int k = spells.length - 7; int k = spells.length - 7;
if (k > 0) { if (k > 0) {
int modifier = (int) (((float) indexStartOffset / k) * (1 + 139 - 27)); int modifier = (int) (((float) indexStartOffset / k) * (1 + 139 - 27));
drawTexture(matrixStack, i + 94, j + 18 + modifier, getZOffset(), 0.0F, 199.0F, 6, 27, 256, 512); blit(i + 94, j + 18 + modifier, getBlitOffset(), 0.0F, 199.0F, 6, 27, 256, 512);
} else { } else {
drawTexture(matrixStack, i + 94, j + 18, getZOffset(), 6.0F, 199.0F, 6, 27, 256, 512); blit(i + 94, j + 18, getBlitOffset(), 6.0F, 199.0F, 6, 27, 256, 512);
} }
} }
private void renderItems() { private void renderItems() {
int i = (width - backgroundWidth) / 2; int i = (width - containerWidth) / 2;
int j = (height - backgroundHeight) / 2; int j = (height - containerHeight) / 2;
int k = j + 16 + 1; int k = j + 16 + 1;
Spell[] spells = handler.getRecipes(); Spell[] spells = container.getRecipes();
for (int x = 0; x < spells.length; x++) { for (int x = 0; x < spells.length; x++) {
if (!canScroll(spells.length) || (x >= indexStartOffset && x < 7 + indexStartOffset)) { if (!canScroll(spells.length) || (x >= indexStartOffset && x < 7 + indexStartOffset)) {
ItemStack itemStack = spells[x].getItemCost(); ItemStack itemStack = spells[x].getItemCost();
itemRenderer.zOffset = 100.0F; itemRenderer.zOffset = 100.0F;
int y = k + 2; int y = k + 2;
itemRenderer.renderInGuiWithOverrides(itemStack, i + 5 + 68, y); itemRenderer.renderGuiItem(itemStack, i + 5 + 68, y);
itemRenderer.renderGuiItemOverlay(textRenderer, itemStack, i + 5 + 68, y); itemRenderer.renderGuiItemOverlay(font, itemStack, i + 5 + 68, y);
itemRenderer.zOffset = 0.0F; itemRenderer.zOffset = 0.0F;
k += 20; k += 20;
} }
} }
} }
private void renderXPCost(MatrixStack matrixStack) { private void renderXPCost() {
if (handler.getRecipes().length > 0) { if (container.getRecipes().length > 0) {
int cost = handler.getRecipes()[selectedIndex].getXPCost(); int cost = container.getRecipes()[selectedIndex].getXPCost();
int color = 8453920; int color = 8453920;
assert client != null; assert minecraft != null;
assert client.player != null; assert minecraft.player != null;
Text string = new TranslatableText("container.repair.cost", cost); String string = new TranslatableText("container.repair.cost", cost).getString();
if (!handler.canTakeResult(playerInventory.player)) { if (!container.canTakeResult(playerInventory.player)) {
color = 16736352; color = 16736352;
} }
int x2 = backgroundWidth - 8; int x2 = containerWidth - 8;
int x1 = x2 - textRenderer.getWidth(string); int x1 = x2 - font.getStringWidth(string);
fill(matrixStack, x1, 65, x2, 77, 1325400064); fill(x1, 65, x2, 77, 1325400064);
textRenderer.drawWithShadow(matrixStack, string, (float) x1, 67.0F, color); font.drawWithShadow(string, (float) x1, 67.0F, color);
} }
} }
@ -137,7 +136,7 @@ public class CastingTableScreen extends HandledScreen<CastingTableScreenHandler>
@Override @Override
public boolean mouseScrolled(double d, double e, double amount) { public boolean mouseScrolled(double d, double e, double amount) {
int i = handler.getRecipes().length; int i = container.getRecipes().length;
if (canScroll(i)) { if (canScroll(i)) {
int j = i - 7; int j = i - 7;
indexStartOffset = (int) ((double) indexStartOffset - amount); indexStartOffset = (int) ((double) indexStartOffset - amount);
@ -149,7 +148,7 @@ public class CastingTableScreen extends HandledScreen<CastingTableScreenHandler>
@Override @Override
public boolean mouseDragged(double mouseX, double mouseY, int button, double deltaX, double deltaY) { public boolean mouseDragged(double mouseX, double mouseY, int button, double deltaX, double deltaY) {
int i = handler.getRecipes().length; int i = container.getRecipes().length;
if (scrolling) { if (scrolling) {
int j = y + 18; int j = y + 18;
int k = j + 139; int k = j + 139;
@ -166,9 +165,9 @@ public class CastingTableScreen extends HandledScreen<CastingTableScreenHandler>
@Override @Override
public boolean mouseClicked(double mouseX, double mouseY, int button) { public boolean mouseClicked(double mouseX, double mouseY, int button) {
scrolling = false; scrolling = false;
int i = (width - backgroundWidth) / 2; int i = (width - containerWidth) / 2;
int j = (height - backgroundHeight) / 2; int j = (height - containerHeight) / 2;
if (canScroll(handler.getRecipes().length) && mouseX > (double) (i + 94) && mouseX < (double) (i + 94 + 6) && mouseY > (double) (j + 18) && mouseY <= (double) (j + 18 + 139 + 1)) { if (canScroll(container.getRecipes().length) && mouseX > (double) (i + 94) && mouseX < (double) (i + 94 + 6) && mouseY > (double) (j + 18) && mouseY <= (double) (j + 18 + 139 + 1)) {
scrolling = true; scrolling = true;
} }
@ -176,9 +175,9 @@ public class CastingTableScreen extends HandledScreen<CastingTableScreenHandler>
} }
private void syncRecipeIndex() { private void syncRecipeIndex() {
handler.setIndex(selectedIndex); container.setIndex(selectedIndex);
assert client != null; assert minecraft != null;
SelectSpellC2SPacket.send(client, selectedIndex); SelectSpellC2SPacket.send(minecraft, selectedIndex);
} }
private final WidgetButtonPage[] buttons = new WidgetButtonPage[7]; private final WidgetButtonPage[] buttons = new WidgetButtonPage[7];
@ -186,8 +185,8 @@ public class CastingTableScreen extends HandledScreen<CastingTableScreenHandler>
@Override @Override
protected void init() { protected void init() {
super.init(); super.init();
int i = (width - backgroundWidth) / 2; int i = (width - containerWidth) / 2;
int j = (height - backgroundHeight) / 2; int j = (height - containerHeight) / 2;
int k = j + 16 + 2; int k = j + 16 + 2;
for (int l = 0; l < 7; ++l) { for (int l = 0; l < 7; ++l) {
@ -200,32 +199,37 @@ public class CastingTableScreen extends HandledScreen<CastingTableScreenHandler>
} }
@Environment(EnvType.CLIENT) @Environment(EnvType.CLIENT)
public class WidgetButtonPage extends ButtonWidget { private class WidgetButtonPage extends ButtonWidget {
final int index; final int index;
public WidgetButtonPage(int i, int j, int k, PressAction pressAction) { public WidgetButtonPage(int i, int j, int k, PressAction pressAction) {
super(i, j, 89, 20, new LiteralText(""), pressAction); super(i, j, 89, 20, "", pressAction);
index = k; index = k;
visible = false; visible = false;
} }
@Override @Override
public void render(MatrixStack matrixStack, int mouseX, int mouseY, float delta) { public void render(int mouseX, int mouseY, float delta) {
active = (index + CastingTableScreen.this.indexStartOffset) != CastingTableScreen.this.selectedIndex; active = (index + CastingTableScreen.this.indexStartOffset) != CastingTableScreen.this.selectedIndex;
super.render(matrixStack, mouseX, mouseY, delta); super.render(mouseX, mouseY, delta);
} }
public int getIndex() { public int getIndex() {
return this.index; return this.index;
} }
public void renderToolTip(MatrixStack matrixStack, int mouseX, int mouseY) { public void renderToolTip(int mouseX, int mouseY) {
if (hovered && handler.getRecipes().length > index + indexStartOffset && mouseX > this.x + 65) { if (isHovered && container.getRecipes().length > index + indexStartOffset && mouseX > this.x + 65) {
ItemStack itemStack = handler.getRecipes()[index + indexStartOffset].getItemCost(); ItemStack itemStack = container.getRecipes()[index + indexStartOffset].getItemCost();
if (!itemStack.isEmpty()) { if (!itemStack.isEmpty()) {
renderTooltip(matrixStack, itemStack, mouseX, mouseY); renderTooltip(itemStack, mouseX, mouseY);
} }
} }
} }
@Override
public void drawCenteredString(TextRenderer font, String str, int centerX, int y, int color) {
drawString(font, str, x + 5, y, color);
}
} }
} }

View File

@ -14,7 +14,7 @@ import com.mojang.brigadier.suggestion.SuggestionsBuilder;
import com.thebrokenrail.sorcerycraft.SorceryCraft; import com.thebrokenrail.sorcerycraft.SorceryCraft;
import com.thebrokenrail.sorcerycraft.spell.api.Spell; import com.thebrokenrail.sorcerycraft.spell.api.Spell;
import com.thebrokenrail.sorcerycraft.spell.api.registry.SpellRegistry; import com.thebrokenrail.sorcerycraft.spell.api.registry.SpellRegistry;
import net.minecraft.command.CommandSource; import net.minecraft.server.command.CommandSource;
import net.minecraft.server.command.ServerCommandSource; import net.minecraft.server.command.ServerCommandSource;
import net.minecraft.text.TranslatableText; import net.minecraft.text.TranslatableText;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;

View File

@ -8,7 +8,7 @@ import com.thebrokenrail.sorcerycraft.spell.api.Spell;
import com.thebrokenrail.sorcerycraft.spell.api.registry.SpellRegistry; import com.thebrokenrail.sorcerycraft.spell.api.registry.SpellRegistry;
import com.thebrokenrail.sorcerycraft.spell.util.SpellHelper; import com.thebrokenrail.sorcerycraft.spell.util.SpellHelper;
import com.thebrokenrail.sorcerycraft.spell.util.SpellPlayerEntity; import com.thebrokenrail.sorcerycraft.spell.util.SpellPlayerEntity;
import net.minecraft.command.argument.EntityArgumentType; import net.minecraft.command.arguments.EntityArgumentType;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.server.command.CommandManager; import net.minecraft.server.command.CommandManager;

View File

@ -9,7 +9,7 @@ import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType; import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity; import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.projectile.thrown.ThrownItemEntity; import net.minecraft.entity.thrown.ThrownItemEntity;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.network.Packet; import net.minecraft.network.Packet;
import net.minecraft.network.packet.s2c.play.EntitySpawnS2CPacket; import net.minecraft.network.packet.s2c.play.EntitySpawnS2CPacket;
@ -52,7 +52,6 @@ public class SpellEntity extends ThrownItemEntity {
@Override @Override
protected void onCollision(HitResult hitResult) { protected void onCollision(HitResult hitResult) {
super.onCollision(hitResult);
if (!getEntityWorld().isClient()) { if (!getEntityWorld().isClient()) {
Map<Identifier, Integer> spells = SpellHelper.getSpells(getItem()); Map<Identifier, Integer> spells = SpellHelper.getSpells(getItem());
if (!spells.containsKey(Spells.INWARD_SPELL)) { if (!spells.containsKey(Spells.INWARD_SPELL)) {

View File

@ -5,16 +5,16 @@ import com.thebrokenrail.sorcerycraft.spell.api.Spell;
import com.thebrokenrail.sorcerycraft.spell.util.SpellPlayerEntity; import com.thebrokenrail.sorcerycraft.spell.util.SpellPlayerEntity;
import com.thebrokenrail.sorcerycraft.spell.api.registry.SpellRegistry; import com.thebrokenrail.sorcerycraft.spell.api.registry.SpellRegistry;
import com.thebrokenrail.sorcerycraft.spell.util.SpellHelper; import com.thebrokenrail.sorcerycraft.spell.util.SpellHelper;
import net.minecraft.container.BlockContext;
import net.minecraft.container.Container;
import net.minecraft.container.ContainerType;
import net.minecraft.container.Slot;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.player.PlayerInventory; import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.inventory.BasicInventory;
import net.minecraft.inventory.CraftingResultInventory; import net.minecraft.inventory.CraftingResultInventory;
import net.minecraft.inventory.Inventory; import net.minecraft.inventory.Inventory;
import net.minecraft.inventory.SimpleInventory;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.screen.ScreenHandler;
import net.minecraft.screen.ScreenHandlerContext;
import net.minecraft.screen.ScreenHandlerType;
import net.minecraft.screen.slot.Slot;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
@ -25,17 +25,17 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.function.BiConsumer; import java.util.function.BiConsumer;
public class CastingTableScreenHandler extends ScreenHandler { public class CastingTableScreenHandler extends Container {
private final Inventory inventory; private final Inventory inventory;
private final Inventory result; private final Inventory result;
private Spell[] spells = new Spell[0]; private Spell[] spells = new Spell[0];
private final ScreenHandlerContext context; private final BlockContext context;
private int index = 0; private int index = 0;
public CastingTableScreenHandler(int syncId, PlayerInventory playerInventory, ScreenHandlerContext blockContext) { public CastingTableScreenHandler(int syncId, PlayerInventory playerInventory, BlockContext blockContext) {
super(ScreenHandlerType.STONECUTTER, syncId); super(ContainerType.STONECUTTER, syncId);
inventory = new SimpleInventory(2) { inventory = new BasicInventory(2) {
public void markDirty() { public void markDirty() {
super.markDirty(); super.markDirty();
CastingTableScreenHandler.this.onContentChanged(this); CastingTableScreenHandler.this.onContentChanged(this);
@ -53,7 +53,7 @@ public class CastingTableScreenHandler extends ScreenHandler {
} }
@Override @Override
public int getMaxItemCount() { public int getMaxStackAmount() {
return 1; return 1;
} }
@ -91,8 +91,8 @@ public class CastingTableScreenHandler extends ScreenHandler {
} }
}); });
CastingTableScreenHandler.this.inventory.setStack(0, ItemStack.EMPTY); CastingTableScreenHandler.this.inventory.setInvStack(0, ItemStack.EMPTY);
CastingTableScreenHandler.this.inventory.removeStack(1, spells[index].getItemCost().getCount()); CastingTableScreenHandler.this.inventory.takeInvStack(1, spells[index].getItemCost().getCount());
return stack; return stack;
} }
}); });
@ -141,7 +141,7 @@ public class CastingTableScreenHandler extends ScreenHandler {
this.index = index; this.index = index;
onContentChanged(inventory); onContentChanged(inventory);
if (inventory.getStack(0).isEmpty() && inventory.getStack(1).isEmpty()) { if (inventory.getInvStack(0).isEmpty() && inventory.getInvStack(1).isEmpty()) {
ItemStack spellItem = new ItemStack(SorceryCraft.SPELL_ITEM); ItemStack spellItem = new ItemStack(SorceryCraft.SPELL_ITEM);
autoFill(0, spellItem, true); autoFill(0, spellItem, true);
ItemStack paymentItem = getRecipes()[index].getItemCost(); ItemStack paymentItem = getRecipes()[index].getItemCost();
@ -198,8 +198,8 @@ public class CastingTableScreenHandler extends ScreenHandler {
@Override @Override
public void onContentChanged(Inventory inventory) { public void onContentChanged(Inventory inventory) {
super.onContentChanged(inventory); super.onContentChanged(inventory);
ItemStack item = inventory.getStack(0); ItemStack item = inventory.getInvStack(0);
ItemStack cost = inventory.getStack(1); ItemStack cost = inventory.getInvStack(1);
if (inventory == this.inventory) { if (inventory == this.inventory) {
if (spells.length > 0 && if (spells.length > 0 &&
!item.isEmpty() && !item.isEmpty() &&
@ -211,9 +211,9 @@ public class CastingTableScreenHandler extends ScreenHandler {
resultSpells.put(spells[index].getID(), spells[index].getLevel()); resultSpells.put(spells[index].getID(), spells[index].getLevel());
} }
SpellHelper.setSpells(resultItem, resultSpells); SpellHelper.setSpells(resultItem, resultSpells);
result.setStack(2, resultItem); result.setInvStack(2, resultItem);
} else { } else {
result.setStack(2, ItemStack.EMPTY); result.setInvStack(2, ItemStack.EMPTY);
} }
} }
} }
@ -223,14 +223,14 @@ public class CastingTableScreenHandler extends ScreenHandler {
for (int i = 3; i < 39; ++i) { for (int i = 3; i < 39; ++i) {
ItemStack itemStack = slots.get(i).getStack(); ItemStack itemStack = slots.get(i).getStack();
if (!itemStack.isEmpty() && itemCompatible(stack, itemStack)) { if (!itemStack.isEmpty() && itemCompatible(stack, itemStack)) {
ItemStack invSlot = inventory.getStack(slot); ItemStack invSlot = inventory.getInvStack(slot);
int count = invSlot.isEmpty() ? 0 : invSlot.getCount(); int count = invSlot.isEmpty() ? 0 : invSlot.getCount();
int requiredCount = Math.min((onlyOne ? 1 : stack.getMaxCount()) - count, itemStack.getCount()); int requiredCount = Math.min((onlyOne ? 1 : stack.getMaxCount()) - count, itemStack.getCount());
ItemStack modifiedItem = itemStack.copy(); ItemStack modifiedItem = itemStack.copy();
int totalCount = count + requiredCount; int totalCount = count + requiredCount;
itemStack.decrement(requiredCount); itemStack.decrement(requiredCount);
modifiedItem.setCount(totalCount); modifiedItem.setCount(totalCount);
inventory.setStack(slot, modifiedItem); inventory.setInvStack(slot, modifiedItem);
if (totalCount >= stack.getMaxCount() || onlyOne) { if (totalCount >= stack.getMaxCount() || onlyOne) {
break; break;
} }

View File

@ -14,11 +14,11 @@ import net.minecraft.item.ItemGroup;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import net.minecraft.util.ActionResult; import net.minecraft.util.ActionResult;
import net.minecraft.util.DefaultedList;
import net.minecraft.util.Hand; import net.minecraft.util.Hand;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import net.minecraft.util.Rarity; import net.minecraft.util.Rarity;
import net.minecraft.util.TypedActionResult; import net.minecraft.util.TypedActionResult;
import net.minecraft.util.collection.DefaultedList;
import net.minecraft.world.World; import net.minecraft.world.World;
import java.util.HashMap; import java.util.HashMap;
@ -53,15 +53,15 @@ public class SpellItem extends Item {
} }
@Override @Override
public ActionResult useOnEntity(ItemStack stack, PlayerEntity user, LivingEntity entity, Hand hand) { public boolean useOnEntity(ItemStack stack, PlayerEntity user, LivingEntity entity, Hand hand) {
use(user.getEntityWorld(), user, hand); use(user.getEntityWorld(), user, hand);
return ActionResult.SUCCESS; return true;
} }
@Override @Override
public boolean hasGlint(ItemStack stack) { public boolean hasEnchantmentGlint(ItemStack stack) {
Map<Identifier, Integer> spells = SpellHelper.getSpells(stack); Map<Identifier, Integer> spells = SpellHelper.getSpells(stack);
return spells.size() > 0 || super.hasGlint(stack); return spells.size() > 0 || super.hasEnchantmentGlint(stack);
} }
@Override @Override
@ -97,7 +97,7 @@ public class SpellItem extends Item {
super.inventoryTick(stack, world, entity, slot, selected); super.inventoryTick(stack, world, entity, slot, selected);
if (!world.isClient() && entity instanceof PlayerEntity) { if (!world.isClient() && entity instanceof PlayerEntity) {
PlayerEntity player = (PlayerEntity) entity; PlayerEntity player = (PlayerEntity) entity;
Map<Identifier, Integer> itemSpells = SpellHelper.getSpells(player.inventory.getStack(slot)); Map<Identifier, Integer> itemSpells = SpellHelper.getSpells(player.inventory.getInvStack(slot));
SpellHelper.learnSpells(player, itemSpells); SpellHelper.learnSpells(player, itemSpells);
} }

View File

@ -1,11 +1,11 @@
package com.thebrokenrail.sorcerycraft.mixin; package com.thebrokenrail.sorcerycraft.mixin;
import net.minecraft.advancement.criterion.Criteria;
import net.minecraft.advancement.criterion.Criterion; import net.minecraft.advancement.criterion.Criterion;
import net.minecraft.advancement.criterion.Criterions;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Invoker; import org.spongepowered.asm.mixin.gen.Invoker;
@Mixin(Criteria.class) @Mixin(Criterions.class)
public interface CriteriaRegistryHook { public interface CriteriaRegistryHook {
@Invoker("register") @Invoker("register")
static <T extends Criterion<?>> T callRegister(T criterion) { static <T extends Criterion<?>> T callRegister(T criterion) {

View File

@ -1,24 +0,0 @@
package com.thebrokenrail.sorcerycraft.mixin;
import com.thebrokenrail.sorcerycraft.client.gui.CastingTableScreen;
import net.minecraft.client.font.TextRenderer;
import net.minecraft.client.gui.DrawableHelper;
import net.minecraft.client.gui.widget.AbstractButtonWidget;
import net.minecraft.client.util.math.MatrixStack;
import net.minecraft.text.Text;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
@SuppressWarnings("ConstantConditions")
@Mixin(AbstractButtonWidget.class)
public class MixinAbstractButtonWidget {
@Redirect(at = @At(value = "INVOKE", target = "Lnet/minecraft/client/gui/widget/AbstractButtonWidget;drawCenteredText(Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/font/TextRenderer;Lnet/minecraft/text/Text;III)V"), method = "renderButton")
public void drawCenteredText(MatrixStack matrices, TextRenderer textRenderer, Text text, int centerX, int y, int color) {
if ((Object) this instanceof CastingTableScreen.WidgetButtonPage) {
DrawableHelper.drawStringWithShadow(matrices, textRenderer, text.getString(), ((CastingTableScreen.WidgetButtonPage) (Object) this).x + 5, y, color);
} else {
DrawableHelper.drawCenteredText(matrices, textRenderer, text, centerX, y, color);
}
}
}

View File

@ -3,9 +3,9 @@ package com.thebrokenrail.sorcerycraft.mixin;
import com.thebrokenrail.sorcerycraft.gui.CastingTableScreenHandler; import com.thebrokenrail.sorcerycraft.gui.CastingTableScreenHandler;
import com.thebrokenrail.sorcerycraft.spell.util.SpellHelper; import com.thebrokenrail.sorcerycraft.spell.util.SpellHelper;
import com.thebrokenrail.sorcerycraft.spell.util.SpellPlayerEntity; import com.thebrokenrail.sorcerycraft.spell.util.SpellPlayerEntity;
import net.minecraft.container.Container;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.screen.ScreenHandler;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import org.spongepowered.asm.mixin.Mixin; import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow; import org.spongepowered.asm.mixin.Shadow;
@ -21,7 +21,7 @@ import java.util.Map;
@Mixin(PlayerEntity.class) @Mixin(PlayerEntity.class)
public class MixinPlayerEntity implements SpellPlayerEntity { public class MixinPlayerEntity implements SpellPlayerEntity {
@Shadow @Shadow
public ScreenHandler currentScreenHandler; public Container container;
@Unique @Unique
private Map<Identifier, Integer> discoveredSpells = new HashMap<>(); private Map<Identifier, Integer> discoveredSpells = new HashMap<>();
@ -38,9 +38,9 @@ public class MixinPlayerEntity implements SpellPlayerEntity {
@Override @Override
public void setDiscoveredSpells(Map<Identifier, Integer> spells) { public void setDiscoveredSpells(Map<Identifier, Integer> spells) {
discoveredSpells = spells; discoveredSpells = spells;
if (currentScreenHandler instanceof CastingTableScreenHandler) { if (container instanceof CastingTableScreenHandler) {
//noinspection ConstantConditions //noinspection ConstantConditions
((CastingTableScreenHandler) currentScreenHandler).setSpells((PlayerEntity) (Object) this); ((CastingTableScreenHandler) container).setSpells((PlayerEntity) (Object) this);
} }
} }

View File

@ -31,7 +31,7 @@ public abstract class MixinServerPlayerEntity extends MixinPlayerEntity implemen
@Override @Override
public void setDiscoveredSpells(Map<Identifier, Integer> spells) { public void setDiscoveredSpells(Map<Identifier, Integer> spells) {
super.setDiscoveredSpells(spells); super.setDiscoveredSpells(spells);
if (currentScreenHandler instanceof CastingTableScreenHandler) { if (container instanceof CastingTableScreenHandler) {
sync(); sync();
} }
} }

View File

@ -7,15 +7,15 @@ import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.network.PacketContext; import net.fabricmc.fabric.api.network.PacketContext;
import net.minecraft.client.MinecraftClient; import net.minecraft.client.MinecraftClient;
import net.minecraft.network.PacketByteBuf; import net.minecraft.container.Container;
import net.minecraft.network.packet.c2s.play.CustomPayloadC2SPacket; import net.minecraft.network.packet.c2s.play.CustomPayloadC2SPacket;
import net.minecraft.screen.ScreenHandler;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import net.minecraft.util.PacketByteBuf;
public class SelectSpellC2SPacket { public class SelectSpellC2SPacket {
public static void handle(PacketContext context, PacketByteBuf bytes) { public static void handle(PacketContext context, PacketByteBuf bytes) {
int index = bytes.readInt(); int index = bytes.readInt();
ScreenHandler handler = context.getPlayer().currentScreenHandler; Container handler = context.getPlayer().container;
if (handler instanceof CastingTableScreenHandler) { if (handler instanceof CastingTableScreenHandler) {
CastingTableScreenHandler merchantContainer = (CastingTableScreenHandler) handler; CastingTableScreenHandler merchantContainer = (CastingTableScreenHandler) handler;
merchantContainer.setIndex(index); merchantContainer.setIndex(index);

View File

@ -1,6 +1,7 @@
package com.thebrokenrail.sorcerycraft.packet; package com.thebrokenrail.sorcerycraft.packet;
import com.thebrokenrail.sorcerycraft.SorceryCraft; import com.thebrokenrail.sorcerycraft.SorceryCraft;
import com.thebrokenrail.sorcerycraft.gui.CastingTableScreenHandler;
import com.thebrokenrail.sorcerycraft.spell.util.SpellPlayerEntity; import com.thebrokenrail.sorcerycraft.spell.util.SpellPlayerEntity;
import com.thebrokenrail.sorcerycraft.spell.util.SpellHelper; import com.thebrokenrail.sorcerycraft.spell.util.SpellHelper;
import io.netty.buffer.Unpooled; import io.netty.buffer.Unpooled;
@ -8,10 +9,10 @@ import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.network.PacketContext; import net.fabricmc.fabric.api.network.PacketContext;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.network.packet.s2c.play.CustomPayloadS2CPacket; import net.minecraft.network.packet.s2c.play.CustomPayloadS2CPacket;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import net.minecraft.util.PacketByteBuf;
public class UpdateKnownSpellsS2CPacket { public class UpdateKnownSpellsS2CPacket {
@Environment(EnvType.CLIENT) @Environment(EnvType.CLIENT)
@ -20,6 +21,9 @@ public class UpdateKnownSpellsS2CPacket {
if (context.getPlayer() != null) { if (context.getPlayer() != null) {
SpellPlayerEntity spellPlayer = (SpellPlayerEntity) context.getPlayer(); SpellPlayerEntity spellPlayer = (SpellPlayerEntity) context.getPlayer();
spellPlayer.setDiscoveredSpells(SpellHelper.getSpells(tag)); spellPlayer.setDiscoveredSpells(SpellHelper.getSpells(tag));
if (context.getPlayer().container instanceof CastingTableScreenHandler) {
((CastingTableScreenHandler) context.getPlayer().container).setSpells(context.getPlayer());
}
} }
} }

View File

@ -1,11 +1,12 @@
package com.thebrokenrail.sorcerycraft.spell; package com.thebrokenrail.sorcerycraft.spell;
import com.thebrokenrail.sorcerycraft.spell.api.Spell; import com.thebrokenrail.sorcerycraft.spell.api.Spell;
import net.minecraft.block.Blocks;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.item.Items; import net.minecraft.item.Items;
import net.minecraft.state.property.Properties; import net.minecraft.state.property.Properties;
import net.minecraft.tag.BlockTags; import net.minecraft.state.property.Properties;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
@ -24,7 +25,7 @@ public class CoolingSpell extends Spell {
@Override @Override
public void execute(World world, Entity source, Entity attacker, BlockHitResult hitResult) { public void execute(World world, Entity source, Entity attacker, BlockHitResult hitResult) {
BlockPos blockPos = hitResult.getBlockPos(); BlockPos blockPos = hitResult.getBlockPos();
if (world.getBlockState(blockPos).isIn(BlockTags.FIRE)) { if (world.getBlockState(blockPos).getBlock() == Blocks.FIRE) {
world.removeBlock(blockPos, false); world.removeBlock(blockPos, false);
} }
if (world.getBlockState(blockPos).contains(Properties.LIT) && world.getBlockState(blockPos).get(Properties.LIT)) { if (world.getBlockState(blockPos).contains(Properties.LIT) && world.getBlockState(blockPos).get(Properties.LIT)) {
@ -32,7 +33,7 @@ public class CoolingSpell extends Spell {
} }
BlockPos sideBlockPos = blockPos.offset(hitResult.getSide()); BlockPos sideBlockPos = blockPos.offset(hitResult.getSide());
if (world.getBlockState(sideBlockPos).isIn(BlockTags.FIRE)) { if (world.getBlockState(sideBlockPos).getBlock() == Blocks.FIRE) {
world.removeBlock(sideBlockPos, false); world.removeBlock(sideBlockPos, false);
} }
} }

View File

@ -1,13 +1,19 @@
package com.thebrokenrail.sorcerycraft.spell; package com.thebrokenrail.sorcerycraft.spell;
import com.thebrokenrail.sorcerycraft.spell.api.Spell; import com.thebrokenrail.sorcerycraft.spell.api.Spell;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.FireBlock;
import net.minecraft.block.TntBlock;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.LivingEntity; import net.minecraft.entity.LivingEntity;
import net.minecraft.item.AutomaticItemPlacementContext; import net.minecraft.item.FlintAndSteelItem;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.item.Items; import net.minecraft.item.Items;
import net.minecraft.state.property.Properties;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; import net.minecraft.world.World;
public class FlameSpell extends Spell { public class FlameSpell extends Spell {
@ -25,7 +31,20 @@ public class FlameSpell extends Spell {
@Override @Override
public void execute(World world, Entity source, Entity attacker, BlockHitResult hitResult) { public void execute(World world, Entity source, Entity attacker, BlockHitResult hitResult) {
Items.FLINT_AND_STEEL.useOnBlock(new AutomaticItemPlacementContext(world, hitResult.getBlockPos(), hitResult.getSide().getOpposite(), new ItemStack(Items.FLINT_AND_STEEL), hitResult.getSide())); BlockPos blockPos = hitResult.getBlockPos();
BlockState blockState = world.getBlockState(blockPos);
BlockPos sideBlockPos = hitResult.getBlockPos().offset(hitResult.getSide());
BlockState sideBlockState = world.getBlockState(sideBlockPos);
if (blockState.getBlock() instanceof TntBlock) {
TntBlock.primeTnt(world, blockPos);
world.removeBlock(blockPos, false);
} else if (FlintAndSteelItem.canIgnite(sideBlockState, world, sideBlockPos)) {
world.setBlockState(sideBlockPos, ((FireBlock) Blocks.FIRE).getStateForPosition(world, sideBlockPos));
} else if (FlintAndSteelItem.isIgnitable(blockState)) {
world.setBlockState(blockPos, blockState.with(Properties.LIT, true));
}
} }
@Override @Override

View File

@ -2,7 +2,6 @@ package com.thebrokenrail.sorcerycraft.spell;
import com.thebrokenrail.sorcerycraft.spell.api.Spell; import com.thebrokenrail.sorcerycraft.spell.api.Spell;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.LightningEntity; import net.minecraft.entity.LightningEntity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.item.Items; import net.minecraft.item.Items;
@ -30,13 +29,11 @@ public class LightningSpell extends Spell {
private void strike(World world, Vec3d pos, Entity attacker) { private void strike(World world, Vec3d pos, Entity attacker) {
ServerWorld serverWorld = (ServerWorld) world; ServerWorld serverWorld = (ServerWorld) world;
LightningEntity lightningEntity = EntityType.LIGHTNING_BOLT.create(world); LightningEntity lightningEntity = new LightningEntity(world, pos.getX(), pos.getY(), pos.getZ(), false);
assert lightningEntity != null;
lightningEntity.updatePosition(pos.x, pos.y, pos.z);
if (attacker instanceof ServerPlayerEntity) { if (attacker instanceof ServerPlayerEntity) {
lightningEntity.setChanneler((ServerPlayerEntity) attacker); lightningEntity.setChanneller((ServerPlayerEntity) attacker);
} }
serverWorld.spawnEntity(lightningEntity); serverWorld.addLightning(lightningEntity);
} }
@Override @Override

View File

@ -17,7 +17,7 @@ public class SteadfastSpell extends Spell {
@Override @Override
public ItemStack getItemCost() { public ItemStack getItemCost() {
return new ItemStack(Items.NETHERITE_INGOT); return new ItemStack(Items.DIAMOND);
} }
@Override @Override

View File

@ -17,7 +17,7 @@ public class TeleportSpell extends Spell {
} }
private int getMaxTeleport(World world) { private int getMaxTeleport(World world) {
return world.getRegistryKey() != World.OVERWORLD ? 128 : 256; return world.getDimension().isNether() ? 128 : 256;
} }
@Override @Override

View File

@ -3,7 +3,7 @@ package com.thebrokenrail.sorcerycraft.spell.api;
import com.thebrokenrail.sorcerycraft.spell.api.registry.SpellRegistry; import com.thebrokenrail.sorcerycraft.spell.api.registry.SpellRegistry;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.text.MutableText; import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText; import net.minecraft.text.TranslatableText;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.hit.BlockHitResult;
@ -83,8 +83,8 @@ public abstract class Spell {
* @param level Spell Level * @param level Spell Level
* @return Translated Display Name * @return Translated Display Name
*/ */
public static MutableText getDefaultTranslation(Identifier id, int level) { public static Text getDefaultTranslation(Identifier id, int level) {
MutableText text = new TranslatableText("spell." + id.getNamespace() + '.' + id.getPath()); Text text = new TranslatableText("spell." + id.getNamespace() + '.' + id.getPath());
if (level != 0 || SpellRegistry.getMaxLevel(id) != 1) { if (level != 0 || SpellRegistry.getMaxLevel(id) != 1) {
text.append(" ").append(new TranslatableText("enchantment.level." + (level + 1))); text.append(" ").append(new TranslatableText("enchantment.level." + (level + 1)));
} }
@ -95,7 +95,7 @@ public abstract class Spell {
* Get Translated Display Name * Get Translated Display Name
* @return Translated Display Name * @return Translated Display Name
*/ */
public MutableText getTranslation() { public Text getTranslation() {
return getDefaultTranslation(getID(), getLevel()); return getDefaultTranslation(getID(), getLevel());
} }
} }

View File

@ -10,9 +10,7 @@ import net.minecraft.loot.condition.LootCondition;
import net.minecraft.loot.context.LootContext; import net.minecraft.loot.context.LootContext;
import net.minecraft.loot.function.ConditionalLootFunction; import net.minecraft.loot.function.ConditionalLootFunction;
import net.minecraft.loot.function.LootFunction; import net.minecraft.loot.function.LootFunction;
import net.minecraft.loot.function.LootFunctionType;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry;
import java.util.Map; import java.util.Map;
@ -34,19 +32,14 @@ public class RandomSpellLootTableFunction extends ConditionalLootFunction {
return stack; return stack;
} }
@Override public static class Factory extends ConditionalLootFunction.Factory<RandomSpellLootTableFunction> {
public LootFunctionType getType() {
return Registry.LOOT_FUNCTION_TYPE.get(new Identifier(SorceryCraft.NAMESPACE, "random_spell"));
}
public static class Factory extends ConditionalLootFunction.Serializer<RandomSpellLootTableFunction> {
public Factory() { public Factory() {
super(); super(new Identifier(SorceryCraft.NAMESPACE, "random_spell"), RandomSpellLootTableFunction.class);
} }
@Override @Override
public RandomSpellLootTableFunction fromJson(JsonObject json, JsonDeserializationContext context, LootCondition[] conditions) { public RandomSpellLootTableFunction fromJson(JsonObject json, JsonDeserializationContext context, LootCondition[] conditions) {
return (RandomSpellLootTableFunction) new com.thebrokenrail.sorcerycraft.spell.util.RandomSpellLootTableFunction.Builder().build(); return (RandomSpellLootTableFunction) new Builder().build();
} }
} }

View File

@ -8,16 +8,12 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.ListTag; import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.Tag; import net.minecraft.nbt.Tag;
import net.minecraft.network.MessageType;
import net.minecraft.network.packet.s2c.play.GameMessageS2CPacket;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.text.LiteralText; import net.minecraft.text.LiteralText;
import net.minecraft.text.MutableText;
import net.minecraft.text.Text; import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText; import net.minecraft.text.TranslatableText;
import net.minecraft.util.Formatting; import net.minecraft.util.Formatting;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import net.minecraft.util.Util;
import net.minecraft.world.World; import net.minecraft.world.World;
import java.util.HashMap; import java.util.HashMap;
@ -89,7 +85,7 @@ public class SpellHelper {
public static Text getTranslatedSpell(Identifier id, int level) { public static Text getTranslatedSpell(Identifier id, int level) {
Spell spell = SpellRegistry.getSpell(id, level); Spell spell = SpellRegistry.getSpell(id, level);
MutableText text; Text text;
if (spell != null) { if (spell != null) {
text = spell.getTranslation(); text = spell.getTranslation();
} else { } else {
@ -124,7 +120,7 @@ public class SpellHelper {
playerSpells.put(spell.getID(), spell.getLevel()); playerSpells.put(spell.getID(), spell.getLevel());
assert world.getServer() != null; assert world.getServer() != null;
Text text = getTranslatedSpellChat(spell.getID(), spell.getLevel()); Text text = getTranslatedSpellChat(spell.getID(), spell.getLevel());
world.getServer().getPlayerManager().sendToAll(new GameMessageS2CPacket(new TranslatableText("chat." + SorceryCraft.NAMESPACE + ".discovered_spell", player.getDisplayName(), text), MessageType.CHAT, Util.NIL_UUID)); world.getServer().getPlayerManager().sendToAll(new TranslatableText("chat." + SorceryCraft.NAMESPACE + ".discovered_spell", player.getDisplayName(), text));
} }
} }
} }

View File

@ -32,12 +32,6 @@
"depends": { "depends": {
"fabricloader": ">=0.7.4", "fabricloader": ">=0.7.4",
"fabric": "*", "fabric": "*",
"minecraft": "1.16.x" "minecraft": "1.15.x"
},
"custom": {
"modupdater": {
"strategy": "curseforge",
"projectID": 365308
}
} }
} }

View File

@ -3,9 +3,8 @@
"package": "com.thebrokenrail.sorcerycraft.mixin", "package": "com.thebrokenrail.sorcerycraft.mixin",
"compatibilityLevel": "JAVA_8", "compatibilityLevel": "JAVA_8",
"client": [ "client": [
"MixinClientPlayerEntity",
"MixinClientPlayNetworkHandler", "MixinClientPlayNetworkHandler",
"MixinAbstractButtonWidget" "MixinClientPlayerEntity"
], ],
"mixins": [ "mixins": [
"CriteriaRegistryHook", "CriteriaRegistryHook",