diff --git a/CHANGELOG.md b/CHANGELOG.md index d4b8438..a3f8255 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,10 @@ ### Changelog +**1.1.4** +* Tweak Casting Table Texture +* Tweak Casting Table Recipe +* Update Mappings + **1.1.3** * Fix Shift-Clicking in Casting Table diff --git a/gradle.properties b/gradle.properties index 4703686..493b1aa 100644 --- a/gradle.properties +++ b/gradle.properties @@ -6,11 +6,11 @@ org.gradle.jvmargs = -Xmx1G minecraft_version = 20w10a curseforge_id = 365308 simple_minecraft_version = 1.16-Snapshot - yarn_mappings = 20w10a+build.12 - loader_version = 0.7.8+build.186 + yarn_mappings = 20w10a+build.16 + loader_version = 0.7.8+build.187 # Mod Properties - mod_version = 1.1.3 + mod_version = 1.1.4 maven_group = com.thebrokenrail archives_base_name = sorcerycraft diff --git a/src/main/java/com/thebrokenrail/sorcerycraft/SorceryCraft.java b/src/main/java/com/thebrokenrail/sorcerycraft/SorceryCraft.java index 214257d..71b90d8 100644 --- a/src/main/java/com/thebrokenrail/sorcerycraft/SorceryCraft.java +++ b/src/main/java/com/thebrokenrail/sorcerycraft/SorceryCraft.java @@ -1,7 +1,7 @@ package com.thebrokenrail.sorcerycraft; import com.thebrokenrail.sorcerycraft.block.CastingTableBlock; -import com.thebrokenrail.sorcerycraft.block.CastingTableContainer; +import com.thebrokenrail.sorcerycraft.block.CastingTableScreenHandler; import com.thebrokenrail.sorcerycraft.client.block.CastingTableScreen; import com.thebrokenrail.sorcerycraft.client.entity.SpellEntityRenderer; import com.thebrokenrail.sorcerycraft.command.SpellCommand; @@ -156,7 +156,7 @@ public class SorceryCraft implements ModInitializer, ClientModInitializer { @Override public void onInitializeClient() { EntityRendererRegistry.INSTANCE.register(SPELL_ENTITY, (entityRenderDispatcher, context) -> new SpellEntityRenderer(entityRenderDispatcher)); - ScreenProviderRegistry.INSTANCE.registerFactory(new Identifier(NAMESPACE, "casting_table"), (container) -> { + ScreenProviderRegistry.INSTANCE.registerFactory(new Identifier(NAMESPACE, "casting_table"), (container) -> { assert MinecraftClient.getInstance().player != null; return new CastingTableScreen(container, MinecraftClient.getInstance().player.inventory, new TranslatableText("block." + SorceryCraft.NAMESPACE + ".casting_table")); }); diff --git a/src/main/java/com/thebrokenrail/sorcerycraft/block/CastingTableBlock.java b/src/main/java/com/thebrokenrail/sorcerycraft/block/CastingTableBlock.java index 3543de7..bf9b7ca 100644 --- a/src/main/java/com/thebrokenrail/sorcerycraft/block/CastingTableBlock.java +++ b/src/main/java/com/thebrokenrail/sorcerycraft/block/CastingTableBlock.java @@ -6,10 +6,11 @@ import net.fabricmc.fabric.api.container.ContainerProviderRegistry; import net.minecraft.block.Block; import net.minecraft.block.BlockState; import net.minecraft.block.Material; -import net.minecraft.container.BlockContext; -import net.minecraft.container.NameableContainerFactory; -import net.minecraft.container.SimpleNamedContainerFactory; +import net.minecraft.client.gui.screen.ingame.CraftingTableScreen; import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.screen.BlockContext; +import net.minecraft.screen.NameableScreenHandlerFactory; +import net.minecraft.screen.SimpleNamedScreenHandlerFactory; import net.minecraft.text.TranslatableText; import net.minecraft.util.ActionResult; import net.minecraft.util.Hand; @@ -33,7 +34,7 @@ public class CastingTableBlock extends Block { } @Override - public NameableContainerFactory createContainerFactory(BlockState state, World world, BlockPos pos) { - return new SimpleNamedContainerFactory((i, playerInventory, playerEntity) -> new CastingTableContainer(i, playerInventory, BlockContext.create(world, pos)), new TranslatableText("container." + SorceryCraft.NAMESPACE + ".casting_table")); + public NameableScreenHandlerFactory createScreenHandlerFactory(BlockState state, World world, BlockPos pos) { + return new SimpleNamedScreenHandlerFactory((i, playerInventory, playerEntity) -> new CastingTableScreenHandler(i, playerInventory, BlockContext.create(world, pos)), new TranslatableText("container." + SorceryCraft.NAMESPACE + ".casting_table")); } } diff --git a/src/main/java/com/thebrokenrail/sorcerycraft/block/CastingTableContainer.java b/src/main/java/com/thebrokenrail/sorcerycraft/block/CastingTableScreenHandler.java similarity index 91% rename from src/main/java/com/thebrokenrail/sorcerycraft/block/CastingTableContainer.java rename to src/main/java/com/thebrokenrail/sorcerycraft/block/CastingTableScreenHandler.java index 04a49f5..e1d2dda 100644 --- a/src/main/java/com/thebrokenrail/sorcerycraft/block/CastingTableContainer.java +++ b/src/main/java/com/thebrokenrail/sorcerycraft/block/CastingTableScreenHandler.java @@ -5,16 +5,16 @@ import com.thebrokenrail.sorcerycraft.spell.api.Spell; import com.thebrokenrail.sorcerycraft.spell.util.SpellPlayerEntity; import com.thebrokenrail.sorcerycraft.spell.registry.SpellRegistry; import com.thebrokenrail.sorcerycraft.spell.util.SpellTag; -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.PlayerInventory; import net.minecraft.inventory.BasicInventory; import net.minecraft.inventory.CraftingResultInventory; import net.minecraft.inventory.Inventory; import net.minecraft.item.ItemStack; +import net.minecraft.screen.BlockContext; +import net.minecraft.screen.ScreenHandler; +import net.minecraft.screen.ScreenHandlerType; +import net.minecraft.screen.slot.Slot; import net.minecraft.util.Identifier; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; @@ -24,20 +24,20 @@ import java.util.List; import java.util.Map; import java.util.function.BiConsumer; -public class CastingTableContainer extends Container { +public class CastingTableScreenHandler extends ScreenHandler { private final Inventory inventory; private final Inventory result; private final Spell[] spells; private final BlockContext context; private int index = 0; - public CastingTableContainer(int syncId, PlayerInventory playerInventory, BlockContext blockContext) { - super(ContainerType.STONECUTTER, syncId); + public CastingTableScreenHandler(int syncId, PlayerInventory playerInventory, BlockContext blockContext) { + super(ScreenHandlerType.STONECUTTER, syncId); inventory = new BasicInventory(2) { public void markDirty() { super.markDirty(); - CastingTableContainer.this.onContentChanged(this); + CastingTableScreenHandler.this.onContentChanged(this); } }; context = blockContext; @@ -99,8 +99,8 @@ public class CastingTableContainer extends Container { context.run((BiConsumer) SorceryCraft::playSpellSound); - CastingTableContainer.this.inventory.setInvStack(0, ItemStack.EMPTY); - CastingTableContainer.this.inventory.takeInvStack(1, spells[index].getItemCost().getCount()); + CastingTableScreenHandler.this.inventory.setInvStack(0, ItemStack.EMPTY); + CastingTableScreenHandler.this.inventory.takeInvStack(1, spells[index].getItemCost().getCount()); return stack; } }); @@ -118,7 +118,7 @@ public class CastingTableContainer extends Container { } public boolean canTakeResult(PlayerEntity playerEntity) { - return (playerEntity.isCreative() || playerEntity.experienceLevel >= spells[index].getXPCost()) && spells[index].getXPCost() > 0; + return playerEntity.isCreative() || playerEntity.experienceLevel >= spells[index].getXPCost(); } public void setIndex(int index) { diff --git a/src/main/java/com/thebrokenrail/sorcerycraft/client/block/CastingTableScreen.java b/src/main/java/com/thebrokenrail/sorcerycraft/client/block/CastingTableScreen.java index 2d90a4c..c5ed0a7 100644 --- a/src/main/java/com/thebrokenrail/sorcerycraft/client/block/CastingTableScreen.java +++ b/src/main/java/com/thebrokenrail/sorcerycraft/client/block/CastingTableScreen.java @@ -2,14 +2,14 @@ package com.thebrokenrail.sorcerycraft.client.block; import com.mojang.blaze3d.systems.RenderSystem; import com.thebrokenrail.sorcerycraft.SorceryCraft; -import com.thebrokenrail.sorcerycraft.block.CastingTableContainer; +import com.thebrokenrail.sorcerycraft.block.CastingTableScreenHandler; import com.thebrokenrail.sorcerycraft.packet.SelectSpellC2SPacket; import com.thebrokenrail.sorcerycraft.spell.api.Spell; import com.thebrokenrail.sorcerycraft.spell.util.SpellTag; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.font.TextRenderer; -import net.minecraft.client.gui.screen.ingame.ContainerScreen; +import net.minecraft.client.gui.screen.ingame.ScreenWithHandler; import net.minecraft.client.gui.widget.ButtonWidget; import net.minecraft.entity.player.PlayerInventory; import net.minecraft.item.ItemStack; @@ -19,22 +19,22 @@ import net.minecraft.util.Identifier; import net.minecraft.util.math.MathHelper; @Environment(EnvType.CLIENT) -public class CastingTableScreen extends ContainerScreen { +public class CastingTableScreen extends ScreenWithHandler { private static final Identifier TEXTURE = new Identifier("textures/gui/container/villager2.png"); private int selectedIndex; private int indexStartOffset; private boolean scrolling; - public CastingTableScreen(CastingTableContainer container, PlayerInventory inventory, Text title) { + public CastingTableScreen(CastingTableScreenHandler container, PlayerInventory inventory, Text title) { super(container, inventory, title); - containerWidth = 276; + backgroundWidth = 276; } @Override protected void drawForeground(int mouseX, int mouseY) { - int j = containerHeight - 94; - textRenderer.draw(title.asFormattedString(), (float) (49 + this.containerWidth / 2 - textRenderer.getStringWidth(title.asFormattedString()) / 2), 6.0F, 4210752); - textRenderer.draw(playerInventory.getDisplayName().asFormattedString(), 107.0F, (float) j, 4210752); + int titleY = backgroundHeight - 94; + textRenderer.draw(title.asFormattedString(), (float) (49 + this.backgroundWidth / 2 - textRenderer.getStringWidth(title.asFormattedString()) / 2), 6.0F, 4210752); + textRenderer.draw(playerInventory.getDisplayName().asFormattedString(), 107.0F, (float) titleY, 4210752); String spells = new TranslatableText("container." + SorceryCraft.NAMESPACE + ".spells").getString(); textRenderer.draw(spells, (float) (5 - textRenderer.getStringWidth(spells) / 2 + 48), 6.0F, 4210752); renderXPCost(); @@ -45,9 +45,9 @@ public class CastingTableScreen extends ContainerScreen { RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F); assert client != null; client.getTextureManager().bindTexture(TEXTURE); - int i = (width - containerWidth) / 2; - int j = (height - containerHeight) / 2; - blit(i, j, getZOffset(), 0.0F, 0.0F, containerWidth, containerHeight, 256, 512); + int i = (width - backgroundWidth) / 2; + int j = (height - backgroundHeight) / 2; + blit(i, j, getZOffset(), 0.0F, 0.0F, backgroundWidth, backgroundHeight, 256, 512); } @Override @@ -63,9 +63,9 @@ public class CastingTableScreen extends ContainerScreen { if (button.isHovered()) { button.renderToolTip(mouseX, mouseY); } - button.visible = button.index < container.getRecipes().length; + button.visible = button.index < handler.getRecipes().length; if (button.visible) { - Spell spell = container.getRecipes()[button.getIndex() + indexStartOffset]; + Spell spell = handler.getRecipes()[button.getIndex() + indexStartOffset]; button.setMessage(SpellTag.getTranslatedSpell(spell.getID(), spell.getLevel(), true).getString()); button.setFocused((button.getIndex() + indexStartOffset) == selectedIndex); } @@ -73,11 +73,11 @@ public class CastingTableScreen extends ContainerScreen { } private void renderScrollbar() { - Spell[] spells = container.getRecipes(); + Spell[] spells = handler.getRecipes(); assert client != null; client.getTextureManager().bindTexture(TEXTURE); - int i = (width - containerWidth) / 2; - int j = (height - containerHeight) / 2; + int i = (width - backgroundWidth) / 2; + int j = (height - backgroundHeight) / 2; int k = spells.length + 1 - 7; if (k > 1) { @@ -95,11 +95,11 @@ public class CastingTableScreen extends ContainerScreen { } private void renderItems() { - int i = (width - containerWidth) / 2; - int j = (height - containerHeight) / 2; + int i = (width - backgroundWidth) / 2; + int j = (height - backgroundHeight) / 2; int k = j + 16 + 1; - Spell[] spells = container.getRecipes(); + Spell[] spells = handler.getRecipes(); for (int x = 0; x < spells.length; x++) { if (!canScroll(spells.length) || (x >= indexStartOffset && x < 7 + indexStartOffset)) { ItemStack itemStack = spells[x].getItemCost(); @@ -115,20 +115,20 @@ public class CastingTableScreen extends ContainerScreen { } private void renderXPCost() { - if (container.getRecipes().length > 0) { - int i = container.getRecipes()[selectedIndex].getXPCost(); - int j = 8453920; + if (handler.getRecipes().length > 0) { + int cost = handler.getRecipes()[selectedIndex].getXPCost(); + int color = 8453920; assert client != null; assert client.player != null; - String string = new TranslatableText("container.repair.cost", i).getString(); - if (!container.canTakeResult(playerInventory.player)) { - j = 16736352; + String string = new TranslatableText("container.repair.cost", cost).getString(); + if (!handler.canTakeResult(playerInventory.player)) { + color = 16736352; } - int x2 = containerWidth - 8; + int x2 = backgroundWidth - 8; int x1 = x2 - textRenderer.getStringWidth(string); fill(x1, 65, x2, 77, 1325400064); - textRenderer.drawWithShadow(string, (float) x1, 67.0F, j); + textRenderer.drawWithShadow(string, (float) x1, 67.0F, color); } } @@ -138,7 +138,7 @@ public class CastingTableScreen extends ContainerScreen { @Override public boolean mouseScrolled(double d, double e, double amount) { - int i = container.getRecipes().length; + int i = handler.getRecipes().length; if (this.canScroll(i)) { int j = i - 7; indexStartOffset = (int) ((double) indexStartOffset - amount); @@ -150,7 +150,7 @@ public class CastingTableScreen extends ContainerScreen { @Override public boolean mouseDragged(double mouseX, double mouseY, int button, double deltaX, double deltaY) { - int i = container.getRecipes().length; + int i = handler.getRecipes().length; if (scrolling) { int j = y + 18; int k = j + 139; @@ -167,9 +167,9 @@ public class CastingTableScreen extends ContainerScreen { @Override public boolean mouseClicked(double mouseX, double mouseY, int button) { scrolling = false; - int i = (width - containerWidth) / 2; - int j = (height - containerHeight) / 2; - if (canScroll(container.getRecipes().length) && mouseX > (double) (i + 94) && mouseX < (double) (i + 94 + 6) && mouseY > (double) (j + 18) && mouseY <= (double) (j + 18 + 139 + 1)) { + int i = (width - backgroundWidth) / 2; + int j = (height - backgroundHeight) / 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)) { scrolling = true; } @@ -177,7 +177,7 @@ public class CastingTableScreen extends ContainerScreen { } private void syncRecipeIndex() { - container.setIndex(selectedIndex); + handler.setIndex(selectedIndex); assert client != null; SelectSpellC2SPacket.send(client, selectedIndex); } @@ -187,8 +187,8 @@ public class CastingTableScreen extends ContainerScreen { @Override protected void init() { super.init(); - int i = (width - containerWidth) / 2; - int j = (height - containerHeight) / 2; + int i = (width - backgroundWidth) / 2; + int j = (height - backgroundHeight) / 2; int k = j + 16 + 2; for (int l = 0; l < 7; ++l) { @@ -220,8 +220,8 @@ public class CastingTableScreen extends ContainerScreen { } public void renderToolTip(int mouseX, int mouseY) { - if (hovered && container.getRecipes().length > index + indexStartOffset && mouseX > this.x + 65) { - ItemStack itemStack = container.getRecipes()[index + indexStartOffset].getItemCost(); + if (hovered && handler.getRecipes().length > index + indexStartOffset && mouseX > this.x + 65) { + ItemStack itemStack = handler.getRecipes()[index + indexStartOffset].getItemCost(); if (!itemStack.isEmpty()) { renderTooltip(itemStack, mouseX, mouseY); } diff --git a/src/main/java/com/thebrokenrail/sorcerycraft/client/entity/SpellEntityRenderer.java b/src/main/java/com/thebrokenrail/sorcerycraft/client/entity/SpellEntityRenderer.java index 5133c7c..d7bfdc9 100644 --- a/src/main/java/com/thebrokenrail/sorcerycraft/client/entity/SpellEntityRenderer.java +++ b/src/main/java/com/thebrokenrail/sorcerycraft/client/entity/SpellEntityRenderer.java @@ -5,7 +5,7 @@ import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.render.entity.EntityRenderDispatcher; import net.minecraft.client.render.entity.EntityRenderer; -import net.minecraft.container.PlayerContainer; +import net.minecraft.screen.PlayerScreenHandler; import net.minecraft.util.Identifier; @Environment(EnvType.CLIENT) @@ -16,6 +16,6 @@ public class SpellEntityRenderer extends EntityRenderer { @Override public Identifier getTexture(SpellEntity spellEntity) { - return PlayerContainer.BLOCK_ATLAS_TEXTURE; + return PlayerScreenHandler.BLOCK_ATLAS_TEXTURE; } } \ No newline at end of file diff --git a/src/main/java/com/thebrokenrail/sorcerycraft/packet/SelectSpellC2SPacket.java b/src/main/java/com/thebrokenrail/sorcerycraft/packet/SelectSpellC2SPacket.java index b2334a2..a57308c 100644 --- a/src/main/java/com/thebrokenrail/sorcerycraft/packet/SelectSpellC2SPacket.java +++ b/src/main/java/com/thebrokenrail/sorcerycraft/packet/SelectSpellC2SPacket.java @@ -1,21 +1,21 @@ package com.thebrokenrail.sorcerycraft.packet; import com.thebrokenrail.sorcerycraft.SorceryCraft; -import com.thebrokenrail.sorcerycraft.block.CastingTableContainer; +import com.thebrokenrail.sorcerycraft.block.CastingTableScreenHandler; import io.netty.buffer.Unpooled; import net.fabricmc.fabric.api.network.PacketContext; import net.minecraft.client.MinecraftClient; -import net.minecraft.container.Container; import net.minecraft.network.packet.c2s.play.CustomPayloadC2SPacket; +import net.minecraft.screen.ScreenHandler; import net.minecraft.util.Identifier; import net.minecraft.util.PacketByteBuf; public class SelectSpellC2SPacket { public static void handle(PacketContext context, PacketByteBuf bytes) { int index = bytes.readInt(); - Container container = context.getPlayer().container; - if (container instanceof CastingTableContainer) { - CastingTableContainer merchantContainer = (CastingTableContainer) container; + ScreenHandler handler = context.getPlayer().currentScreenHandler; + if (handler instanceof CastingTableScreenHandler) { + CastingTableScreenHandler merchantContainer = (CastingTableScreenHandler) handler; merchantContainer.setIndex(index); } } diff --git a/src/main/resources/assets/sorcerycraft/textures/block/casting_table.png b/src/main/resources/assets/sorcerycraft/textures/block/casting_table.png index 88a126f..6d43c2c 100644 Binary files a/src/main/resources/assets/sorcerycraft/textures/block/casting_table.png and b/src/main/resources/assets/sorcerycraft/textures/block/casting_table.png differ diff --git a/src/main/resources/data/sorcerycraft/loot_tables/blocks/casting_table.json b/src/main/resources/data/sorcerycraft/loot_tables/blocks/casting_table.json index 96e9030..dcf7622 100644 --- a/src/main/resources/data/sorcerycraft/loot_tables/blocks/casting_table.json +++ b/src/main/resources/data/sorcerycraft/loot_tables/blocks/casting_table.json @@ -1,19 +1,19 @@ { - "type": "minecraft:block", - "pools": [ - { - "rolls": 1, - "entries": [ + "type": "minecraft:block", + "pools": [ { - "type": "minecraft:item", - "name": "sorcerycraft:casting_table" + "rolls": 1, + "entries": [ + { + "type": "minecraft:item", + "name": "sorcerycraft:casting_table" + } + ], + "conditions": [ + { + "condition": "minecraft:survives_explosion" + } + ] } - ], - "conditions": [ - { - "condition": "minecraft:survives_explosion" - } - ] - } - ] + ] } \ No newline at end of file diff --git a/src/main/resources/data/sorcerycraft/recipes/casting_table.json b/src/main/resources/data/sorcerycraft/recipes/casting_table.json index 013913b..f75d7b2 100644 --- a/src/main/resources/data/sorcerycraft/recipes/casting_table.json +++ b/src/main/resources/data/sorcerycraft/recipes/casting_table.json @@ -1,24 +1,23 @@ { - "type": "minecraft:crafting_shaped", - "pattern": [ - "LCL", - "CDC", - "LCL" - ], - "key": { - "L": { - "item": "minecraft:lapis_lazuli" + "type": "minecraft:crafting_shaped", + "pattern": [ + "LSL", + "SDS", + "LSL" + ], + "key": { + "L": { + "item": "minecraft:lapis_lazuli" + }, + "S": { + "item": "minecraft:smooth_stone" + }, + "D": { + "item": "minecraft:diamond" + } }, - "C": { - "item": "minecraft:cobblestone" - }, - "D": { - "item": "minecraft:diamond" + "result": { + "item": "sorcerycraft:casting_table" } - }, - "result": { - "item": "sorcerycraft:casting_table", - "count": 1 - } } diff --git a/src/main/resources/data/sorcerycraft/recipes/spell.json b/src/main/resources/data/sorcerycraft/recipes/spell.json index 939be77..4bfe32b 100644 --- a/src/main/resources/data/sorcerycraft/recipes/spell.json +++ b/src/main/resources/data/sorcerycraft/recipes/spell.json @@ -1,21 +1,21 @@ { - "type": "minecraft:crafting_shaped", - "pattern": [ - " L ", - "LPL", - " L " - ], - "key": { - "L": { - "item": "minecraft:lapis_lazuli" + "type": "minecraft:crafting_shaped", + "pattern": [ + " L ", + "LPL", + " L " + ], + "key": { + "L": { + "item": "minecraft:lapis_lazuli" + }, + "P": { + "item": "minecraft:paper" + } }, - "P": { - "item": "minecraft:paper" + "result": { + "item": "sorcerycraft:spell", + "count": 1 } - }, - "result": { - "item": "sorcerycraft:spell", - "count": 1 - } }