From 3c4cefdad341de8614e6dd42e19adb7affc4bd58 Mon Sep 17 00:00:00 2001 From: Alexander Behrhof Date: Mon, 26 Jul 2021 21:27:26 -0400 Subject: [PATCH] Start working on updating Iron Chests to 1.17.1 --- build.gradle | 5 +- gradle.properties | 10 +- .../com/progwml6/ironchest/IronChests.java | 26 +- .../client/model/IronChestsModels.java | 6 +- .../inventory/IronChestItemStackRenderer.java | 20 +- .../client/model/inventory/ModelItem.java | 2 +- .../render/IronChestTileEntityRenderer.java | 118 ++--- .../client/screen/IronChestScreen.java | 38 +- .../common/ai/CatsSitOnChestsHandler.java | 16 +- .../common/ai/IronChestCatSitOnBlockGoal.java | 20 +- .../common/block/CopperChestBlock.java | 10 +- .../common/block/CrystalChestBlock.java | 10 +- .../common/block/DiamondChestBlock.java | 10 +- .../common/block/DirtChestBlock.java | 10 +- .../common/block/GenericIronChestBlock.java | 222 ++++---- .../common/block/GoldChestBlock.java | 10 +- .../common/block/IronChestBlock.java | 10 +- .../common/block/IronChestsBlocks.java | 48 +- .../common/block/IronChestsTypes.java | 12 +- .../common/block/ObsidianChestBlock.java | 10 +- .../common/block/SilverChestBlock.java | 10 +- .../tileentity/CopperChestTileEntity.java | 6 +- .../tileentity/CrystalChestTileEntity.java | 44 +- .../tileentity/DiamondChestTileEntity.java | 6 +- .../block/tileentity/DirtChestTileEntity.java | 42 +- .../GenericIronChestTileEntity.java | 136 ++--- .../block/tileentity/GoldChestTileEntity.java | 6 +- .../tileentity/IronChestsTileEntityTypes.java | 36 +- .../tileentity/ObsidianChestTileEntity.java | 6 +- .../tileentity/SilverChestTileEntity.java | 6 +- .../common/data/IronChestsRecipeProvider.java | 480 +++++++++--------- .../common/inventory/DirtChestSlot.java | 16 +- .../common/inventory/IronChestContainer.java | 104 ++-- .../inventory/IronChestsContainerTypes.java | 20 +- .../common/item/ChestUpgradeItem.java | 110 ++-- .../common/item/IronChestsItems.java | 4 +- .../network/InventoryTopStacksSyncPacket.java | 26 +- .../common/network/IronChestNetwork.java | 50 +- .../common/network/helper/ISimplePacket.java | 4 +- .../resources/META-INF/accesstransformer.cfg | 2 +- 40 files changed, 873 insertions(+), 854 deletions(-) diff --git a/build.gradle b/build.gradle index 7e30aa2..dc79040 100755 --- a/build.gradle +++ b/build.gradle @@ -23,10 +23,11 @@ repositories { group = "com.progwml6.ironchest" -sourceCompatibility = targetCompatibility = compileJava.sourceCompatibility = compileJava.targetCompatibility = '1.8' +// Mojang ships Java 16 to end users in 1.17+ instead of Java 8 in 1.16 or lower, so your mod should target Java 16. +java.toolchain.languageVersion = JavaLanguageVersion.of(16) minecraft { - mappings channel: 'snapshot', version: mappings_version + mappings channel: 'official', version: mappings_version accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg') diff --git a/gradle.properties b/gradle.properties index db7d3d3..3454023 100644 --- a/gradle.properties +++ b/gradle.properties @@ -7,16 +7,16 @@ org.gradle.daemon=false mod_version=11.2 # Minecraft Version Information -minecraft_version=1.16.5 -minecraft_range=[1.16.5,1.17) +minecraft_version=1.17.1 +minecraft_range=[1.17.1,1.18) # Forge Version Information loader_range=[33.0,) -forge_version=36.1.1 -forge_range=[36.1.1,) +forge_version=37.0.1 +forge_range=[37.0.1,) # Mappings Information -mappings_version=20200916-1.16.2 +mappings_version=1.17.1 # Build dependencies jei_version=1.16.4:7.6.1.65 diff --git a/src/main/java/com/progwml6/ironchest/IronChests.java b/src/main/java/com/progwml6/ironchest/IronChests.java index 9d4b7aa..5cdc23c 100644 --- a/src/main/java/com/progwml6/ironchest/IronChests.java +++ b/src/main/java/com/progwml6/ironchest/IronChests.java @@ -8,10 +8,10 @@ import com.progwml6.ironchest.common.data.IronChestsRecipeProvider; import com.progwml6.ironchest.common.inventory.IronChestsContainerTypes; import com.progwml6.ironchest.common.item.IronChestsItems; import com.progwml6.ironchest.common.network.IronChestNetwork; -import net.minecraft.client.gui.ScreenManager; +import net.minecraft.client.gui.screens.MenuScreens; import net.minecraft.data.DataGenerator; -import net.minecraft.item.ItemGroup; -import net.minecraft.item.ItemStack; +import net.minecraft.world.item.CreativeModeTab; +import net.minecraft.world.item.ItemStack; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.eventbus.api.IEventBus; @@ -28,10 +28,10 @@ public class IronChests { public static final String MODID = "ironchest"; - public static final ItemGroup IRONCHESTS_ITEM_GROUP = (new ItemGroup("ironchest") { + public static final CreativeModeTab IRONCHESTS_ITEM_GROUP = (new CreativeModeTab("ironchest") { @Override @OnlyIn(Dist.CLIENT) - public ItemStack createIcon() { + public ItemStack makeIcon() { return new ItemStack(IronChestsBlocks.IRON_CHEST.get()); } }); @@ -59,14 +59,14 @@ public class IronChests { @OnlyIn(Dist.CLIENT) private void setupClient(final FMLClientSetupEvent event) { - ScreenManager.registerFactory(IronChestsContainerTypes.IRON_CHEST.get(), IronChestScreen::new); - ScreenManager.registerFactory(IronChestsContainerTypes.GOLD_CHEST.get(), IronChestScreen::new); - ScreenManager.registerFactory(IronChestsContainerTypes.DIAMOND_CHEST.get(), IronChestScreen::new); - ScreenManager.registerFactory(IronChestsContainerTypes.CRYSTAL_CHEST.get(), IronChestScreen::new); - ScreenManager.registerFactory(IronChestsContainerTypes.COPPER_CHEST.get(), IronChestScreen::new); - ScreenManager.registerFactory(IronChestsContainerTypes.SILVER_CHEST.get(), IronChestScreen::new); - ScreenManager.registerFactory(IronChestsContainerTypes.OBSIDIAN_CHEST.get(), IronChestScreen::new); - ScreenManager.registerFactory(IronChestsContainerTypes.DIRT_CHEST.get(), IronChestScreen::new); + MenuScreens.register(IronChestsContainerTypes.IRON_CHEST.get(), IronChestScreen::new); + MenuScreens.register(IronChestsContainerTypes.GOLD_CHEST.get(), IronChestScreen::new); + MenuScreens.register(IronChestsContainerTypes.DIAMOND_CHEST.get(), IronChestScreen::new); + MenuScreens.register(IronChestsContainerTypes.CRYSTAL_CHEST.get(), IronChestScreen::new); + MenuScreens.register(IronChestsContainerTypes.COPPER_CHEST.get(), IronChestScreen::new); + MenuScreens.register(IronChestsContainerTypes.SILVER_CHEST.get(), IronChestScreen::new); + MenuScreens.register(IronChestsContainerTypes.OBSIDIAN_CHEST.get(), IronChestScreen::new); + MenuScreens.register(IronChestsContainerTypes.DIRT_CHEST.get(), IronChestScreen::new); ClientRegistry.bindTileEntityRenderer(IronChestsTileEntityTypes.IRON_CHEST.get(), IronChestTileEntityRenderer::new); ClientRegistry.bindTileEntityRenderer(IronChestsTileEntityTypes.GOLD_CHEST.get(), IronChestTileEntityRenderer::new); diff --git a/src/main/java/com/progwml6/ironchest/client/model/IronChestsModels.java b/src/main/java/com/progwml6/ironchest/client/model/IronChestsModels.java index 1ccaa3f..4c3d510 100644 --- a/src/main/java/com/progwml6/ironchest/client/model/IronChestsModels.java +++ b/src/main/java/com/progwml6/ironchest/client/model/IronChestsModels.java @@ -2,8 +2,8 @@ package com.progwml6.ironchest.client.model; import com.progwml6.ironchest.IronChests; import com.progwml6.ironchest.common.block.IronChestsTypes; -import net.minecraft.client.renderer.Atlases; -import net.minecraft.util.ResourceLocation; +import net.minecraft.client.renderer.Sheets; +import net.minecraft.resources.ResourceLocation; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.client.event.TextureStitchEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; @@ -50,7 +50,7 @@ public class IronChestsModels { @SubscribeEvent public static void onStitch(TextureStitchEvent.Pre event) { - if (!event.getMap().getTextureLocation().equals(Atlases.CHEST_ATLAS)) { + if (!event.getMap().location().equals(Sheets.CHEST_SHEET)) { return; } diff --git a/src/main/java/com/progwml6/ironchest/client/model/inventory/IronChestItemStackRenderer.java b/src/main/java/com/progwml6/ironchest/client/model/inventory/IronChestItemStackRenderer.java index 34d1f4d..a8f5823 100644 --- a/src/main/java/com/progwml6/ironchest/client/model/inventory/IronChestItemStackRenderer.java +++ b/src/main/java/com/progwml6/ironchest/client/model/inventory/IronChestItemStackRenderer.java @@ -1,19 +1,19 @@ package com.progwml6.ironchest.client.model.inventory; -import com.mojang.blaze3d.matrix.MatrixStack; -import net.minecraft.client.renderer.IRenderTypeBuffer; -import net.minecraft.client.renderer.model.ItemCameraTransforms; -import net.minecraft.client.renderer.tileentity.ItemStackTileEntityRenderer; -import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; -import net.minecraft.item.ItemStack; -import net.minecraft.tileentity.TileEntity; +import com.mojang.blaze3d.vertex.PoseStack; +import net.minecraft.client.renderer.MultiBufferSource; +import net.minecraft.client.renderer.block.model.ItemTransforms; +import net.minecraft.client.renderer.BlockEntityWithoutLevelRenderer; +import net.minecraft.client.renderer.blockentity.BlockEntityRenderDispatcher; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.block.entity.BlockEntity; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; import java.util.function.Supplier; @OnlyIn(Dist.CLIENT) -public class IronChestItemStackRenderer extends ItemStackTileEntityRenderer { +public class IronChestItemStackRenderer extends BlockEntityWithoutLevelRenderer { private final Supplier te; @@ -22,7 +22,7 @@ public class IronChestItemStackRenderer extends ItemStackT } @Override - public void func_239207_a_(ItemStack itemStackIn, ItemCameraTransforms.TransformType transformType, MatrixStack matrixStackIn, IRenderTypeBuffer bufferIn, int combinedLightIn, int combinedOverlayIn) { - TileEntityRendererDispatcher.instance.renderItem(this.te.get(), matrixStackIn, bufferIn, combinedLightIn, combinedOverlayIn); + public void renderByItem(ItemStack itemStackIn, ItemTransforms.TransformType transformType, PoseStack matrixStackIn, MultiBufferSource bufferIn, int combinedLightIn, int combinedOverlayIn) { + BlockEntityRenderDispatcher.instance.renderItem(this.te.get(), matrixStackIn, bufferIn, combinedLightIn, combinedOverlayIn); } } diff --git a/src/main/java/com/progwml6/ironchest/client/model/inventory/ModelItem.java b/src/main/java/com/progwml6/ironchest/client/model/inventory/ModelItem.java index 5920f12..e676db0 100644 --- a/src/main/java/com/progwml6/ironchest/client/model/inventory/ModelItem.java +++ b/src/main/java/com/progwml6/ironchest/client/model/inventory/ModelItem.java @@ -1,6 +1,6 @@ package com.progwml6.ironchest.client.model.inventory; -import net.minecraft.util.math.vector.Vector3f; +import com.mojang.math.Vector3f; public class ModelItem { private final Vector3f center; diff --git a/src/main/java/com/progwml6/ironchest/client/render/IronChestTileEntityRenderer.java b/src/main/java/com/progwml6/ironchest/client/render/IronChestTileEntityRenderer.java index c262802..603cc51 100644 --- a/src/main/java/com/progwml6/ironchest/client/render/IronChestTileEntityRenderer.java +++ b/src/main/java/com/progwml6/ironchest/client/render/IronChestTileEntityRenderer.java @@ -1,50 +1,50 @@ package com.progwml6.ironchest.client.render; import com.google.common.primitives.SignedBytes; -import com.mojang.blaze3d.matrix.MatrixStack; -import com.mojang.blaze3d.vertex.IVertexBuilder; +import com.mojang.blaze3d.vertex.PoseStack; +import com.mojang.blaze3d.vertex.VertexConsumer; import com.progwml6.ironchest.client.model.IronChestsModels; import com.progwml6.ironchest.client.model.inventory.ModelItem; import com.progwml6.ironchest.common.block.GenericIronChestBlock; import com.progwml6.ironchest.common.block.IronChestsTypes; import com.progwml6.ironchest.common.block.tileentity.CrystalChestTileEntity; import com.progwml6.ironchest.common.block.tileentity.GenericIronChestTileEntity; -import net.minecraft.block.Block; -import net.minecraft.block.BlockState; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockState; import net.minecraft.client.Minecraft; -import net.minecraft.client.renderer.Atlases; -import net.minecraft.client.renderer.IRenderTypeBuffer; +import net.minecraft.client.renderer.Sheets; +import net.minecraft.client.renderer.MultiBufferSource; import net.minecraft.client.renderer.RenderType; -import net.minecraft.client.renderer.entity.ItemRenderer; +import net.minecraft.client.renderer.entity.ItemEntityRenderer; import net.minecraft.client.renderer.model.ItemCameraTransforms; -import net.minecraft.client.renderer.model.ModelRenderer; -import net.minecraft.client.renderer.model.RenderMaterial; +import net.minecraft.client.model.geom.ModelPart; +import net.minecraft.client.resources.model.Material; import net.minecraft.client.renderer.texture.OverlayTexture; -import net.minecraft.client.renderer.tileentity.DualBrightnessCallback; -import net.minecraft.client.renderer.tileentity.TileEntityRenderer; -import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; -import net.minecraft.entity.EntityType; -import net.minecraft.entity.item.ItemEntity; -import net.minecraft.item.ItemStack; -import net.minecraft.tileentity.IChestLid; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.tileentity.TileEntityMerger; -import net.minecraft.util.Direction; -import net.minecraft.util.math.vector.Vector3d; -import net.minecraft.util.math.vector.Vector3f; -import net.minecraft.world.World; +import net.minecraft.client.renderer.blockentity.BrightnessCombiner; +import net.minecraft.client.renderer.blockentity.BlockEntityRenderer; +import net.minecraft.client.renderer.blockentity.BlockEntityRenderDispatcher; +import net.minecraft.world.entity.EntityType; +import net.minecraft.world.entity.item.ItemEntity; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.block.entity.LidBlockEntity; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.DoubleBlockCombiner; +import net.minecraft.core.Direction; +import net.minecraft.world.phys.Vec3; +import com.mojang.math.Vector3f; +import net.minecraft.world.level.Level; import java.util.Arrays; import java.util.List; -public class IronChestTileEntityRenderer extends TileEntityRenderer { +public class IronChestTileEntityRenderer extends BlockEntityRenderer { - private final ModelRenderer chestLid; - private final ModelRenderer chestBottom; - private final ModelRenderer chestLock; + private final ModelPart chestLid; + private final ModelPart chestBottom; + private final ModelPart chestLock; private static ItemEntity customItem; - private static ItemRenderer itemRenderer; + private static ItemEntityRenderer itemRenderer; private static final List MODEL_ITEMS = Arrays.asList( new ModelItem(new Vector3f(0.3F, 0.45F, 0.3F), 3.0F), @@ -58,28 +58,28 @@ public class IronChestTileEntityRenderer exten new ModelItem(new Vector3f(0.5F, 0.32F, 0.5F), 3.0F) ); - public IronChestTileEntityRenderer(TileEntityRendererDispatcher tileEntityRendererDispatcher) { + public IronChestTileEntityRenderer(BlockEntityRenderDispatcher tileEntityRendererDispatcher) { super(tileEntityRendererDispatcher); - this.chestBottom = new ModelRenderer(64, 64, 0, 19); + this.chestBottom = new ModelPart(64, 64, 0, 19); this.chestBottom.addBox(1.0F, 0.0F, 1.0F, 14.0F, 10.0F, 14.0F, 0.0F); - this.chestLid = new ModelRenderer(64, 64, 0, 0); + this.chestLid = new ModelPart(64, 64, 0, 0); this.chestLid.addBox(1.0F, 0.0F, 0.0F, 14.0F, 5.0F, 14.0F, 0.0F); - this.chestLid.rotationPointY = 9.0F; - this.chestLid.rotationPointZ = 1.0F; - this.chestLock = new ModelRenderer(64, 64, 0, 0); + this.chestLid.y = 9.0F; + this.chestLid.z = 1.0F; + this.chestLock = new ModelPart(64, 64, 0, 0); this.chestLock.addBox(7.0F, -1.0F, 15.0F, 2.0F, 4.0F, 1.0F, 0.0F); - this.chestLock.rotationPointY = 8.0F; + this.chestLock.y = 8.0F; } @Override - public void render(T tileEntityIn, float partialTicks, MatrixStack matrixStackIn, IRenderTypeBuffer bufferIn, int combinedLightIn, int combinedOverlayIn) { + public void render(T tileEntityIn, float partialTicks, PoseStack matrixStackIn, MultiBufferSource bufferIn, int combinedLightIn, int combinedOverlayIn) { GenericIronChestTileEntity tileEntity = (GenericIronChestTileEntity) tileEntityIn; - World world = tileEntity.getWorld(); + Level world = tileEntity.getLevel(); boolean flag = world != null; - BlockState blockstate = flag ? tileEntity.getBlockState() : (BlockState) tileEntity.getBlockToUse().getDefaultState().with(GenericIronChestBlock.FACING, Direction.SOUTH); + BlockState blockstate = flag ? tileEntity.getBlockState() : (BlockState) tileEntity.getBlockToUse().defaultBlockState().setValue(GenericIronChestBlock.FACING, Direction.SOUTH); Block block = blockstate.getBlock(); IronChestsTypes chestType = IronChestsTypes.IRON; IronChestsTypes actualType = GenericIronChestBlock.getTypeFromBlock(block); @@ -91,32 +91,32 @@ public class IronChestTileEntityRenderer exten if (block instanceof GenericIronChestBlock) { GenericIronChestBlock ironChestBlock = (GenericIronChestBlock) block; - matrixStackIn.push(); - float f = blockstate.get(GenericIronChestBlock.FACING).getHorizontalAngle(); + matrixStackIn.pushPose(); + float f = blockstate.getValue(GenericIronChestBlock.FACING).toYRot(); matrixStackIn.translate(0.5D, 0.5D, 0.5D); - matrixStackIn.rotate(Vector3f.YP.rotationDegrees(-f)); + matrixStackIn.mulPose(Vector3f.YP.rotationDegrees(-f)); matrixStackIn.translate(-0.5D, -0.5D, -0.5D); - TileEntityMerger.ICallbackWrapper iCallbackWrapper; + DoubleBlockCombiner.NeighborCombineResult iCallbackWrapper; if (flag) { - iCallbackWrapper = ironChestBlock.getWrapper(blockstate, world, tileEntity.getPos(), true); + iCallbackWrapper = ironChestBlock.getWrapper(blockstate, world, tileEntity.getBlockPos(), true); } else { - iCallbackWrapper = TileEntityMerger.ICallback::func_225537_b_; + iCallbackWrapper = DoubleBlockCombiner.Combiner::acceptNone; } - float f1 = iCallbackWrapper.apply(GenericIronChestBlock.getLid((IChestLid) tileEntity)).get(partialTicks); + float f1 = iCallbackWrapper.apply(GenericIronChestBlock.getLid((LidBlockEntity) tileEntity)).get(partialTicks); f1 = 1.0F - f1; f1 = 1.0F - f1 * f1 * f1; - int i = iCallbackWrapper.apply(new DualBrightnessCallback<>()).applyAsInt(combinedLightIn); + int i = iCallbackWrapper.apply(new BrightnessCombiner<>()).applyAsInt(combinedLightIn); - RenderMaterial material = new RenderMaterial(Atlases.CHEST_ATLAS, IronChestsModels.chooseChestTexture(chestType)); - IVertexBuilder ivertexbuilder = material.getBuffer(bufferIn, RenderType::getEntityCutout); + Material material = new Material(Sheets.CHEST_SHEET, IronChestsModels.chooseChestTexture(chestType)); + VertexConsumer ivertexbuilder = material.buffer(bufferIn, RenderType::entityCutout); this.handleModelRender(matrixStackIn, ivertexbuilder, this.chestLid, this.chestLock, this.chestBottom, f1, i, combinedOverlayIn); - matrixStackIn.pop(); + matrixStackIn.popPose(); - if (chestType.isTransparent() && tileEntity instanceof CrystalChestTileEntity && Vector3d.copyCentered(tileEntityIn.getPos()).isWithinDistanceOf(this.renderDispatcher.renderInfo.getProjectedView(), 128d)) { + if (chestType.isTransparent() && tileEntity instanceof CrystalChestTileEntity && Vec3.atCenterOf(tileEntityIn.getBlockPos()).closerThan(this.renderer.camera.getPosition(), 128d)) { float rotation = (float) (360D * (System.currentTimeMillis() & 0x3FFFL) / 0x3FFFL) - partialTicks; CrystalChestTileEntity crystalChestTileEntity = (CrystalChestTileEntity) tileEntity; @@ -132,9 +132,9 @@ public class IronChestTileEntityRenderer exten } } - private void handleModelRender(MatrixStack matrixStackIn, IVertexBuilder iVertexBuilder, ModelRenderer firstModel, ModelRenderer secondModel, ModelRenderer thirdModel, float f1, int p_228871_7_, int p_228871_8_) { - firstModel.rotateAngleX = -(f1 * ((float) Math.PI / 2F)); - secondModel.rotateAngleX = firstModel.rotateAngleX; + private void handleModelRender(PoseStack matrixStackIn, VertexConsumer iVertexBuilder, ModelPart firstModel, ModelPart secondModel, ModelPart thirdModel, float f1, int p_228871_7_, int p_228871_8_) { + firstModel.xRot = -(f1 * ((float) Math.PI / 2F)); + secondModel.xRot = firstModel.xRot; firstModel.render(matrixStackIn, iVertexBuilder, p_228871_7_, p_228871_8_); secondModel.render(matrixStackIn, iVertexBuilder, p_228871_7_, p_228871_8_); thirdModel.render(matrixStackIn, iVertexBuilder, p_228871_7_, p_228871_8_); @@ -149,18 +149,18 @@ public class IronChestTileEntityRenderer exten * @param modelItem Model items for render information * @param light Model light */ - public static void renderItem(MatrixStack matrices, IRenderTypeBuffer buffer, ItemStack item, ModelItem modelItem, float rotation, int light, float partialTicks) { + public static void renderItem(PoseStack matrices, MultiBufferSource buffer, ItemStack item, ModelItem modelItem, float rotation, int light, float partialTicks) { // if no stack, skip if (item.isEmpty()) return; customItem.setItem(item); // start rendering - matrices.push(); + matrices.pushPose(); Vector3f center = modelItem.getCenter(); - matrices.translate(center.getX(), center.getY(), center.getZ()); + matrices.translate(center.x(), center.y(), center.z()); - matrices.rotate(Vector3f.YP.rotation(rotation)); + matrices.mulPose(Vector3f.YP.rotation(rotation)); // scale float scale = modelItem.getSizeScaled(); @@ -168,9 +168,9 @@ public class IronChestTileEntityRenderer exten // render the actual item if (itemRenderer == null) { - itemRenderer = new ItemRenderer(Minecraft.getInstance().getRenderManager(), Minecraft.getInstance().getItemRenderer()) { + itemRenderer = new ItemEntityRenderer(Minecraft.getInstance().getEntityRenderDispatcher(), Minecraft.getInstance().getItemRenderer()) { @Override - public int getModelCount(ItemStack stack) { + public int getRenderAmount(ItemStack stack) { return SignedBytes.saturatedCast(Math.min(stack.getCount() / 32, 15) + 1); } @@ -187,6 +187,6 @@ public class IronChestTileEntityRenderer exten } itemRenderer.render(customItem, 0F, partialTicks, matrices, buffer, light); - matrices.pop(); + matrices.popPose(); } } diff --git a/src/main/java/com/progwml6/ironchest/client/screen/IronChestScreen.java b/src/main/java/com/progwml6/ironchest/client/screen/IronChestScreen.java index ace0c52..13fa19a 100644 --- a/src/main/java/com/progwml6/ironchest/client/screen/IronChestScreen.java +++ b/src/main/java/com/progwml6/ironchest/client/screen/IronChestScreen.java @@ -1,18 +1,18 @@ package com.progwml6.ironchest.client.screen; -import com.mojang.blaze3d.matrix.MatrixStack; +import com.mojang.blaze3d.vertex.PoseStack; import com.mojang.blaze3d.systems.RenderSystem; import com.progwml6.ironchest.common.block.IronChestsTypes; import com.progwml6.ironchest.common.inventory.IronChestContainer; -import net.minecraft.client.gui.IHasContainer; -import net.minecraft.client.gui.screen.inventory.ContainerScreen; -import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.util.text.ITextComponent; +import net.minecraft.client.gui.screens.inventory.MenuAccess; +import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.network.chat.Component; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; @OnlyIn(Dist.CLIENT) -public class IronChestScreen extends ContainerScreen implements IHasContainer { +public class IronChestScreen extends AbstractContainerScreen implements MenuAccess { private final IronChestsTypes chestType; @@ -20,12 +20,12 @@ public class IronChestScreen extends ContainerScreen impleme private final int textureYSize; - public IronChestScreen(IronChestContainer container, PlayerInventory playerInventory, ITextComponent title) { + public IronChestScreen(IronChestContainer container, Inventory playerInventory, Component title) { super(container, playerInventory, title); this.chestType = container.getChestType(); - this.xSize = container.getChestType().xSize; - this.ySize = container.getChestType().ySize; + this.imageWidth = container.getChestType().xSize; + this.imageHeight = container.getChestType().ySize; this.textureXSize = container.getChestType().textureXSize; this.textureYSize = container.getChestType().textureYSize; @@ -33,29 +33,29 @@ public class IronChestScreen extends ContainerScreen impleme } @Override - public void render(MatrixStack matrixStack, int mouseX, int mouseY, float partialTicks) { + public void render(PoseStack matrixStack, int mouseX, int mouseY, float partialTicks) { this.renderBackground(matrixStack); super.render(matrixStack, mouseX, mouseY, partialTicks); - this.renderHoveredTooltip(matrixStack, mouseX, mouseY); + this.renderTooltip(matrixStack, mouseX, mouseY); } @Override - protected void drawGuiContainerForegroundLayer(MatrixStack matrixStack, int mouseX, int mouseY) { - this.font.func_243248_b(matrixStack, this.title, 8.0F, 6.0F, 4210752); + protected void renderLabels(PoseStack matrixStack, int mouseX, int mouseY) { + this.font.draw(matrixStack, this.title, 8.0F, 6.0F, 4210752); - this.font.func_243248_b(matrixStack, this.playerInventory.getDisplayName(), 8.0F, (float) (this.ySize - 96 + 2), 4210752); + this.font.draw(matrixStack, this.inventory.getDisplayName(), 8.0F, (float) (this.imageHeight - 96 + 2), 4210752); } @Override - protected void drawGuiContainerBackgroundLayer(MatrixStack matrixStack, float partialTicks, int mouseX, int mouseY) { + protected void renderBg(PoseStack matrixStack, float partialTicks, int mouseX, int mouseY) { RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F); - this.minecraft.getTextureManager().bindTexture(this.chestType.guiTexture); + this.minecraft.getTextureManager().bind(this.chestType.guiTexture); - int x = (this.width - this.xSize) / 2; - int y = (this.height - this.ySize) / 2; + int x = (this.width - this.imageWidth) / 2; + int y = (this.height - this.imageHeight) / 2; - blit(matrixStack, x, y, 0, 0, this.xSize, this.ySize, this.textureXSize, this.textureYSize); + blit(matrixStack, x, y, 0, 0, this.imageWidth, this.imageHeight, this.textureXSize, this.textureYSize); } } diff --git a/src/main/java/com/progwml6/ironchest/common/ai/CatsSitOnChestsHandler.java b/src/main/java/com/progwml6/ironchest/common/ai/CatsSitOnChestsHandler.java index b874c63..c134ebe 100644 --- a/src/main/java/com/progwml6/ironchest/common/ai/CatsSitOnChestsHandler.java +++ b/src/main/java/com/progwml6/ironchest/common/ai/CatsSitOnChestsHandler.java @@ -1,8 +1,8 @@ package com.progwml6.ironchest.common.ai; -import net.minecraft.entity.ai.goal.CatSitOnBlockGoal; -import net.minecraft.entity.ai.goal.PrioritizedGoal; -import net.minecraft.entity.passive.CatEntity; +import net.minecraft.world.entity.ai.goal.CatSitOnBlockGoal; +import net.minecraft.world.entity.ai.goal.WrappedGoal; +import net.minecraft.world.entity.animal.Cat; import net.minecraftforge.event.entity.living.LivingEvent; import net.minecraftforge.eventbus.api.SubscribeEvent; @@ -12,18 +12,18 @@ public class CatsSitOnChestsHandler { @SubscribeEvent public void changeSittingTaskForOcelots(final LivingEvent.LivingUpdateEvent evt) { - if (evt.getEntityLiving().ticksExisted < 5 && evt.getEntityLiving() instanceof CatEntity) { - HashSet goals = new HashSet<>(); + if (evt.getEntityLiving().tickCount < 5 && evt.getEntityLiving() instanceof Cat) { + HashSet goals = new HashSet<>(); - CatEntity catEntity = (CatEntity) evt.getEntityLiving(); + Cat catEntity = (Cat) evt.getEntityLiving(); - for (PrioritizedGoal goal : catEntity.goalSelector.goals) { + for (WrappedGoal goal : catEntity.goalSelector.availableGoals) { if (goal.getGoal().getClass() == CatSitOnBlockGoal.class) { goals.add(goal); } } - for (PrioritizedGoal goal : goals) { + for (WrappedGoal goal : goals) { catEntity.goalSelector.removeGoal(goal.getGoal()); catEntity.goalSelector.addGoal(goal.getPriority(), new IronChestCatSitOnBlockGoal(catEntity, 0.4F)); } diff --git a/src/main/java/com/progwml6/ironchest/common/ai/IronChestCatSitOnBlockGoal.java b/src/main/java/com/progwml6/ironchest/common/ai/IronChestCatSitOnBlockGoal.java index d65a6c8..aaea8af 100644 --- a/src/main/java/com/progwml6/ironchest/common/ai/IronChestCatSitOnBlockGoal.java +++ b/src/main/java/com/progwml6/ironchest/common/ai/IronChestCatSitOnBlockGoal.java @@ -2,22 +2,22 @@ package com.progwml6.ironchest.common.ai; import com.progwml6.ironchest.common.block.GenericIronChestBlock; import com.progwml6.ironchest.common.block.tileentity.GenericIronChestTileEntity; -import net.minecraft.block.Block; -import net.minecraft.block.BlockState; -import net.minecraft.entity.ai.goal.CatSitOnBlockGoal; -import net.minecraft.entity.passive.CatEntity; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.IWorldReader; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.entity.ai.goal.CatSitOnBlockGoal; +import net.minecraft.world.entity.animal.Cat; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.LevelReader; public class IronChestCatSitOnBlockGoal extends CatSitOnBlockGoal { - public IronChestCatSitOnBlockGoal(CatEntity catEntity, double p_i50330_2_) { + public IronChestCatSitOnBlockGoal(Cat catEntity, double p_i50330_2_) { super(catEntity, p_i50330_2_); } @Override - protected boolean shouldMoveTo(IWorldReader worldIn, BlockPos pos) { - if (!worldIn.isAirBlock(pos.up())) { + protected boolean isValidTarget(LevelReader worldIn, BlockPos pos) { + if (!worldIn.isEmptyBlock(pos.above())) { return false; } else { @@ -28,7 +28,7 @@ public class IronChestCatSitOnBlockGoal extends CatSitOnBlockGoal { return GenericIronChestTileEntity.getPlayersUsing(worldIn, pos) < 1; } - return super.shouldMoveTo(worldIn, pos); + return super.isValidTarget(worldIn, pos); } } } diff --git a/src/main/java/com/progwml6/ironchest/common/block/CopperChestBlock.java b/src/main/java/com/progwml6/ironchest/common/block/CopperChestBlock.java index e7dd3a7..d195735 100644 --- a/src/main/java/com/progwml6/ironchest/common/block/CopperChestBlock.java +++ b/src/main/java/com/progwml6/ironchest/common/block/CopperChestBlock.java @@ -2,9 +2,11 @@ package com.progwml6.ironchest.common.block; import com.progwml6.ironchest.common.block.tileentity.CopperChestTileEntity; import com.progwml6.ironchest.common.block.tileentity.IronChestsTileEntityTypes; -import net.minecraft.block.BlockState; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.world.IBlockReader; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.BlockGetter; + +import net.minecraft.world.level.block.state.BlockBehaviour.Properties; public class CopperChestBlock extends GenericIronChestBlock { @@ -13,7 +15,7 @@ public class CopperChestBlock extends GenericIronChestBlock { } @Override - public TileEntity createTileEntity(BlockState state, IBlockReader world) { + public BlockEntity createTileEntity(BlockState state, BlockGetter world) { return new CopperChestTileEntity(); } } diff --git a/src/main/java/com/progwml6/ironchest/common/block/CrystalChestBlock.java b/src/main/java/com/progwml6/ironchest/common/block/CrystalChestBlock.java index 10c77e6..a9128df 100644 --- a/src/main/java/com/progwml6/ironchest/common/block/CrystalChestBlock.java +++ b/src/main/java/com/progwml6/ironchest/common/block/CrystalChestBlock.java @@ -2,9 +2,11 @@ package com.progwml6.ironchest.common.block; import com.progwml6.ironchest.common.block.tileentity.CrystalChestTileEntity; import com.progwml6.ironchest.common.block.tileentity.IronChestsTileEntityTypes; -import net.minecraft.block.BlockState; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.world.IBlockReader; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.BlockGetter; + +import net.minecraft.world.level.block.state.BlockBehaviour.Properties; public class CrystalChestBlock extends GenericIronChestBlock { @@ -14,7 +16,7 @@ public class CrystalChestBlock extends GenericIronChestBlock { @Override - public TileEntity createTileEntity(BlockState state, IBlockReader world) { + public BlockEntity createTileEntity(BlockState state, BlockGetter world) { return new CrystalChestTileEntity(); } } diff --git a/src/main/java/com/progwml6/ironchest/common/block/DiamondChestBlock.java b/src/main/java/com/progwml6/ironchest/common/block/DiamondChestBlock.java index 2f2dbe9..0cf51e9 100644 --- a/src/main/java/com/progwml6/ironchest/common/block/DiamondChestBlock.java +++ b/src/main/java/com/progwml6/ironchest/common/block/DiamondChestBlock.java @@ -2,9 +2,11 @@ package com.progwml6.ironchest.common.block; import com.progwml6.ironchest.common.block.tileentity.DiamondChestTileEntity; import com.progwml6.ironchest.common.block.tileentity.IronChestsTileEntityTypes; -import net.minecraft.block.BlockState; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.world.IBlockReader; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.BlockGetter; + +import net.minecraft.world.level.block.state.BlockBehaviour.Properties; public class DiamondChestBlock extends GenericIronChestBlock { @@ -13,7 +15,7 @@ public class DiamondChestBlock extends GenericIronChestBlock { } @Override - public TileEntity createTileEntity(BlockState state, IBlockReader world) { + public BlockEntity createTileEntity(BlockState state, BlockGetter world) { return new DiamondChestTileEntity(); } } \ No newline at end of file diff --git a/src/main/java/com/progwml6/ironchest/common/block/DirtChestBlock.java b/src/main/java/com/progwml6/ironchest/common/block/DirtChestBlock.java index 16bb62e..917c595 100644 --- a/src/main/java/com/progwml6/ironchest/common/block/DirtChestBlock.java +++ b/src/main/java/com/progwml6/ironchest/common/block/DirtChestBlock.java @@ -3,9 +3,11 @@ package com.progwml6.ironchest.common.block; import com.progwml6.ironchest.common.block.tileentity.DirtChestTileEntity; import com.progwml6.ironchest.common.block.tileentity.IronChestsTileEntityTypes; import com.progwml6.ironchest.common.block.tileentity.ObsidianChestTileEntity; -import net.minecraft.block.BlockState; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.world.IBlockReader; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.BlockGetter; + +import net.minecraft.world.level.block.state.BlockBehaviour.Properties; public class DirtChestBlock extends GenericIronChestBlock { @@ -14,7 +16,7 @@ public class DirtChestBlock extends GenericIronChestBlock { } @Override - public TileEntity createTileEntity(BlockState state, IBlockReader world) { + public BlockEntity createTileEntity(BlockState state, BlockGetter world) { return new DirtChestTileEntity(); } } diff --git a/src/main/java/com/progwml6/ironchest/common/block/GenericIronChestBlock.java b/src/main/java/com/progwml6/ironchest/common/block/GenericIronChestBlock.java index 2f5a70a..7affe47 100644 --- a/src/main/java/com/progwml6/ironchest/common/block/GenericIronChestBlock.java +++ b/src/main/java/com/progwml6/ironchest/common/block/GenericIronChestBlock.java @@ -2,48 +2,48 @@ package com.progwml6.ironchest.common.block; import com.progwml6.ironchest.common.block.tileentity.GenericIronChestTileEntity; import it.unimi.dsi.fastutil.floats.Float2FloatFunction; -import net.minecraft.block.Block; -import net.minecraft.block.BlockRenderType; -import net.minecraft.block.BlockState; -import net.minecraft.block.HorizontalBlock; -import net.minecraft.block.IWaterLoggable; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.passive.CatEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.fluid.Fluids; -import net.minecraft.fluid.FluidState; -import net.minecraft.inventory.IInventory; -import net.minecraft.inventory.InventoryHelper; -import net.minecraft.inventory.container.Container; -import net.minecraft.inventory.container.INamedContainerProvider; -import net.minecraft.item.BlockItemUseContext; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.pathfinding.PathType; -import net.minecraft.state.BooleanProperty; -import net.minecraft.state.DirectionProperty; -import net.minecraft.state.StateContainer; -import net.minecraft.state.properties.BlockStateProperties; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.RenderShape; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.HorizontalDirectionalBlock; +import net.minecraft.world.level.block.SimpleWaterloggedBlock; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.animal.Cat; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.level.material.Fluids; +import net.minecraft.world.level.material.FluidState; +import net.minecraft.world.Container; +import net.minecraft.world.Containers; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.MenuProvider; +import net.minecraft.world.item.context.BlockPlaceContext; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.level.pathfinder.PathComputationType; +import net.minecraft.world.level.block.state.properties.BooleanProperty; +import net.minecraft.world.level.block.state.properties.DirectionProperty; +import net.minecraft.world.level.block.state.StateDefinition; +import net.minecraft.world.level.block.state.properties.BlockStateProperties; import net.minecraft.stats.Stat; import net.minecraft.stats.Stats; -import net.minecraft.tileentity.IChestLid; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.tileentity.TileEntityMerger; -import net.minecraft.tileentity.TileEntityType; -import net.minecraft.util.ActionResultType; -import net.minecraft.util.Direction; -import net.minecraft.util.Hand; -import net.minecraft.util.Mirror; -import net.minecraft.util.ResourceLocation; -import net.minecraft.util.Rotation; -import net.minecraft.util.math.AxisAlignedBB; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.BlockRayTraceResult; -import net.minecraft.util.math.shapes.ISelectionContext; -import net.minecraft.util.math.shapes.VoxelShape; -import net.minecraft.world.IBlockReader; -import net.minecraft.world.IWorld; -import net.minecraft.world.World; +import net.minecraft.world.level.block.entity.LidBlockEntity; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.DoubleBlockCombiner; +import net.minecraft.world.level.block.entity.BlockEntityType; +import net.minecraft.world.InteractionResult; +import net.minecraft.core.Direction; +import net.minecraft.world.InteractionHand; +import net.minecraft.world.level.block.Mirror; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.world.level.block.Rotation; +import net.minecraft.world.phys.AABB; +import net.minecraft.core.BlockPos; +import net.minecraft.world.phys.BlockHitResult; +import net.minecraft.world.phys.shapes.CollisionContext; +import net.minecraft.world.phys.shapes.VoxelShape; +import net.minecraft.world.level.BlockGetter; +import net.minecraft.world.level.LevelAccessor; +import net.minecraft.world.level.Level; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; @@ -52,97 +52,99 @@ import java.util.List; import java.util.function.BiPredicate; import java.util.function.Supplier; -public class GenericIronChestBlock extends Block implements IWaterLoggable { +import net.minecraft.world.level.block.state.BlockBehaviour.Properties; - public static final DirectionProperty FACING = HorizontalBlock.HORIZONTAL_FACING; +public class GenericIronChestBlock extends Block implements SimpleWaterloggedBlock { + + public static final DirectionProperty FACING = HorizontalDirectionalBlock.FACING; public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED; - protected static final VoxelShape IRON_CHEST_SHAPE = Block.makeCuboidShape(1.0D, 0.0D, 1.0D, 15.0D, 14.0D, 15.0D); + protected static final VoxelShape IRON_CHEST_SHAPE = Block.box(1.0D, 0.0D, 1.0D, 15.0D, 14.0D, 15.0D); private final IronChestsTypes type; - private final Supplier> tileEntityTypeSupplier; + private final Supplier> tileEntityTypeSupplier; - public GenericIronChestBlock(IronChestsTypes typeIn, Supplier> tileEntityTypeSupplierIn, Properties propertiesIn) { + public GenericIronChestBlock(IronChestsTypes typeIn, Supplier> tileEntityTypeSupplierIn, Properties propertiesIn) { super(propertiesIn); this.type = typeIn; this.tileEntityTypeSupplier = tileEntityTypeSupplierIn; - this.setDefaultState(this.stateContainer.getBaseState().with(FACING, Direction.NORTH).with(WATERLOGGED, Boolean.valueOf(false))); + this.registerDefaultState(this.stateDefinition.any().setValue(FACING, Direction.NORTH).setValue(WATERLOGGED, Boolean.valueOf(false))); } @Override - public BlockRenderType getRenderType(BlockState state) { - return BlockRenderType.ENTITYBLOCK_ANIMATED; + public RenderShape getRenderShape(BlockState state) { + return RenderShape.ENTITYBLOCK_ANIMATED; } @Override - public BlockState updatePostPlacement(BlockState stateIn, Direction facing, BlockState facingState, IWorld worldIn, BlockPos currentPos, BlockPos facingPos) { - if (stateIn.get(WATERLOGGED)) { - worldIn.getPendingFluidTicks().scheduleTick(currentPos, Fluids.WATER, Fluids.WATER.getTickRate(worldIn)); + public BlockState updateShape(BlockState stateIn, Direction facing, BlockState facingState, LevelAccessor worldIn, BlockPos currentPos, BlockPos facingPos) { + if (stateIn.getValue(WATERLOGGED)) { + worldIn.getLiquidTicks().scheduleTick(currentPos, Fluids.WATER, Fluids.WATER.getTickDelay(worldIn)); } - return super.updatePostPlacement(stateIn, facing, facingState, worldIn, currentPos, facingPos); + return super.updateShape(stateIn, facing, facingState, worldIn, currentPos, facingPos); } @Override - public VoxelShape getShape(BlockState state, IBlockReader worldIn, BlockPos pos, ISelectionContext context) { + public VoxelShape getShape(BlockState state, BlockGetter worldIn, BlockPos pos, CollisionContext context) { return IRON_CHEST_SHAPE; } @Override - public BlockState getStateForPlacement(BlockItemUseContext context) { - Direction direction = context.getPlacementHorizontalFacing().getOpposite(); - FluidState ifluidstate = context.getWorld().getFluidState(context.getPos()); + public BlockState getStateForPlacement(BlockPlaceContext context) { + Direction direction = context.getHorizontalDirection().getOpposite(); + FluidState ifluidstate = context.getLevel().getFluidState(context.getClickedPos()); - return this.getDefaultState().with(FACING, direction).with(WATERLOGGED, ifluidstate.getFluid() == Fluids.WATER); + return this.defaultBlockState().setValue(FACING, direction).setValue(WATERLOGGED, ifluidstate.getType() == Fluids.WATER); } @Override public FluidState getFluidState(BlockState state) { - return state.get(WATERLOGGED) ? Fluids.WATER.getStillFluidState(false) : super.getFluidState(state); + return state.getValue(WATERLOGGED) ? Fluids.WATER.getSource(false) : super.getFluidState(state); } @Override - public void onBlockPlacedBy(World worldIn, BlockPos pos, BlockState state, LivingEntity placer, ItemStack stack) { - TileEntity tileentity = worldIn.getTileEntity(pos); + public void setPlacedBy(Level worldIn, BlockPos pos, BlockState state, LivingEntity placer, ItemStack stack) { + BlockEntity tileentity = worldIn.getBlockEntity(pos); if (tileentity instanceof GenericIronChestTileEntity) { ((GenericIronChestTileEntity) tileentity).wasPlaced(placer, stack); - if (stack.hasDisplayName()) { - ((GenericIronChestTileEntity) tileentity).setCustomName(stack.getDisplayName()); + if (stack.hasCustomHoverName()) { + ((GenericIronChestTileEntity) tileentity).setCustomName(stack.getHoverName()); } } } @Override - public void onReplaced(BlockState state, World worldIn, BlockPos pos, BlockState newState, boolean isMoving) { + public void onRemove(BlockState state, Level worldIn, BlockPos pos, BlockState newState, boolean isMoving) { if (state.getBlock() != newState.getBlock()) { - TileEntity tileentity = worldIn.getTileEntity(pos); + BlockEntity tileentity = worldIn.getBlockEntity(pos); if (tileentity instanceof GenericIronChestTileEntity) { ((GenericIronChestTileEntity) tileentity).removeAdornments(); - InventoryHelper.dropInventoryItems(worldIn, pos, (GenericIronChestTileEntity) tileentity); - worldIn.updateComparatorOutputLevel(pos, this); + Containers.dropContents(worldIn, pos, (GenericIronChestTileEntity) tileentity); + worldIn.updateNeighbourForOutputSignal(pos, this); } - super.onReplaced(state, worldIn, pos, newState, isMoving); + super.onRemove(state, worldIn, pos, newState, isMoving); } } @Override - public ActionResultType onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult hit) { - if (!worldIn.isRemote) { - INamedContainerProvider inamedcontainerprovider = this.getContainer(state, worldIn, pos); + public InteractionResult use(BlockState state, Level worldIn, BlockPos pos, Player player, InteractionHand handIn, BlockHitResult hit) { + if (!worldIn.isClientSide) { + MenuProvider inamedcontainerprovider = this.getMenuProvider(state, worldIn, pos); if (inamedcontainerprovider != null) { - player.openContainer(inamedcontainerprovider); - player.addStat(this.getOpenStat()); + player.openMenu(inamedcontainerprovider); + player.awardStat(this.getOpenStat()); } } - return ActionResultType.SUCCESS; + return InteractionResult.SUCCESS; } protected Stat getOpenStat() { @@ -151,9 +153,9 @@ public class GenericIronChestBlock extends Block implements IWaterLoggable { @Override @Nullable - public INamedContainerProvider getContainer(BlockState state, World world, BlockPos pos) { - TileEntity tileentity = world.getTileEntity(pos); - return tileentity instanceof INamedContainerProvider ? (INamedContainerProvider) tileentity : null; + public MenuProvider getMenuProvider(BlockState state, Level world, BlockPos pos) { + BlockEntity tileentity = world.getBlockEntity(pos); + return tileentity instanceof MenuProvider ? (MenuProvider) tileentity : null; } @Override @@ -162,25 +164,25 @@ public class GenericIronChestBlock extends Block implements IWaterLoggable { } @Override - public boolean eventReceived(BlockState state, World worldIn, BlockPos pos, int id, int param) { - super.eventReceived(state, worldIn, pos, id, param); - TileEntity tileentity = worldIn.getTileEntity(pos); - return tileentity == null ? false : tileentity.receiveClientEvent(id, param); + public boolean triggerEvent(BlockState state, Level worldIn, BlockPos pos, int id, int param) { + super.triggerEvent(state, worldIn, pos, id, param); + BlockEntity tileentity = worldIn.getBlockEntity(pos); + return tileentity == null ? false : tileentity.triggerEvent(id, param); } - private static boolean isBlocked(IWorld iWorld, BlockPos blockPos) { + private static boolean isBlocked(LevelAccessor iWorld, BlockPos blockPos) { return isBelowSolidBlock(iWorld, blockPos) || isCatSittingOn(iWorld, blockPos); } - private static boolean isBelowSolidBlock(IBlockReader iBlockReader, BlockPos worldIn) { - BlockPos blockpos = worldIn.up(); - return iBlockReader.getBlockState(blockpos).isNormalCube(iBlockReader, blockpos); + private static boolean isBelowSolidBlock(BlockGetter iBlockReader, BlockPos worldIn) { + BlockPos blockpos = worldIn.above(); + return iBlockReader.getBlockState(blockpos).isRedstoneConductor(iBlockReader, blockpos); } - private static boolean isCatSittingOn(IWorld iWorld, BlockPos blockPos) { - List list = iWorld.getEntitiesWithinAABB(CatEntity.class, new AxisAlignedBB((double) blockPos.getX(), (double) (blockPos.getY() + 1), (double) blockPos.getZ(), (double) (blockPos.getX() + 1), (double) (blockPos.getY() + 2), (double) (blockPos.getZ() + 1))); + private static boolean isCatSittingOn(LevelAccessor iWorld, BlockPos blockPos) { + List list = iWorld.getEntitiesOfClass(Cat.class, new AABB((double) blockPos.getX(), (double) (blockPos.getY() + 1), (double) blockPos.getZ(), (double) (blockPos.getX() + 1), (double) (blockPos.getY() + 2), (double) (blockPos.getZ() + 1))); if (!list.isEmpty()) { - for (CatEntity catentity : list) { + for (Cat catentity : list) { if (catentity.isSleeping()) { return true; } @@ -191,37 +193,37 @@ public class GenericIronChestBlock extends Block implements IWaterLoggable { } @Override - public boolean hasComparatorInputOverride(BlockState state) { + public boolean hasAnalogOutputSignal(BlockState state) { return true; } @Override - public int getComparatorInputOverride(BlockState blockState, World worldIn, BlockPos pos) { - return Container.calcRedstoneFromInventory((IInventory) worldIn.getTileEntity(pos)); + public int getAnalogOutputSignal(BlockState blockState, Level worldIn, BlockPos pos) { + return AbstractContainerMenu.getRedstoneSignalFromContainer((Container) worldIn.getBlockEntity(pos)); } @Override public BlockState rotate(BlockState state, Rotation rot) { - return state.with(FACING, rot.rotate(state.get(FACING))); + return state.setValue(FACING, rot.rotate(state.getValue(FACING))); } @Override public BlockState mirror(BlockState state, Mirror mirrorIn) { - return state.rotate(mirrorIn.toRotation(state.get(FACING))); + return state.rotate(mirrorIn.getRotation(state.getValue(FACING))); } @Override - protected void fillStateContainer(StateContainer.Builder builder) { + protected void createBlockStateDefinition(StateDefinition.Builder builder) { builder.add(FACING, WATERLOGGED); } @Override - public boolean allowsMovement(BlockState state, IBlockReader worldIn, BlockPos pos, PathType type) { + public boolean isPathfindable(BlockState state, BlockGetter worldIn, BlockPos pos, PathComputationType type) { return false; } public static IronChestsTypes getTypeFromItem(Item itemIn) { - return getTypeFromBlock(Block.getBlockFromItem(itemIn)); + return getTypeFromBlock(Block.byItem(itemIn)); } public static IronChestsTypes getTypeFromBlock(Block blockIn) { @@ -233,29 +235,29 @@ public class GenericIronChestBlock extends Block implements IWaterLoggable { } @OnlyIn(Dist.CLIENT) - public static TileEntityMerger.ICallback getLid(final IChestLid p_226917_0_) { - return new TileEntityMerger.ICallback() { + public static DoubleBlockCombiner.Combiner getLid(final LidBlockEntity p_226917_0_) { + return new DoubleBlockCombiner.Combiner() { @Override - public Float2FloatFunction func_225539_a_(GenericIronChestTileEntity p_225539_1_, GenericIronChestTileEntity p_225539_2_) { + public Float2FloatFunction acceptDouble(GenericIronChestTileEntity p_225539_1_, GenericIronChestTileEntity p_225539_2_) { return (p_226921_2_) -> { - return Math.max(p_225539_1_.getLidAngle(p_226921_2_), p_225539_2_.getLidAngle(p_226921_2_)); + return Math.max(p_225539_1_.getOpenNess(p_226921_2_), p_225539_2_.getOpenNess(p_226921_2_)); }; } @Override - public Float2FloatFunction func_225538_a_(GenericIronChestTileEntity p_225538_1_) { - return p_225538_1_::getLidAngle; + public Float2FloatFunction acceptSingle(GenericIronChestTileEntity p_225538_1_) { + return p_225538_1_::getOpenNess; } @Override - public Float2FloatFunction func_225537_b_() { - return p_226917_0_::getLidAngle; + public Float2FloatFunction acceptNone() { + return p_226917_0_::getOpenNess; } }; } - public TileEntityMerger.ICallbackWrapper getWrapper(BlockState blockState, World world, BlockPos blockPos, boolean p_225536_4_) { - BiPredicate biPredicate; + public DoubleBlockCombiner.NeighborCombineResult getWrapper(BlockState blockState, Level world, BlockPos blockPos, boolean p_225536_4_) { + BiPredicate biPredicate; if (p_225536_4_) { biPredicate = (p_226918_0_, p_226918_1_) -> false; } @@ -263,15 +265,15 @@ public class GenericIronChestBlock extends Block implements IWaterLoggable { biPredicate = GenericIronChestBlock::isBlocked; } - return TileEntityMerger.func_226924_a_(this.tileEntityTypeSupplier.get(), GenericIronChestBlock::getMergerType, GenericIronChestBlock::getDirectionToAttached, FACING, blockState, world, blockPos, biPredicate); + return DoubleBlockCombiner.combineWithNeigbour(this.tileEntityTypeSupplier.get(), GenericIronChestBlock::getMergerType, GenericIronChestBlock::getDirectionToAttached, FACING, blockState, world, blockPos, biPredicate); } - public static TileEntityMerger.Type getMergerType(BlockState blockState) { - return TileEntityMerger.Type.SINGLE; + public static DoubleBlockCombiner.BlockType getMergerType(BlockState blockState) { + return DoubleBlockCombiner.BlockType.SINGLE; } public static Direction getDirectionToAttached(BlockState state) { - Direction direction = state.get(FACING); - return direction.rotateYCCW(); + Direction direction = state.getValue(FACING); + return direction.getCounterClockWise(); } } diff --git a/src/main/java/com/progwml6/ironchest/common/block/GoldChestBlock.java b/src/main/java/com/progwml6/ironchest/common/block/GoldChestBlock.java index e168d51..e6ca1b6 100644 --- a/src/main/java/com/progwml6/ironchest/common/block/GoldChestBlock.java +++ b/src/main/java/com/progwml6/ironchest/common/block/GoldChestBlock.java @@ -2,9 +2,11 @@ package com.progwml6.ironchest.common.block; import com.progwml6.ironchest.common.block.tileentity.GoldChestTileEntity; import com.progwml6.ironchest.common.block.tileentity.IronChestsTileEntityTypes; -import net.minecraft.block.BlockState; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.world.IBlockReader; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.BlockGetter; + +import net.minecraft.world.level.block.state.BlockBehaviour.Properties; public class GoldChestBlock extends GenericIronChestBlock { @@ -13,7 +15,7 @@ public class GoldChestBlock extends GenericIronChestBlock { } @Override - public TileEntity createTileEntity(BlockState state, IBlockReader world) { + public BlockEntity createTileEntity(BlockState state, BlockGetter world) { return new GoldChestTileEntity(); } } diff --git a/src/main/java/com/progwml6/ironchest/common/block/IronChestBlock.java b/src/main/java/com/progwml6/ironchest/common/block/IronChestBlock.java index 468e494..78ea061 100644 --- a/src/main/java/com/progwml6/ironchest/common/block/IronChestBlock.java +++ b/src/main/java/com/progwml6/ironchest/common/block/IronChestBlock.java @@ -2,10 +2,10 @@ package com.progwml6.ironchest.common.block; import com.progwml6.ironchest.common.block.tileentity.IronChestTileEntity; import com.progwml6.ironchest.common.block.tileentity.IronChestsTileEntityTypes; -import net.minecraft.block.Block; -import net.minecraft.block.BlockState; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.world.IBlockReader; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.BlockGetter; public class IronChestBlock extends GenericIronChestBlock { @@ -14,7 +14,7 @@ public class IronChestBlock extends GenericIronChestBlock { } @Override - public TileEntity createTileEntity(BlockState state, IBlockReader world) { + public BlockEntity createTileEntity(BlockState state, BlockGetter world) { return new IronChestTileEntity(); } } diff --git a/src/main/java/com/progwml6/ironchest/common/block/IronChestsBlocks.java b/src/main/java/com/progwml6/ironchest/common/block/IronChestsBlocks.java index 2d05738..7b2b296 100644 --- a/src/main/java/com/progwml6/ironchest/common/block/IronChestsBlocks.java +++ b/src/main/java/com/progwml6/ironchest/common/block/IronChestsBlocks.java @@ -11,11 +11,11 @@ import com.progwml6.ironchest.common.block.tileentity.IronChestTileEntity; import com.progwml6.ironchest.common.block.tileentity.ObsidianChestTileEntity; import com.progwml6.ironchest.common.block.tileentity.SilverChestTileEntity; import com.progwml6.ironchest.common.item.IronChestsItems; -import net.minecraft.block.Block; -import net.minecraft.block.material.Material; -import net.minecraft.client.renderer.tileentity.ItemStackTileEntityRenderer; -import net.minecraft.item.BlockItem; -import net.minecraft.item.Item; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.material.Material; +import net.minecraft.client.renderer.BlockEntityWithoutLevelRenderer; +import net.minecraft.world.item.BlockItem; +import net.minecraft.world.item.Item; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.fml.RegistryObject; @@ -32,38 +32,38 @@ public class IronChestsBlocks { public static final DeferredRegister ITEMS = IronChestsItems.ITEMS; public static final RegistryObject IRON_CHEST = register( - "iron_chest", () -> new IronChestBlock(Block.Properties.create(Material.IRON).hardnessAndResistance(3.0F)), + "iron_chest", () -> new IronChestBlock(Block.Properties.of(Material.METAL).strength(3.0F)), () -> ironChestRenderer()); public static final RegistryObject GOLD_CHEST = register( - "gold_chest", () -> new GoldChestBlock(Block.Properties.create(Material.IRON).hardnessAndResistance(3.0F)), + "gold_chest", () -> new GoldChestBlock(Block.Properties.of(Material.METAL).strength(3.0F)), () -> goldChestRenderer()); public static final RegistryObject DIAMOND_CHEST = register( - "diamond_chest", () -> new DiamondChestBlock(Block.Properties.create(Material.IRON).hardnessAndResistance(3.0F)), + "diamond_chest", () -> new DiamondChestBlock(Block.Properties.of(Material.METAL).strength(3.0F)), () -> diamondChestRenderer()); public static final RegistryObject COPPER_CHEST = register( - "copper_chest", () -> new CopperChestBlock(Block.Properties.create(Material.IRON).hardnessAndResistance(3.0F)), + "copper_chest", () -> new CopperChestBlock(Block.Properties.of(Material.METAL).strength(3.0F)), () -> copperChestRenderer()); public static final RegistryObject SILVER_CHEST = register( - "silver_chest", () -> new SilverChestBlock(Block.Properties.create(Material.IRON).hardnessAndResistance(3.0F)), + "silver_chest", () -> new SilverChestBlock(Block.Properties.of(Material.METAL).strength(3.0F)), () -> silverChestRenderer()); public static final RegistryObject CRYSTAL_CHEST = register( - "crystal_chest", () -> new CrystalChestBlock(Block.Properties.create(Material.IRON).hardnessAndResistance(3.0F)), + "crystal_chest", () -> new CrystalChestBlock(Block.Properties.of(Material.METAL).strength(3.0F)), () -> crystalChestRenderer()); public static final RegistryObject OBSIDIAN_CHEST = register( - "obsidian_chest", () -> new ObsidianChestBlock(Block.Properties.create(Material.IRON).hardnessAndResistance(3.0F, 10000.0F)), + "obsidian_chest", () -> new ObsidianChestBlock(Block.Properties.of(Material.METAL).strength(3.0F, 10000.0F)), () -> obsidianChestRenderer()); public static final RegistryObject DIRT_CHEST = register( - "dirt_chest", () -> new DirtChestBlock(Block.Properties.create(Material.IRON).hardnessAndResistance(3.0F)), + "dirt_chest", () -> new DirtChestBlock(Block.Properties.of(Material.METAL).strength(3.0F)), () -> dirtChestRenderer()); - private static RegistryObject register(String name, Supplier sup, Supplier> renderMethod) { + private static RegistryObject register(String name, Supplier sup, Supplier> renderMethod) { return register(name, sup, block -> item(block, renderMethod)); } @@ -77,47 +77,47 @@ public class IronChestsBlocks { return BLOCKS.register(name, sup); } - private static Supplier item(final RegistryObject block, final Supplier> renderMethod) { - return () -> new BlockItem(block.get(), new Item.Properties().group(IronChests.IRONCHESTS_ITEM_GROUP).setISTER(renderMethod)); + private static Supplier item(final RegistryObject block, final Supplier> renderMethod) { + return () -> new BlockItem(block.get(), new Item.Properties().tab(IronChests.IRONCHESTS_ITEM_GROUP).setISTER(renderMethod)); } @OnlyIn(Dist.CLIENT) - private static Callable ironChestRenderer() { + private static Callable ironChestRenderer() { return () -> new IronChestItemStackRenderer(IronChestTileEntity::new); } @OnlyIn(Dist.CLIENT) - private static Callable goldChestRenderer() { + private static Callable goldChestRenderer() { return () -> new IronChestItemStackRenderer(GoldChestTileEntity::new); } @OnlyIn(Dist.CLIENT) - private static Callable diamondChestRenderer() { + private static Callable diamondChestRenderer() { return () -> new IronChestItemStackRenderer(DiamondChestTileEntity::new); } @OnlyIn(Dist.CLIENT) - private static Callable copperChestRenderer() { + private static Callable copperChestRenderer() { return () -> new IronChestItemStackRenderer(CopperChestTileEntity::new); } @OnlyIn(Dist.CLIENT) - private static Callable silverChestRenderer() { + private static Callable silverChestRenderer() { return () -> new IronChestItemStackRenderer(SilverChestTileEntity::new); } @OnlyIn(Dist.CLIENT) - private static Callable crystalChestRenderer() { + private static Callable crystalChestRenderer() { return () -> new IronChestItemStackRenderer(CrystalChestTileEntity::new); } @OnlyIn(Dist.CLIENT) - private static Callable obsidianChestRenderer() { + private static Callable obsidianChestRenderer() { return () -> new IronChestItemStackRenderer(ObsidianChestTileEntity::new); } @OnlyIn(Dist.CLIENT) - private static Callable dirtChestRenderer() { + private static Callable dirtChestRenderer() { return () -> new IronChestItemStackRenderer(DirtChestTileEntity::new); } } diff --git a/src/main/java/com/progwml6/ironchest/common/block/IronChestsTypes.java b/src/main/java/com/progwml6/ironchest/common/block/IronChestsTypes.java index aab6cd0..a3aac5d 100644 --- a/src/main/java/com/progwml6/ironchest/common/block/IronChestsTypes.java +++ b/src/main/java/com/progwml6/ironchest/common/block/IronChestsTypes.java @@ -10,15 +10,15 @@ import com.progwml6.ironchest.common.block.tileentity.GoldChestTileEntity; import com.progwml6.ironchest.common.block.tileentity.IronChestTileEntity; import com.progwml6.ironchest.common.block.tileentity.ObsidianChestTileEntity; import com.progwml6.ironchest.common.block.tileentity.SilverChestTileEntity; -import net.minecraft.block.Block; -import net.minecraft.block.Blocks; -import net.minecraft.util.IStringSerializable; -import net.minecraft.util.ResourceLocation; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.util.StringRepresentable; +import net.minecraft.resources.ResourceLocation; import javax.annotation.Nullable; import java.util.Locale; -public enum IronChestsTypes implements IStringSerializable { +public enum IronChestsTypes implements StringRepresentable { IRON(54, 9, 184, 222, new ResourceLocation("ironchest", "textures/gui/iron_container.png"), 256, 256), GOLD(81, 9, 184, 276, new ResourceLocation("ironchest", "textures/gui/gold_container.png"), 256, 276), @@ -63,7 +63,7 @@ public enum IronChestsTypes implements IStringSerializable { } @Override - public String getString() { + public String getSerializedName() { return this.getEnglishName(); } diff --git a/src/main/java/com/progwml6/ironchest/common/block/ObsidianChestBlock.java b/src/main/java/com/progwml6/ironchest/common/block/ObsidianChestBlock.java index 01e6501..c14c851 100644 --- a/src/main/java/com/progwml6/ironchest/common/block/ObsidianChestBlock.java +++ b/src/main/java/com/progwml6/ironchest/common/block/ObsidianChestBlock.java @@ -3,9 +3,11 @@ package com.progwml6.ironchest.common.block; import com.progwml6.ironchest.common.block.tileentity.IronChestsTileEntityTypes; import com.progwml6.ironchest.common.block.tileentity.ObsidianChestTileEntity; import com.progwml6.ironchest.common.block.tileentity.SilverChestTileEntity; -import net.minecraft.block.BlockState; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.world.IBlockReader; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.BlockGetter; + +import net.minecraft.world.level.block.state.BlockBehaviour.Properties; public class ObsidianChestBlock extends GenericIronChestBlock { @@ -14,7 +16,7 @@ public class ObsidianChestBlock extends GenericIronChestBlock { } @Override - public TileEntity createTileEntity(BlockState state, IBlockReader world) { + public BlockEntity createTileEntity(BlockState state, BlockGetter world) { return new ObsidianChestTileEntity(); } } diff --git a/src/main/java/com/progwml6/ironchest/common/block/SilverChestBlock.java b/src/main/java/com/progwml6/ironchest/common/block/SilverChestBlock.java index 09b58da..ecfc5c7 100644 --- a/src/main/java/com/progwml6/ironchest/common/block/SilverChestBlock.java +++ b/src/main/java/com/progwml6/ironchest/common/block/SilverChestBlock.java @@ -3,9 +3,11 @@ package com.progwml6.ironchest.common.block; import com.progwml6.ironchest.common.block.tileentity.CopperChestTileEntity; import com.progwml6.ironchest.common.block.tileentity.IronChestsTileEntityTypes; import com.progwml6.ironchest.common.block.tileentity.SilverChestTileEntity; -import net.minecraft.block.BlockState; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.world.IBlockReader; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.BlockGetter; + +import net.minecraft.world.level.block.state.BlockBehaviour.Properties; public class SilverChestBlock extends GenericIronChestBlock { @@ -14,7 +16,7 @@ public class SilverChestBlock extends GenericIronChestBlock { } @Override - public TileEntity createTileEntity(BlockState state, IBlockReader world) { + public BlockEntity createTileEntity(BlockState state, BlockGetter world) { return new SilverChestTileEntity(); } } diff --git a/src/main/java/com/progwml6/ironchest/common/block/tileentity/CopperChestTileEntity.java b/src/main/java/com/progwml6/ironchest/common/block/tileentity/CopperChestTileEntity.java index 8de2985..790d25b 100644 --- a/src/main/java/com/progwml6/ironchest/common/block/tileentity/CopperChestTileEntity.java +++ b/src/main/java/com/progwml6/ironchest/common/block/tileentity/CopperChestTileEntity.java @@ -3,8 +3,8 @@ package com.progwml6.ironchest.common.block.tileentity; import com.progwml6.ironchest.common.block.IronChestsBlocks; import com.progwml6.ironchest.common.block.IronChestsTypes; import com.progwml6.ironchest.common.inventory.IronChestContainer; -import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.inventory.container.Container; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.inventory.AbstractContainerMenu; public class CopperChestTileEntity extends GenericIronChestTileEntity { @@ -13,7 +13,7 @@ public class CopperChestTileEntity extends GenericIronChestTileEntity { } @Override - protected Container createMenu(int id, PlayerInventory playerInventory) { + protected AbstractContainerMenu createMenu(int id, Inventory playerInventory) { return IronChestContainer.createCopperContainer(id, playerInventory, this); } } \ No newline at end of file diff --git a/src/main/java/com/progwml6/ironchest/common/block/tileentity/CrystalChestTileEntity.java b/src/main/java/com/progwml6/ironchest/common/block/tileentity/CrystalChestTileEntity.java index 7d2df4a..e1bd9e8 100644 --- a/src/main/java/com/progwml6/ironchest/common/block/tileentity/CrystalChestTileEntity.java +++ b/src/main/java/com/progwml6/ironchest/common/block/tileentity/CrystalChestTileEntity.java @@ -5,12 +5,12 @@ import com.progwml6.ironchest.common.block.IronChestsTypes; import com.progwml6.ironchest.common.inventory.IronChestContainer; import com.progwml6.ironchest.common.network.InventoryTopStacksSyncPacket; import com.progwml6.ironchest.common.network.IronChestNetwork; -import net.minecraft.block.BlockState; -import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.inventory.container.Container; -import net.minecraft.item.ItemStack; -import net.minecraft.util.NonNullList; -import net.minecraft.world.server.ServerWorld; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.item.ItemStack; +import net.minecraft.core.NonNullList; +import net.minecraft.server.level.ServerLevel; import net.minecraftforge.fml.network.PacketDistributor; import java.util.Collections; @@ -29,7 +29,7 @@ public class CrystalChestTileEntity extends GenericIronChestTileEntity { } @Override - protected Container createMenu(int id, PlayerInventory playerInventory) { + protected AbstractContainerMenu createMenu(int id, Inventory playerInventory) { return IronChestContainer.createCrystalContainer(id, playerInventory, this); } @@ -37,7 +37,7 @@ public class CrystalChestTileEntity extends GenericIronChestTileEntity { public void tick() { super.tick(); - if (!this.world.isRemote && this.inventoryTouched) { + if (!this.level.isClientSide && this.inventoryTouched) { this.inventoryTouched = false; this.sortTopStacks(); @@ -52,10 +52,10 @@ public class CrystalChestTileEntity extends GenericIronChestTileEntity { } @Override - public ItemStack getStackInSlot(int index) { + public ItemStack getItem(int index) { this.inventoryTouched = true; - return super.getStackInSlot(index); + return super.getItem(index); } public NonNullList getTopItems() { @@ -63,25 +63,25 @@ public class CrystalChestTileEntity extends GenericIronChestTileEntity { } private void sortTopStacks() { - if (!this.getChestType().isTransparent() || (this.world != null && this.world.isRemote)) { + if (!this.getChestType().isTransparent() || (this.level != null && this.level.isClientSide)) { return; } - NonNullList tempCopy = NonNullList.withSize(this.getSizeInventory(), ItemStack.EMPTY); + NonNullList tempCopy = NonNullList.withSize(this.getContainerSize(), ItemStack.EMPTY); boolean hasStuff = false; int compressedIdx = 0; mainLoop: - for (int i = 0; i < this.getSizeInventory(); i++) { + for (int i = 0; i < this.getContainerSize(); i++) { ItemStack itemStack = this.getItems().get(i); if (!itemStack.isEmpty()) { for (int j = 0; j < compressedIdx; j++) { ItemStack tempCopyStack = tempCopy.get(j); - if (ItemStack.areItemsEqualIgnoreDurability(tempCopyStack, itemStack)) { + if (ItemStack.isSameIgnoreDurability(tempCopyStack, itemStack)) { if (itemStack.getCount() != tempCopyStack.getCount()) { tempCopyStack.grow(itemStack.getCount()); } @@ -105,10 +105,10 @@ public class CrystalChestTileEntity extends GenericIronChestTileEntity { this.getTopItems().set(i, ItemStack.EMPTY); } - if (this.world != null) { - BlockState iblockstate = this.world.getBlockState(this.pos); + if (this.level != null) { + BlockState iblockstate = this.level.getBlockState(this.worldPosition); - this.world.notifyBlockUpdate(this.pos, iblockstate, iblockstate, 3); + this.level.sendBlockUpdated(this.worldPosition, iblockstate, iblockstate, 3); } return; @@ -146,10 +146,10 @@ public class CrystalChestTileEntity extends GenericIronChestTileEntity { this.getTopItems().set(i, ItemStack.EMPTY); } - if (this.world != null) { - BlockState iblockstate = this.world.getBlockState(this.pos); + if (this.level != null) { + BlockState iblockstate = this.level.getBlockState(this.worldPosition); - this.world.notifyBlockUpdate(this.pos, iblockstate, iblockstate, 3); + this.level.sendBlockUpdated(this.worldPosition, iblockstate, iblockstate, 3); } sendTopStacksPacket(); @@ -181,8 +181,8 @@ public class CrystalChestTileEntity extends GenericIronChestTileEntity { protected void sendTopStacksPacket() { NonNullList stacks = this.buildItemStackDataList(); - if (this.world != null && this.world instanceof ServerWorld && !this.world.isRemote) { - IronChestNetwork.getInstance().sendToClientsAround(new InventoryTopStacksSyncPacket(stacks, this.pos), (ServerWorld) this.world, this.pos); + if (this.level != null && this.level instanceof ServerLevel && !this.level.isClientSide) { + IronChestNetwork.getInstance().sendToClientsAround(new InventoryTopStacksSyncPacket(stacks, this.worldPosition), (ServerLevel) this.level, this.worldPosition); } } diff --git a/src/main/java/com/progwml6/ironchest/common/block/tileentity/DiamondChestTileEntity.java b/src/main/java/com/progwml6/ironchest/common/block/tileentity/DiamondChestTileEntity.java index 582ed69..4905323 100644 --- a/src/main/java/com/progwml6/ironchest/common/block/tileentity/DiamondChestTileEntity.java +++ b/src/main/java/com/progwml6/ironchest/common/block/tileentity/DiamondChestTileEntity.java @@ -3,8 +3,8 @@ package com.progwml6.ironchest.common.block.tileentity; import com.progwml6.ironchest.common.block.IronChestsBlocks; import com.progwml6.ironchest.common.block.IronChestsTypes; import com.progwml6.ironchest.common.inventory.IronChestContainer; -import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.inventory.container.Container; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.inventory.AbstractContainerMenu; public class DiamondChestTileEntity extends GenericIronChestTileEntity { @@ -13,7 +13,7 @@ public class DiamondChestTileEntity extends GenericIronChestTileEntity { } @Override - protected Container createMenu(int id, PlayerInventory playerInventory) { + protected AbstractContainerMenu createMenu(int id, Inventory playerInventory) { return IronChestContainer.createDiamondContainer(id, playerInventory, this); } } diff --git a/src/main/java/com/progwml6/ironchest/common/block/tileentity/DirtChestTileEntity.java b/src/main/java/com/progwml6/ironchest/common/block/tileentity/DirtChestTileEntity.java index 1df6d63..f584f67 100644 --- a/src/main/java/com/progwml6/ironchest/common/block/tileentity/DirtChestTileEntity.java +++ b/src/main/java/com/progwml6/ironchest/common/block/tileentity/DirtChestTileEntity.java @@ -3,16 +3,16 @@ package com.progwml6.ironchest.common.block.tileentity; import com.progwml6.ironchest.common.block.IronChestsBlocks; import com.progwml6.ironchest.common.block.IronChestsTypes; import com.progwml6.ironchest.common.inventory.IronChestContainer; -import net.minecraft.client.resources.I18n; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.inventory.container.Container; -import net.minecraft.item.ItemStack; -import net.minecraft.item.Items; -import net.minecraft.nbt.ListNBT; -import net.minecraft.nbt.StringNBT; -import net.minecraft.util.text.ITextComponent; -import net.minecraft.util.text.TranslationTextComponent; +import net.minecraft.client.resources.language.I18n; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.Items; +import net.minecraft.nbt.ListTag; +import net.minecraft.nbt.StringTag; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.TranslatableComponent; public class DirtChestTileEntity extends GenericIronChestTileEntity { @@ -29,7 +29,7 @@ public class DirtChestTileEntity extends GenericIronChestTileEntity { } @Override - protected Container createMenu(int id, PlayerInventory playerInventory) { + protected AbstractContainerMenu createMenu(int id, Inventory playerInventory) { return IronChestContainer.createDirtContainer(id, playerInventory, this); } @@ -47,24 +47,24 @@ public class DirtChestTileEntity extends GenericIronChestTileEntity { @Override public void removeAdornments() { - if (!this.getItems().get(0).isEmpty() && this.getItems().get(0).isItemEqual(dirtChest9000GuideBook)) { + if (!this.getItems().get(0).isEmpty() && this.getItems().get(0).sameItem(dirtChest9000GuideBook)) { this.getItems().set(0, ItemStack.EMPTY); } } private static void createBookData() { - dirtChest9000GuideBook.setTagInfo("author", StringNBT.valueOf("cpw")); + dirtChest9000GuideBook.addTagElement("author", StringTag.valueOf("cpw")); - dirtChest9000GuideBook.setTagInfo("title", StringNBT.valueOf(I18n.format("book.ironchest.dirtchest9000.title"))); + dirtChest9000GuideBook.addTagElement("title", StringTag.valueOf(I18n.get("book.ironchest.dirtchest9000.title"))); - ListNBT pages = new ListNBT(); - pages.add(StringNBT.valueOf(ITextComponent.Serializer.toJson(new TranslationTextComponent("book.ironchest.dirtchest9000.page1")))); - pages.add(StringNBT.valueOf(ITextComponent.Serializer.toJson(new TranslationTextComponent("book.ironchest.dirtchest9000.page2")))); - pages.add(StringNBT.valueOf(ITextComponent.Serializer.toJson(new TranslationTextComponent("book.ironchest.dirtchest9000.page3")))); - pages.add(StringNBT.valueOf(ITextComponent.Serializer.toJson(new TranslationTextComponent("book.ironchest.dirtchest9000.page4")))); - pages.add(StringNBT.valueOf(ITextComponent.Serializer.toJson(new TranslationTextComponent("book.ironchest.dirtchest9000.page5")))); + ListTag pages = new ListTag(); + pages.add(StringTag.valueOf(Component.Serializer.toJson(new TranslatableComponent("book.ironchest.dirtchest9000.page1")))); + pages.add(StringTag.valueOf(Component.Serializer.toJson(new TranslatableComponent("book.ironchest.dirtchest9000.page2")))); + pages.add(StringTag.valueOf(Component.Serializer.toJson(new TranslatableComponent("book.ironchest.dirtchest9000.page3")))); + pages.add(StringTag.valueOf(Component.Serializer.toJson(new TranslatableComponent("book.ironchest.dirtchest9000.page4")))); + pages.add(StringTag.valueOf(Component.Serializer.toJson(new TranslatableComponent("book.ironchest.dirtchest9000.page5")))); - dirtChest9000GuideBook.setTagInfo("pages", pages); + dirtChest9000GuideBook.addTagElement("pages", pages); bookDataCreated = true; } diff --git a/src/main/java/com/progwml6/ironchest/common/block/tileentity/GenericIronChestTileEntity.java b/src/main/java/com/progwml6/ironchest/common/block/tileentity/GenericIronChestTileEntity.java index 5bb0492..222433b 100644 --- a/src/main/java/com/progwml6/ironchest/common/block/tileentity/GenericIronChestTileEntity.java +++ b/src/main/java/com/progwml6/ironchest/common/block/tileentity/GenericIronChestTileEntity.java @@ -4,39 +4,39 @@ import com.progwml6.ironchest.IronChests; import com.progwml6.ironchest.common.block.GenericIronChestBlock; import com.progwml6.ironchest.common.block.IronChestsTypes; import com.progwml6.ironchest.common.inventory.IronChestContainer; -import net.minecraft.block.Block; -import net.minecraft.block.BlockState; -import net.minecraft.entity.LivingEntity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.inventory.ItemStackHelper; -import net.minecraft.inventory.container.Container; -import net.minecraft.item.ItemStack; -import net.minecraft.nbt.CompoundNBT; -import net.minecraft.tileentity.IChestLid; -import net.minecraft.tileentity.ITickableTileEntity; -import net.minecraft.tileentity.LockableLootTileEntity; -import net.minecraft.tileentity.LockableTileEntity; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.tileentity.TileEntityType; -import net.minecraft.util.NonNullList; -import net.minecraft.util.SoundCategory; -import net.minecraft.util.SoundEvent; -import net.minecraft.util.SoundEvents; -import net.minecraft.util.math.AxisAlignedBB; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.math.MathHelper; -import net.minecraft.util.text.ITextComponent; -import net.minecraft.util.text.TranslationTextComponent; -import net.minecraft.world.IBlockReader; -import net.minecraft.world.World; +import net.minecraft.world.level.block.Block; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.entity.LivingEntity; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.ContainerHelper; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.item.ItemStack; +import net.minecraft.nbt.CompoundTag; +import net.minecraft.world.level.block.entity.LidBlockEntity; +import net.minecraft.world.level.block.entity.TickableBlockEntity; +import net.minecraft.world.level.block.entity.RandomizableContainerBlockEntity; +import net.minecraft.world.level.block.entity.BaseContainerBlockEntity; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.level.block.entity.BlockEntityType; +import net.minecraft.core.NonNullList; +import net.minecraft.sounds.SoundSource; +import net.minecraft.sounds.SoundEvent; +import net.minecraft.sounds.SoundEvents; +import net.minecraft.world.phys.AABB; +import net.minecraft.core.BlockPos; +import net.minecraft.util.Mth; +import net.minecraft.network.chat.Component; +import net.minecraft.network.chat.TranslatableComponent; +import net.minecraft.world.level.BlockGetter; +import net.minecraft.world.level.Level; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; import java.util.function.Supplier; -@OnlyIn(value = Dist.CLIENT, _interface = IChestLid.class) -public class GenericIronChestTileEntity extends LockableLootTileEntity implements IChestLid, ITickableTileEntity { +@OnlyIn(value = Dist.CLIENT, _interface = LidBlockEntity.class) +public class GenericIronChestTileEntity extends RandomizableContainerBlockEntity implements LidBlockEntity, TickableBlockEntity { private NonNullList chestContents; protected float lidAngle; @@ -46,7 +46,7 @@ public class GenericIronChestTileEntity extends LockableLootTileEntity implement private IronChestsTypes chestType; private Supplier blockToUse; - protected GenericIronChestTileEntity(TileEntityType typeIn, IronChestsTypes chestTypeIn, Supplier blockToUseIn) { + protected GenericIronChestTileEntity(BlockEntityType typeIn, IronChestsTypes chestTypeIn, Supplier blockToUseIn) { super(typeIn); this.chestContents = NonNullList.withSize(chestTypeIn.size, ItemStack.EMPTY); @@ -55,7 +55,7 @@ public class GenericIronChestTileEntity extends LockableLootTileEntity implement } @Override - public int getSizeInventory() { + public int getContainerSize() { return this.getItems().size(); } @@ -71,27 +71,27 @@ public class GenericIronChestTileEntity extends LockableLootTileEntity implement } @Override - protected ITextComponent getDefaultName() { - return new TranslationTextComponent(IronChests.MODID + ".container." + this.chestType.getId() + "_chest"); + protected Component getDefaultName() { + return new TranslatableComponent(IronChests.MODID + ".container." + this.chestType.getId() + "_chest"); } @Override - public void read(BlockState state, CompoundNBT compound) { - super.read(state, compound); + public void load(BlockState state, CompoundTag compound) { + super.load(state, compound); - this.chestContents = NonNullList.withSize(this.getSizeInventory(), ItemStack.EMPTY); + this.chestContents = NonNullList.withSize(this.getContainerSize(), ItemStack.EMPTY); - if (!this.checkLootAndRead(compound)) { - ItemStackHelper.loadAllItems(compound, this.chestContents); + if (!this.tryLoadLootTable(compound)) { + ContainerHelper.loadAllItems(compound, this.chestContents); } } @Override - public CompoundNBT write(CompoundNBT compound) { - super.write(compound); + public CompoundTag save(CompoundTag compound) { + super.save(compound); - if (!this.checkLootAndWrite(compound)) { - ItemStackHelper.saveAllItems(compound, this.chestContents); + if (!this.trySaveLootTable(compound)) { + ContainerHelper.saveAllItems(compound, this.chestContents); } return compound; @@ -99,15 +99,15 @@ public class GenericIronChestTileEntity extends LockableLootTileEntity implement @Override public void tick() { - int i = this.pos.getX(); - int j = this.pos.getY(); - int k = this.pos.getZ(); + int i = this.worldPosition.getX(); + int j = this.worldPosition.getY(); + int k = this.worldPosition.getZ(); ++this.ticksSinceSync; - this.numPlayersUsing = getNumberOfPlayersUsing(this.world, this, this.ticksSinceSync, i, j, k, this.numPlayersUsing); + this.numPlayersUsing = getNumberOfPlayersUsing(this.level, this, this.ticksSinceSync, i, j, k, this.numPlayersUsing); this.prevLidAngle = this.lidAngle; float f = 0.1F; if (this.numPlayersUsing > 0 && this.lidAngle == 0.0F) { - this.playSound(SoundEvents.BLOCK_CHEST_OPEN); + this.playSound(SoundEvents.CHEST_OPEN); } if (this.numPlayersUsing == 0 && this.lidAngle > 0.0F || this.numPlayersUsing > 0 && this.lidAngle < 1.0F) { @@ -125,7 +125,7 @@ public class GenericIronChestTileEntity extends LockableLootTileEntity implement float f2 = 0.5F; if (this.lidAngle < 0.5F && f1 >= 0.5F) { - this.playSound(SoundEvents.BLOCK_CHEST_CLOSE); + this.playSound(SoundEvents.CHEST_CLOSE); } if (this.lidAngle < 0.0F) { @@ -134,19 +134,19 @@ public class GenericIronChestTileEntity extends LockableLootTileEntity implement } } - public static int getNumberOfPlayersUsing(World worldIn, LockableTileEntity lockableTileEntity, int ticksSinceSync, int x, int y, int z, int numPlayersUsing) { - if (!worldIn.isRemote && numPlayersUsing != 0 && (ticksSinceSync + x + y + z) % 200 == 0) { + public static int getNumberOfPlayersUsing(Level worldIn, BaseContainerBlockEntity lockableTileEntity, int ticksSinceSync, int x, int y, int z, int numPlayersUsing) { + if (!worldIn.isClientSide && numPlayersUsing != 0 && (ticksSinceSync + x + y + z) % 200 == 0) { numPlayersUsing = getNumberOfPlayersUsing(worldIn, lockableTileEntity, x, y, z); } return numPlayersUsing; } - public static int getNumberOfPlayersUsing(World world, LockableTileEntity lockableTileEntity, int x, int y, int z) { + public static int getNumberOfPlayersUsing(Level world, BaseContainerBlockEntity lockableTileEntity, int x, int y, int z) { int i = 0; - for (PlayerEntity playerentity : world.getEntitiesWithinAABB(PlayerEntity.class, new AxisAlignedBB((double) ((float) x - 5.0F), (double) ((float) y - 5.0F), (double) ((float) z - 5.0F), (double) ((float) (x + 1) + 5.0F), (double) ((float) (y + 1) + 5.0F), (double) ((float) (z + 1) + 5.0F)))) { - if (playerentity.openContainer instanceof IronChestContainer) { + for (Player playerentity : world.getEntitiesOfClass(Player.class, new AABB((double) ((float) x - 5.0F), (double) ((float) y - 5.0F), (double) ((float) z - 5.0F), (double) ((float) (x + 1) + 5.0F), (double) ((float) (y + 1) + 5.0F), (double) ((float) (z + 1) + 5.0F)))) { + if (playerentity.containerMenu instanceof IronChestContainer) { ++i; } } @@ -155,26 +155,26 @@ public class GenericIronChestTileEntity extends LockableLootTileEntity implement } private void playSound(SoundEvent soundIn) { - double d0 = (double) this.pos.getX() + 0.5D; - double d1 = (double) this.pos.getY() + 0.5D; - double d2 = (double) this.pos.getZ() + 0.5D; + double d0 = (double) this.worldPosition.getX() + 0.5D; + double d1 = (double) this.worldPosition.getY() + 0.5D; + double d2 = (double) this.worldPosition.getZ() + 0.5D; - this.world.playSound((PlayerEntity) null, d0, d1, d2, soundIn, SoundCategory.BLOCKS, 0.5F, this.world.rand.nextFloat() * 0.1F + 0.9F); + this.level.playSound((Player) null, d0, d1, d2, soundIn, SoundSource.BLOCKS, 0.5F, this.level.random.nextFloat() * 0.1F + 0.9F); } @Override - public boolean receiveClientEvent(int id, int type) { + public boolean triggerEvent(int id, int type) { if (id == 1) { this.numPlayersUsing = type; return true; } else { - return super.receiveClientEvent(id, type); + return super.triggerEvent(id, type); } } @Override - public void openInventory(PlayerEntity player) { + public void startOpen(Player player) { if (!player.isSpectator()) { if (this.numPlayersUsing < 0) { this.numPlayersUsing = 0; @@ -186,7 +186,7 @@ public class GenericIronChestTileEntity extends LockableLootTileEntity implement } @Override - public void closeInventory(PlayerEntity player) { + public void stopOpen(Player player) { if (!player.isSpectator()) { --this.numPlayersUsing; this.onOpenOrClose(); @@ -197,8 +197,8 @@ public class GenericIronChestTileEntity extends LockableLootTileEntity implement Block block = this.getBlockState().getBlock(); if (block instanceof GenericIronChestBlock) { - this.world.addBlockEvent(this.pos, block, 1, this.numPlayersUsing); - this.world.notifyNeighborsOfStateChange(this.pos, block); + this.level.blockEvent(this.worldPosition, block, 1, this.numPlayersUsing); + this.level.updateNeighborsAt(this.worldPosition, block); } } @@ -220,14 +220,14 @@ public class GenericIronChestTileEntity extends LockableLootTileEntity implement @Override @OnlyIn(Dist.CLIENT) - public float getLidAngle(float partialTicks) { - return MathHelper.lerp(partialTicks, this.prevLidAngle, this.lidAngle); + public float getOpenNess(float partialTicks) { + return Mth.lerp(partialTicks, this.prevLidAngle, this.lidAngle); } - public static int getPlayersUsing(IBlockReader reader, BlockPos posIn) { + public static int getPlayersUsing(BlockGetter reader, BlockPos posIn) { BlockState blockstate = reader.getBlockState(posIn); if (blockstate.hasTileEntity()) { - TileEntity tileentity = reader.getTileEntity(posIn); + BlockEntity tileentity = reader.getBlockEntity(posIn); if (tileentity instanceof GenericIronChestTileEntity) { return ((GenericIronChestTileEntity) tileentity).numPlayersUsing; } @@ -237,7 +237,7 @@ public class GenericIronChestTileEntity extends LockableLootTileEntity implement } @Override - protected Container createMenu(int windowId, PlayerInventory playerInventory) { + protected AbstractContainerMenu createMenu(int windowId, Inventory playerInventory) { return IronChestContainer.createIronContainer(windowId, playerInventory, this); } @@ -250,7 +250,7 @@ public class GenericIronChestTileEntity extends LockableLootTileEntity implement public IronChestsTypes getChestType() { IronChestsTypes type = IronChestsTypes.IRON; - if (this.hasWorld()) { + if (this.hasLevel()) { IronChestsTypes typeFromBlock = GenericIronChestBlock.getTypeFromBlock(this.getBlockState().getBlock()); if (typeFromBlock != null) { diff --git a/src/main/java/com/progwml6/ironchest/common/block/tileentity/GoldChestTileEntity.java b/src/main/java/com/progwml6/ironchest/common/block/tileentity/GoldChestTileEntity.java index 0664838..13f354d 100644 --- a/src/main/java/com/progwml6/ironchest/common/block/tileentity/GoldChestTileEntity.java +++ b/src/main/java/com/progwml6/ironchest/common/block/tileentity/GoldChestTileEntity.java @@ -3,8 +3,8 @@ package com.progwml6.ironchest.common.block.tileentity; import com.progwml6.ironchest.common.block.IronChestsBlocks; import com.progwml6.ironchest.common.block.IronChestsTypes; import com.progwml6.ironchest.common.inventory.IronChestContainer; -import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.inventory.container.Container; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.inventory.AbstractContainerMenu; public class GoldChestTileEntity extends GenericIronChestTileEntity { @@ -13,7 +13,7 @@ public class GoldChestTileEntity extends GenericIronChestTileEntity { } @Override - protected Container createMenu(int id, PlayerInventory playerInventory) { + protected AbstractContainerMenu createMenu(int id, Inventory playerInventory) { return IronChestContainer.createGoldContainer(id, playerInventory, this); } } diff --git a/src/main/java/com/progwml6/ironchest/common/block/tileentity/IronChestsTileEntityTypes.java b/src/main/java/com/progwml6/ironchest/common/block/tileentity/IronChestsTileEntityTypes.java index 7361816..19bfa8d 100644 --- a/src/main/java/com/progwml6/ironchest/common/block/tileentity/IronChestsTileEntityTypes.java +++ b/src/main/java/com/progwml6/ironchest/common/block/tileentity/IronChestsTileEntityTypes.java @@ -3,36 +3,36 @@ package com.progwml6.ironchest.common.block.tileentity; import com.google.common.collect.Sets; import com.progwml6.ironchest.IronChests; import com.progwml6.ironchest.common.block.IronChestsBlocks; -import net.minecraft.tileentity.TileEntityType; +import net.minecraft.world.level.block.entity.BlockEntityType; import net.minecraftforge.fml.RegistryObject; import net.minecraftforge.registries.DeferredRegister; import net.minecraftforge.registries.ForgeRegistries; public class IronChestsTileEntityTypes { - public static final DeferredRegister> TILE_ENTITIES = DeferredRegister.create(ForgeRegistries.TILE_ENTITIES, IronChests.MODID); + public static final DeferredRegister> TILE_ENTITIES = DeferredRegister.create(ForgeRegistries.TILE_ENTITIES, IronChests.MODID); - public static final RegistryObject> IRON_CHEST = TILE_ENTITIES.register( - "iron_chest", () -> new TileEntityType<>(IronChestTileEntity::new, Sets.newHashSet(IronChestsBlocks.IRON_CHEST.get()), null)); + public static final RegistryObject> IRON_CHEST = TILE_ENTITIES.register( + "iron_chest", () -> new BlockEntityType<>(IronChestTileEntity::new, Sets.newHashSet(IronChestsBlocks.IRON_CHEST.get()), null)); - public static final RegistryObject> GOLD_CHEST = TILE_ENTITIES.register( - "gold_chest", () -> new TileEntityType<>(GoldChestTileEntity::new, Sets.newHashSet(IronChestsBlocks.GOLD_CHEST.get()), null)); + public static final RegistryObject> GOLD_CHEST = TILE_ENTITIES.register( + "gold_chest", () -> new BlockEntityType<>(GoldChestTileEntity::new, Sets.newHashSet(IronChestsBlocks.GOLD_CHEST.get()), null)); - public static final RegistryObject> DIAMOND_CHEST = TILE_ENTITIES.register( - "diamond_chest", () -> new TileEntityType<>(DiamondChestTileEntity::new, Sets.newHashSet(IronChestsBlocks.DIAMOND_CHEST.get()), null)); + public static final RegistryObject> DIAMOND_CHEST = TILE_ENTITIES.register( + "diamond_chest", () -> new BlockEntityType<>(DiamondChestTileEntity::new, Sets.newHashSet(IronChestsBlocks.DIAMOND_CHEST.get()), null)); - public static final RegistryObject> COPPER_CHEST = TILE_ENTITIES.register( - "copper_chest", () -> new TileEntityType<>(CopperChestTileEntity::new, Sets.newHashSet(IronChestsBlocks.COPPER_CHEST.get()), null)); + public static final RegistryObject> COPPER_CHEST = TILE_ENTITIES.register( + "copper_chest", () -> new BlockEntityType<>(CopperChestTileEntity::new, Sets.newHashSet(IronChestsBlocks.COPPER_CHEST.get()), null)); - public static final RegistryObject> SILVER_CHEST = TILE_ENTITIES.register( - "silver_chest", () -> new TileEntityType<>(SilverChestTileEntity::new, Sets.newHashSet(IronChestsBlocks.SILVER_CHEST.get()), null)); + public static final RegistryObject> SILVER_CHEST = TILE_ENTITIES.register( + "silver_chest", () -> new BlockEntityType<>(SilverChestTileEntity::new, Sets.newHashSet(IronChestsBlocks.SILVER_CHEST.get()), null)); - public static final RegistryObject> CRYSTAL_CHEST = TILE_ENTITIES.register( - "crystal_chest", () -> new TileEntityType<>(CrystalChestTileEntity::new, Sets.newHashSet(IronChestsBlocks.CRYSTAL_CHEST.get()), null)); + public static final RegistryObject> CRYSTAL_CHEST = TILE_ENTITIES.register( + "crystal_chest", () -> new BlockEntityType<>(CrystalChestTileEntity::new, Sets.newHashSet(IronChestsBlocks.CRYSTAL_CHEST.get()), null)); - public static final RegistryObject> OBSIDIAN_CHEST = TILE_ENTITIES.register( - "obsidian_chest", () -> new TileEntityType<>(ObsidianChestTileEntity::new, Sets.newHashSet(IronChestsBlocks.OBSIDIAN_CHEST.get()), null)); + public static final RegistryObject> OBSIDIAN_CHEST = TILE_ENTITIES.register( + "obsidian_chest", () -> new BlockEntityType<>(ObsidianChestTileEntity::new, Sets.newHashSet(IronChestsBlocks.OBSIDIAN_CHEST.get()), null)); - public static final RegistryObject> DIRT_CHEST = TILE_ENTITIES.register( - "dirt_chest", () -> new TileEntityType<>(DirtChestTileEntity::new, Sets.newHashSet(IronChestsBlocks.DIRT_CHEST.get()), null)); + public static final RegistryObject> DIRT_CHEST = TILE_ENTITIES.register( + "dirt_chest", () -> new BlockEntityType<>(DirtChestTileEntity::new, Sets.newHashSet(IronChestsBlocks.DIRT_CHEST.get()), null)); } diff --git a/src/main/java/com/progwml6/ironchest/common/block/tileentity/ObsidianChestTileEntity.java b/src/main/java/com/progwml6/ironchest/common/block/tileentity/ObsidianChestTileEntity.java index 654bb0c..0e6f88b 100644 --- a/src/main/java/com/progwml6/ironchest/common/block/tileentity/ObsidianChestTileEntity.java +++ b/src/main/java/com/progwml6/ironchest/common/block/tileentity/ObsidianChestTileEntity.java @@ -3,8 +3,8 @@ package com.progwml6.ironchest.common.block.tileentity; import com.progwml6.ironchest.common.block.IronChestsBlocks; import com.progwml6.ironchest.common.block.IronChestsTypes; import com.progwml6.ironchest.common.inventory.IronChestContainer; -import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.inventory.container.Container; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.inventory.AbstractContainerMenu; public class ObsidianChestTileEntity extends GenericIronChestTileEntity { @@ -13,7 +13,7 @@ public class ObsidianChestTileEntity extends GenericIronChestTileEntity { } @Override - protected Container createMenu(int id, PlayerInventory playerInventory) { + protected AbstractContainerMenu createMenu(int id, Inventory playerInventory) { return IronChestContainer.createObsidianContainer(id, playerInventory, this); } } diff --git a/src/main/java/com/progwml6/ironchest/common/block/tileentity/SilverChestTileEntity.java b/src/main/java/com/progwml6/ironchest/common/block/tileentity/SilverChestTileEntity.java index 7019489..c112fab 100644 --- a/src/main/java/com/progwml6/ironchest/common/block/tileentity/SilverChestTileEntity.java +++ b/src/main/java/com/progwml6/ironchest/common/block/tileentity/SilverChestTileEntity.java @@ -3,8 +3,8 @@ package com.progwml6.ironchest.common.block.tileentity; import com.progwml6.ironchest.common.block.IronChestsBlocks; import com.progwml6.ironchest.common.block.IronChestsTypes; import com.progwml6.ironchest.common.inventory.IronChestContainer; -import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.inventory.container.Container; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.inventory.AbstractContainerMenu; public class SilverChestTileEntity extends GenericIronChestTileEntity { @@ -13,7 +13,7 @@ public class SilverChestTileEntity extends GenericIronChestTileEntity { } @Override - protected Container createMenu(int id, PlayerInventory playerInventory) { + protected AbstractContainerMenu createMenu(int id, Inventory playerInventory) { return IronChestContainer.createSilverContainer(id, playerInventory, this); } } \ No newline at end of file diff --git a/src/main/java/com/progwml6/ironchest/common/data/IronChestsRecipeProvider.java b/src/main/java/com/progwml6/ironchest/common/data/IronChestsRecipeProvider.java index 95b6965..57ebd75 100644 --- a/src/main/java/com/progwml6/ironchest/common/data/IronChestsRecipeProvider.java +++ b/src/main/java/com/progwml6/ironchest/common/data/IronChestsRecipeProvider.java @@ -6,18 +6,18 @@ import com.progwml6.ironchest.common.item.IronChestsItems; import com.progwml6.ironchest.common.item.IronChestsUpgradeType; import net.minecraft.advancements.Advancement; import net.minecraft.advancements.AdvancementRewards; -import net.minecraft.advancements.IRequirementsStrategy; -import net.minecraft.advancements.criterion.RecipeUnlockedTrigger; -import net.minecraft.block.Blocks; +import net.minecraft.advancements.RequirementsStrategy; +import net.minecraft.advancements.critereon.RecipeUnlockedTrigger; +import net.minecraft.world.level.block.Blocks; import net.minecraft.data.DataGenerator; -import net.minecraft.data.IFinishedRecipe; -import net.minecraft.data.RecipeProvider; -import net.minecraft.data.ShapedRecipeBuilder; -import net.minecraft.item.Item; -import net.minecraft.item.crafting.Ingredient; +import net.minecraft.data.recipes.FinishedRecipe; +import net.minecraft.data.recipes.RecipeProvider; +import net.minecraft.data.recipes.ShapedRecipeBuilder; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.crafting.Ingredient; import net.minecraft.tags.ItemTags; -import net.minecraft.util.IItemProvider; -import net.minecraft.util.ResourceLocation; +import net.minecraft.world.level.ItemLike; +import net.minecraft.resources.ResourceLocation; import net.minecraftforge.common.Tags; import net.minecraftforge.common.crafting.ConditionalAdvancement; import net.minecraftforge.common.crafting.ConditionalRecipe; @@ -37,327 +37,327 @@ public class IronChestsRecipeProvider extends RecipeProvider implements IConditi } @Override - protected void registerRecipes(Consumer consumer) { + protected void buildShapelessRecipes(Consumer consumer) { this.addChestsRecipes(consumer); this.addUpgradesRecipes(consumer); } - private void addChestsRecipes(Consumer consumer) { + private void addChestsRecipes(Consumer consumer) { String folder = "chests/"; - ShapedRecipeBuilder.shapedRecipe(IronChestsBlocks.IRON_CHEST.get()) - .key('M', Tags.Items.INGOTS_IRON) - .key('S', Tags.Items.CHESTS_WOODEN) - .patternLine("MMM") - .patternLine("MSM") - .patternLine("MMM") - .addCriterion("has_iron_ingot", hasItem(Tags.Items.INGOTS_IRON)) - .build(consumer, location(folder + "vanilla_iron_chest")); + ShapedRecipeBuilder.shaped(IronChestsBlocks.IRON_CHEST.get()) + .define('M', Tags.Items.INGOTS_IRON) + .define('S', Tags.Items.CHESTS_WOODEN) + .pattern("MMM") + .pattern("MSM") + .pattern("MMM") + .unlockedBy("has_iron_ingot", has(Tags.Items.INGOTS_IRON)) + .save(consumer, location(folder + "vanilla_iron_chest")); - ShapedRecipeBuilder.shapedRecipe(IronChestsBlocks.GOLD_CHEST.get()) - .key('M', Tags.Items.INGOTS_GOLD) - .key('S', IronChestsBlocks.IRON_CHEST.get()) - .patternLine("MMM") - .patternLine("MSM") - .patternLine("MMM") - .addCriterion("has_gold_ingot", hasItem(Tags.Items.INGOTS_GOLD)) - .build(consumer, location(folder + "iron_gold_chest")); + ShapedRecipeBuilder.shaped(IronChestsBlocks.GOLD_CHEST.get()) + .define('M', Tags.Items.INGOTS_GOLD) + .define('S', IronChestsBlocks.IRON_CHEST.get()) + .pattern("MMM") + .pattern("MSM") + .pattern("MMM") + .unlockedBy("has_gold_ingot", has(Tags.Items.INGOTS_GOLD)) + .save(consumer, location(folder + "iron_gold_chest")); - ShapedRecipeBuilder.shapedRecipe(IronChestsBlocks.DIAMOND_CHEST.get()) - .key('M', Tags.Items.GEMS_DIAMOND) - .key('S', IronChestsBlocks.GOLD_CHEST.get()) - .key('G', Tags.Items.GLASS) - .patternLine("GGG") - .patternLine("MSM") - .patternLine("GGG") - .addCriterion("has_diamonds", hasItem(Tags.Items.GEMS_DIAMOND)) - .build(consumer, location(folder + "gold_diamond_chest")); + ShapedRecipeBuilder.shaped(IronChestsBlocks.DIAMOND_CHEST.get()) + .define('M', Tags.Items.GEMS_DIAMOND) + .define('S', IronChestsBlocks.GOLD_CHEST.get()) + .define('G', Tags.Items.GLASS) + .pattern("GGG") + .pattern("MSM") + .pattern("GGG") + .unlockedBy("has_diamonds", has(Tags.Items.GEMS_DIAMOND)) + .save(consumer, location(folder + "gold_diamond_chest")); - ShapedRecipeBuilder.shapedRecipe(IronChestsBlocks.OBSIDIAN_CHEST.get()) - .key('M', Blocks.OBSIDIAN) - .key('S', IronChestsBlocks.DIAMOND_CHEST.get()) - .patternLine("MMM") - .patternLine("MSM") - .patternLine("MMM") - .addCriterion("has_obsidian", hasItem(Blocks.OBSIDIAN)) - .build(consumer, location(folder + "diamond_obsidian_chest")); + ShapedRecipeBuilder.shaped(IronChestsBlocks.OBSIDIAN_CHEST.get()) + .define('M', Blocks.OBSIDIAN) + .define('S', IronChestsBlocks.DIAMOND_CHEST.get()) + .pattern("MMM") + .pattern("MSM") + .pattern("MMM") + .unlockedBy("has_obsidian", has(Blocks.OBSIDIAN)) + .save(consumer, location(folder + "diamond_obsidian_chest")); - ShapedRecipeBuilder.shapedRecipe(IronChestsBlocks.CRYSTAL_CHEST.get()) - .key('G', Tags.Items.GLASS) - .key('S', IronChestsBlocks.DIAMOND_CHEST.get()) - .patternLine("GGG") - .patternLine("GSG") - .patternLine("GGG") - .addCriterion("has_glass", hasItem(Tags.Items.GLASS)) - .build(consumer, location(folder + "diamond_crystal_chest")); + ShapedRecipeBuilder.shaped(IronChestsBlocks.CRYSTAL_CHEST.get()) + .define('G', Tags.Items.GLASS) + .define('S', IronChestsBlocks.DIAMOND_CHEST.get()) + .pattern("GGG") + .pattern("GSG") + .pattern("GGG") + .unlockedBy("has_glass", has(Tags.Items.GLASS)) + .save(consumer, location(folder + "diamond_crystal_chest")); - ShapedRecipeBuilder.shapedRecipe(IronChestsBlocks.DIRT_CHEST.get()) - .key('M', Ingredient.fromItems(Blocks.DIRT, Blocks.COARSE_DIRT, Blocks.PODZOL)) - .key('S', Tags.Items.CHESTS_WOODEN) - .patternLine("MMM") - .patternLine("MSM") - .patternLine("MMM") - .addCriterion("has_iron_ingot", hasItem(Blocks.DIRT)) - .build(consumer, location(folder + "vanilla_dirt_chest")); + ShapedRecipeBuilder.shaped(IronChestsBlocks.DIRT_CHEST.get()) + .define('M', Ingredient.of(Blocks.DIRT, Blocks.COARSE_DIRT, Blocks.PODZOL)) + .define('S', Tags.Items.CHESTS_WOODEN) + .pattern("MMM") + .pattern("MSM") + .pattern("MMM") + .unlockedBy("has_iron_ingot", has(Blocks.DIRT)) + .save(consumer, location(folder + "vanilla_dirt_chest")); ResourceLocation copperToIronChest = location(folder + "copper_iron_chest"); ConditionalRecipe.builder() .addCondition(not(new TagEmptyCondition("forge:ingots/copper"))) - .addRecipe(ShapedRecipeBuilder.shapedRecipe(IronChestsBlocks.IRON_CHEST.get()) - .key('M', Tags.Items.INGOTS_IRON) - .key('S', IronChestsBlocks.COPPER_CHEST.get()) - .key('G', Tags.Items.GLASS) - .patternLine("MGM") - .patternLine("GSG") - .patternLine("MGM") - .addCriterion("has_item", hasItem(Tags.Items.INGOTS_IRON))::build) + .addRecipe(ShapedRecipeBuilder.shaped(IronChestsBlocks.IRON_CHEST.get()) + .define('M', Tags.Items.INGOTS_IRON) + .define('S', IronChestsBlocks.COPPER_CHEST.get()) + .define('G', Tags.Items.GLASS) + .pattern("MGM") + .pattern("GSG") + .pattern("MGM") + .unlockedBy("has_item", has(Tags.Items.INGOTS_IRON))::save) .setAdvancement(location("recipes/ironchest/chests/copper_iron_chest"), ConditionalAdvancement.builder() .addCondition(not(new TagEmptyCondition("forge:ingots/copper"))) - .addAdvancement(Advancement.Builder.builder() - .withParentId(new ResourceLocation("recipes/root")) - .withRewards(AdvancementRewards.Builder.recipe(copperToIronChest)) - .withCriterion("has_item", hasItem(Tags.Items.INGOTS_IRON)) - .withCriterion("has_the_recipe", RecipeUnlockedTrigger.create(copperToIronChest)) - .withRequirementsStrategy(IRequirementsStrategy.OR)) + .addAdvancement(Advancement.Builder.advancement() + .parent(new ResourceLocation("recipes/root")) + .rewards(AdvancementRewards.Builder.recipe(copperToIronChest)) + .addCriterion("has_item", has(Tags.Items.INGOTS_IRON)) + .addCriterion("has_the_recipe", RecipeUnlockedTrigger.unlocked(copperToIronChest)) + .requirements(RequirementsStrategy.OR)) ).build(consumer, copperToIronChest); ResourceLocation copperToSilverChest = location(folder + "copper_silver_chest"); ConditionalRecipe.builder() .addCondition(not(new TagEmptyCondition("forge:ingots/silver"))) - .addRecipe(ShapedRecipeBuilder.shapedRecipe(IronChestsBlocks.SILVER_CHEST.get()) - .key('M', INGOTS_SILVER) - .key('S', IronChestsBlocks.COPPER_CHEST.get()) - .patternLine("MMM") - .patternLine("MSM") - .patternLine("MMM") - .addCriterion("has_item", hasItem(INGOTS_SILVER))::build) + .addRecipe(ShapedRecipeBuilder.shaped(IronChestsBlocks.SILVER_CHEST.get()) + .define('M', INGOTS_SILVER) + .define('S', IronChestsBlocks.COPPER_CHEST.get()) + .pattern("MMM") + .pattern("MSM") + .pattern("MMM") + .unlockedBy("has_item", has(INGOTS_SILVER))::save) .setAdvancement(location("recipes/ironchest/chests/copper_silver_chest"), ConditionalAdvancement.builder() .addCondition(not(new TagEmptyCondition("forge:ingots/silver"))) - .addAdvancement(Advancement.Builder.builder() - .withParentId(new ResourceLocation("recipes/root")) - .withRewards(AdvancementRewards.Builder.recipe(copperToSilverChest)) - .withCriterion("has_item", hasItem(INGOTS_SILVER)) - .withCriterion("has_the_recipe", RecipeUnlockedTrigger.create(copperToSilverChest)) - .withRequirementsStrategy(IRequirementsStrategy.OR)) + .addAdvancement(Advancement.Builder.advancement() + .parent(new ResourceLocation("recipes/root")) + .rewards(AdvancementRewards.Builder.recipe(copperToSilverChest)) + .addCriterion("has_item", has(INGOTS_SILVER)) + .addCriterion("has_the_recipe", RecipeUnlockedTrigger.unlocked(copperToSilverChest)) + .requirements(RequirementsStrategy.OR)) ).build(consumer, copperToSilverChest); ResourceLocation ironToSilverChest = location(folder + "iron_silver_chest"); ConditionalRecipe.builder() .addCondition(not(new TagEmptyCondition("forge:ingots/silver"))) - .addRecipe(ShapedRecipeBuilder.shapedRecipe(IronChestsBlocks.SILVER_CHEST.get()) - .key('M', INGOTS_SILVER) - .key('S', IronChestsBlocks.IRON_CHEST.get()) - .key('G', Tags.Items.GLASS) - .patternLine("MGM") - .patternLine("MSM") - .patternLine("MGM") - .addCriterion("has_item", hasItem(INGOTS_SILVER))::build) + .addRecipe(ShapedRecipeBuilder.shaped(IronChestsBlocks.SILVER_CHEST.get()) + .define('M', INGOTS_SILVER) + .define('S', IronChestsBlocks.IRON_CHEST.get()) + .define('G', Tags.Items.GLASS) + .pattern("MGM") + .pattern("MSM") + .pattern("MGM") + .unlockedBy("has_item", has(INGOTS_SILVER))::save) .setAdvancement(location("recipes/ironchest/chests/iron_silver_chest"), ConditionalAdvancement.builder() .addCondition(not(new TagEmptyCondition("forge:ingots/silver"))) - .addAdvancement(Advancement.Builder.builder() - .withParentId(new ResourceLocation("recipes/root")) - .withRewards(AdvancementRewards.Builder.recipe(ironToSilverChest)) - .withCriterion("has_item", hasItem(INGOTS_SILVER)) - .withCriterion("has_the_recipe", RecipeUnlockedTrigger.create(ironToSilverChest)) - .withRequirementsStrategy(IRequirementsStrategy.OR)) + .addAdvancement(Advancement.Builder.advancement() + .parent(new ResourceLocation("recipes/root")) + .rewards(AdvancementRewards.Builder.recipe(ironToSilverChest)) + .addCriterion("has_item", has(INGOTS_SILVER)) + .addCriterion("has_the_recipe", RecipeUnlockedTrigger.unlocked(ironToSilverChest)) + .requirements(RequirementsStrategy.OR)) ).build(consumer, ironToSilverChest); ResourceLocation vanillaToCopperChest = location(folder + "vanilla_copper_chest"); ConditionalRecipe.builder() .addCondition(not(new TagEmptyCondition("forge:ingots/copper"))) - .addRecipe(ShapedRecipeBuilder.shapedRecipe(IronChestsBlocks.COPPER_CHEST.get()) - .key('M', INGOTS_COPPER) - .key('S', Tags.Items.CHESTS_WOODEN) - .patternLine("MMM") - .patternLine("MSM") - .patternLine("MMM") - .addCriterion("has_item", hasItem(INGOTS_COPPER))::build) + .addRecipe(ShapedRecipeBuilder.shaped(IronChestsBlocks.COPPER_CHEST.get()) + .define('M', INGOTS_COPPER) + .define('S', Tags.Items.CHESTS_WOODEN) + .pattern("MMM") + .pattern("MSM") + .pattern("MMM") + .unlockedBy("has_item", has(INGOTS_COPPER))::save) .setAdvancement(location("recipes/ironchest/chests/vanilla_copper_chest"), ConditionalAdvancement.builder() .addCondition(not(new TagEmptyCondition("forge:ingots/silver"))) - .addAdvancement(Advancement.Builder.builder() - .withParentId(new ResourceLocation("recipes/root")) - .withRewards(AdvancementRewards.Builder.recipe(vanillaToCopperChest)) - .withCriterion("has_item", hasItem(INGOTS_COPPER)) - .withCriterion("has_the_recipe", RecipeUnlockedTrigger.create(vanillaToCopperChest)) - .withRequirementsStrategy(IRequirementsStrategy.OR)) + .addAdvancement(Advancement.Builder.advancement() + .parent(new ResourceLocation("recipes/root")) + .rewards(AdvancementRewards.Builder.recipe(vanillaToCopperChest)) + .addCriterion("has_item", has(INGOTS_COPPER)) + .addCriterion("has_the_recipe", RecipeUnlockedTrigger.unlocked(vanillaToCopperChest)) + .requirements(RequirementsStrategy.OR)) ).build(consumer, vanillaToCopperChest); ResourceLocation silverToGoldChest = location(folder + "silver_gold_chest"); ConditionalRecipe.builder() .addCondition(not(new TagEmptyCondition("forge:ingots/copper"))) - .addRecipe(ShapedRecipeBuilder.shapedRecipe(IronChestsBlocks.GOLD_CHEST.get()) - .key('M', Tags.Items.INGOTS_GOLD) - .key('S', IronChestsBlocks.SILVER_CHEST.get()) - .key('G', Tags.Items.GLASS) - .patternLine("MGM") - .patternLine("GSG") - .patternLine("MGM") - .addCriterion("has_item", hasItem(INGOTS_SILVER))::build) + .addRecipe(ShapedRecipeBuilder.shaped(IronChestsBlocks.GOLD_CHEST.get()) + .define('M', Tags.Items.INGOTS_GOLD) + .define('S', IronChestsBlocks.SILVER_CHEST.get()) + .define('G', Tags.Items.GLASS) + .pattern("MGM") + .pattern("GSG") + .pattern("MGM") + .unlockedBy("has_item", has(INGOTS_SILVER))::save) .setAdvancement(location("recipes/ironchest/chests/silver_gold_chest"), ConditionalAdvancement.builder() .addCondition(not(new TagEmptyCondition("forge:ingots/silver"))) - .addAdvancement(Advancement.Builder.builder() - .withParentId(new ResourceLocation("recipes/root")) - .withRewards(AdvancementRewards.Builder.recipe(silverToGoldChest)) - .withCriterion("has_item", hasItem(INGOTS_SILVER)) - .withCriterion("has_the_recipe", RecipeUnlockedTrigger.create(silverToGoldChest)) - .withRequirementsStrategy(IRequirementsStrategy.OR)) + .addAdvancement(Advancement.Builder.advancement() + .parent(new ResourceLocation("recipes/root")) + .rewards(AdvancementRewards.Builder.recipe(silverToGoldChest)) + .addCriterion("has_item", has(INGOTS_SILVER)) + .addCriterion("has_the_recipe", RecipeUnlockedTrigger.unlocked(silverToGoldChest)) + .requirements(RequirementsStrategy.OR)) ).build(consumer, silverToGoldChest); ResourceLocation silverToDiamondChest = location(folder + "silver_diamond_chest"); ConditionalRecipe.builder() .addCondition(not(new TagEmptyCondition("forge:ingots/copper"))) - .addRecipe(ShapedRecipeBuilder.shapedRecipe(IronChestsBlocks.DIAMOND_CHEST.get()) - .key('M', Tags.Items.GEMS_DIAMOND) - .key('S', IronChestsBlocks.SILVER_CHEST.get()) - .key('G', Tags.Items.GLASS) - .patternLine("GGG") - .patternLine("GSG") - .patternLine("MMM") - .addCriterion("has_item", hasItem(Tags.Items.GEMS_DIAMOND))::build) + .addRecipe(ShapedRecipeBuilder.shaped(IronChestsBlocks.DIAMOND_CHEST.get()) + .define('M', Tags.Items.GEMS_DIAMOND) + .define('S', IronChestsBlocks.SILVER_CHEST.get()) + .define('G', Tags.Items.GLASS) + .pattern("GGG") + .pattern("GSG") + .pattern("MMM") + .unlockedBy("has_item", has(Tags.Items.GEMS_DIAMOND))::save) .setAdvancement(location("recipes/ironchest/chests/silver_diamond_chest"), ConditionalAdvancement.builder() .addCondition(not(new TagEmptyCondition("forge:ingots/silver"))) - .addAdvancement(Advancement.Builder.builder() - .withParentId(new ResourceLocation("recipes/root")) - .withRewards(AdvancementRewards.Builder.recipe(silverToDiamondChest)) - .withCriterion("has_item", hasItem(Tags.Items.GEMS_DIAMOND)) - .withCriterion("has_the_recipe", RecipeUnlockedTrigger.create(silverToDiamondChest)) - .withRequirementsStrategy(IRequirementsStrategy.OR)) + .addAdvancement(Advancement.Builder.advancement() + .parent(new ResourceLocation("recipes/root")) + .rewards(AdvancementRewards.Builder.recipe(silverToDiamondChest)) + .addCriterion("has_item", has(Tags.Items.GEMS_DIAMOND)) + .addCriterion("has_the_recipe", RecipeUnlockedTrigger.unlocked(silverToDiamondChest)) + .requirements(RequirementsStrategy.OR)) ).build(consumer, silverToDiamondChest); } - private void addUpgradesRecipes(Consumer consumer) { + private void addUpgradesRecipes(Consumer consumer) { String folder = "upgrades/"; - ShapedRecipeBuilder.shapedRecipe(IronChestsItems.UPGRADES.get(IronChestsUpgradeType.WOOD_TO_IRON).get()) - .key('M', Tags.Items.INGOTS_IRON) - .key('P', ItemTags.PLANKS) - .patternLine("MMM") - .patternLine("MPM") - .patternLine("MMM") - .addCriterion("has_iron_ingot", hasItem(Tags.Items.INGOTS_IRON)) - .build(consumer, prefix(IronChestsItems.UPGRADES.get(IronChestsUpgradeType.WOOD_TO_IRON).get(), folder)); + ShapedRecipeBuilder.shaped(IronChestsItems.UPGRADES.get(IronChestsUpgradeType.WOOD_TO_IRON).get()) + .define('M', Tags.Items.INGOTS_IRON) + .define('P', ItemTags.PLANKS) + .pattern("MMM") + .pattern("MPM") + .pattern("MMM") + .unlockedBy("has_iron_ingot", has(Tags.Items.INGOTS_IRON)) + .save(consumer, prefix(IronChestsItems.UPGRADES.get(IronChestsUpgradeType.WOOD_TO_IRON).get(), folder)); - ShapedRecipeBuilder.shapedRecipe(IronChestsItems.UPGRADES.get(IronChestsUpgradeType.IRON_TO_GOLD).get()) - .key('I', Tags.Items.INGOTS_IRON) - .key('G', Tags.Items.INGOTS_GOLD) - .patternLine("GGG") - .patternLine("GIG") - .patternLine("GGG") - .addCriterion("has_iron_ingot", hasItem(Tags.Items.INGOTS_IRON)) - .build(consumer, prefix(IronChestsItems.UPGRADES.get(IronChestsUpgradeType.IRON_TO_GOLD).get(), folder)); + ShapedRecipeBuilder.shaped(IronChestsItems.UPGRADES.get(IronChestsUpgradeType.IRON_TO_GOLD).get()) + .define('I', Tags.Items.INGOTS_IRON) + .define('G', Tags.Items.INGOTS_GOLD) + .pattern("GGG") + .pattern("GIG") + .pattern("GGG") + .unlockedBy("has_iron_ingot", has(Tags.Items.INGOTS_IRON)) + .save(consumer, prefix(IronChestsItems.UPGRADES.get(IronChestsUpgradeType.IRON_TO_GOLD).get(), folder)); - ShapedRecipeBuilder.shapedRecipe(IronChestsItems.UPGRADES.get(IronChestsUpgradeType.GOLD_TO_DIAMOND).get()) - .key('M', Tags.Items.GEMS_DIAMOND) - .key('S', Tags.Items.INGOTS_GOLD) - .key('G', Tags.Items.GLASS) - .patternLine("GGG") - .patternLine("MSM") - .patternLine("GGG") - .addCriterion("has_glass", hasItem(Tags.Items.GLASS)) - .build(consumer, prefix(IronChestsItems.UPGRADES.get(IronChestsUpgradeType.GOLD_TO_DIAMOND).get(), folder)); + ShapedRecipeBuilder.shaped(IronChestsItems.UPGRADES.get(IronChestsUpgradeType.GOLD_TO_DIAMOND).get()) + .define('M', Tags.Items.GEMS_DIAMOND) + .define('S', Tags.Items.INGOTS_GOLD) + .define('G', Tags.Items.GLASS) + .pattern("GGG") + .pattern("MSM") + .pattern("GGG") + .unlockedBy("has_glass", has(Tags.Items.GLASS)) + .save(consumer, prefix(IronChestsItems.UPGRADES.get(IronChestsUpgradeType.GOLD_TO_DIAMOND).get(), folder)); - ShapedRecipeBuilder.shapedRecipe(IronChestsItems.UPGRADES.get(IronChestsUpgradeType.DIAMOND_TO_OBSIDIAN).get()) - .key('S', Blocks.OBSIDIAN) - .key('G', Tags.Items.GLASS) - .patternLine("GGG") - .patternLine("GSG") - .patternLine("GGG") - .addCriterion("has_glass", hasItem(Tags.Items.GLASS)) - .build(consumer, prefix(IronChestsItems.UPGRADES.get(IronChestsUpgradeType.DIAMOND_TO_OBSIDIAN).get(), folder)); + ShapedRecipeBuilder.shaped(IronChestsItems.UPGRADES.get(IronChestsUpgradeType.DIAMOND_TO_OBSIDIAN).get()) + .define('S', Blocks.OBSIDIAN) + .define('G', Tags.Items.GLASS) + .pattern("GGG") + .pattern("GSG") + .pattern("GGG") + .unlockedBy("has_glass", has(Tags.Items.GLASS)) + .save(consumer, prefix(IronChestsItems.UPGRADES.get(IronChestsUpgradeType.DIAMOND_TO_OBSIDIAN).get(), folder)); - ShapedRecipeBuilder.shapedRecipe(IronChestsItems.UPGRADES.get(IronChestsUpgradeType.DIAMOND_TO_CRYSTAL).get()) - .key('M', Blocks.OBSIDIAN) - .key('G', Tags.Items.GLASS) - .patternLine("MMM") - .patternLine("MGM") - .patternLine("MMM") - .addCriterion("has_glass", hasItem(Tags.Items.GLASS)) - .build(consumer, prefix(IronChestsItems.UPGRADES.get(IronChestsUpgradeType.DIAMOND_TO_CRYSTAL).get(), folder)); + ShapedRecipeBuilder.shaped(IronChestsItems.UPGRADES.get(IronChestsUpgradeType.DIAMOND_TO_CRYSTAL).get()) + .define('M', Blocks.OBSIDIAN) + .define('G', Tags.Items.GLASS) + .pattern("MMM") + .pattern("MGM") + .pattern("MMM") + .unlockedBy("has_glass", has(Tags.Items.GLASS)) + .save(consumer, prefix(IronChestsItems.UPGRADES.get(IronChestsUpgradeType.DIAMOND_TO_CRYSTAL).get(), folder)); ResourceLocation woodToCopperChestUpgradeId = prefix(IronChestsItems.UPGRADES.get(IronChestsUpgradeType.WOOD_TO_COPPER).get(), folder); ConditionalRecipe.builder() .addCondition(not(new TagEmptyCondition("forge:ingots/copper"))) - .addRecipe(ShapedRecipeBuilder.shapedRecipe(IronChestsItems.UPGRADES.get(IronChestsUpgradeType.WOOD_TO_COPPER).get()) - .key('M', INGOTS_COPPER) - .key('S', ItemTags.PLANKS) - .patternLine("MMM") - .patternLine("MSM") - .patternLine("MMM") - .addCriterion("has_item", hasItem(ItemTags.PLANKS))::build) + .addRecipe(ShapedRecipeBuilder.shaped(IronChestsItems.UPGRADES.get(IronChestsUpgradeType.WOOD_TO_COPPER).get()) + .define('M', INGOTS_COPPER) + .define('S', ItemTags.PLANKS) + .pattern("MMM") + .pattern("MSM") + .pattern("MMM") + .unlockedBy("has_item", has(ItemTags.PLANKS))::save) .setAdvancement(location("recipes/ironchest/upgrades/wood_to_copper_chest_upgrade"), ConditionalAdvancement.builder() .addCondition(not(new TagEmptyCondition("forge:ingots/copper"))) - .addAdvancement(Advancement.Builder.builder() - .withParentId(new ResourceLocation("recipes/root")) - .withRewards(AdvancementRewards.Builder.recipe(woodToCopperChestUpgradeId)) - .withCriterion("has_item", hasItem(ItemTags.PLANKS)) - .withCriterion("has_the_recipe", RecipeUnlockedTrigger.create(woodToCopperChestUpgradeId)) - .withRequirementsStrategy(IRequirementsStrategy.OR)) + .addAdvancement(Advancement.Builder.advancement() + .parent(new ResourceLocation("recipes/root")) + .rewards(AdvancementRewards.Builder.recipe(woodToCopperChestUpgradeId)) + .addCriterion("has_item", has(ItemTags.PLANKS)) + .addCriterion("has_the_recipe", RecipeUnlockedTrigger.unlocked(woodToCopperChestUpgradeId)) + .requirements(RequirementsStrategy.OR)) ).build(consumer, woodToCopperChestUpgradeId); ResourceLocation copperToIronChestUpgrade = prefix(IronChestsItems.UPGRADES.get(IronChestsUpgradeType.COPPER_TO_IRON).get(), folder); ConditionalRecipe.builder() .addCondition(not(new TagEmptyCondition("forge:ingots/copper"))) - .addRecipe(ShapedRecipeBuilder.shapedRecipe(IronChestsItems.UPGRADES.get(IronChestsUpgradeType.COPPER_TO_IRON).get()) - .key('M', Tags.Items.INGOTS_IRON) - .key('S', INGOTS_COPPER) - .key('G', Tags.Items.GLASS) - .patternLine("MGM") - .patternLine("GSG") - .patternLine("MGM") - .addCriterion("has_item", hasItem(ItemTags.PLANKS))::build) + .addRecipe(ShapedRecipeBuilder.shaped(IronChestsItems.UPGRADES.get(IronChestsUpgradeType.COPPER_TO_IRON).get()) + .define('M', Tags.Items.INGOTS_IRON) + .define('S', INGOTS_COPPER) + .define('G', Tags.Items.GLASS) + .pattern("MGM") + .pattern("GSG") + .pattern("MGM") + .unlockedBy("has_item", has(ItemTags.PLANKS))::save) .setAdvancement(location("recipes/ironchest/upgrades/copper_to_iron_chest_upgrade"), ConditionalAdvancement.builder() .addCondition(not(new TagEmptyCondition("forge:ingots/copper"))) - .addAdvancement(Advancement.Builder.builder() - .withParentId(new ResourceLocation("recipes/root")) - .withRewards(AdvancementRewards.Builder.recipe(copperToIronChestUpgrade)) - .withCriterion("has_item", hasItem(Tags.Items.GLASS)) - .withCriterion("has_the_recipe", RecipeUnlockedTrigger.create(copperToIronChestUpgrade)) - .withRequirementsStrategy(IRequirementsStrategy.OR)) + .addAdvancement(Advancement.Builder.advancement() + .parent(new ResourceLocation("recipes/root")) + .rewards(AdvancementRewards.Builder.recipe(copperToIronChestUpgrade)) + .addCriterion("has_item", has(Tags.Items.GLASS)) + .addCriterion("has_the_recipe", RecipeUnlockedTrigger.unlocked(copperToIronChestUpgrade)) + .requirements(RequirementsStrategy.OR)) ).build(consumer, copperToIronChestUpgrade); ResourceLocation copperToSilverChestUpgrade = prefix(IronChestsItems.UPGRADES.get(IronChestsUpgradeType.COPPER_TO_SILVER).get(), folder); ConditionalRecipe.builder() .addCondition(and(not(new TagEmptyCondition("forge:ingots/copper")), not(new TagEmptyCondition("forge:ingots/silver")))) - .addRecipe(ShapedRecipeBuilder.shapedRecipe(IronChestsItems.UPGRADES.get(IronChestsUpgradeType.COPPER_TO_SILVER).get()) - .key('M', INGOTS_SILVER) - .key('S', INGOTS_COPPER) - .patternLine("MMM") - .patternLine("MSM") - .patternLine("MMM") - .addCriterion("has_item", hasItem(INGOTS_COPPER))::build) + .addRecipe(ShapedRecipeBuilder.shaped(IronChestsItems.UPGRADES.get(IronChestsUpgradeType.COPPER_TO_SILVER).get()) + .define('M', INGOTS_SILVER) + .define('S', INGOTS_COPPER) + .pattern("MMM") + .pattern("MSM") + .pattern("MMM") + .unlockedBy("has_item", has(INGOTS_COPPER))::save) .setAdvancement(location("recipes/ironchest/upgrades/copper_to_silver_chest_upgrade"), ConditionalAdvancement.builder() .addCondition(and(not(new TagEmptyCondition("forge:ingots/copper")), not(new TagEmptyCondition("forge:ingots/silver")))) - .addAdvancement(Advancement.Builder.builder() - .withParentId(new ResourceLocation("recipes/root")) - .withRewards(AdvancementRewards.Builder.recipe(copperToSilverChestUpgrade)) - .withCriterion("has_item", hasItem(INGOTS_COPPER)) - .withCriterion("has_the_recipe", RecipeUnlockedTrigger.create(copperToSilverChestUpgrade)) - .withRequirementsStrategy(IRequirementsStrategy.OR)) + .addAdvancement(Advancement.Builder.advancement() + .parent(new ResourceLocation("recipes/root")) + .rewards(AdvancementRewards.Builder.recipe(copperToSilverChestUpgrade)) + .addCriterion("has_item", has(INGOTS_COPPER)) + .addCriterion("has_the_recipe", RecipeUnlockedTrigger.unlocked(copperToSilverChestUpgrade)) + .requirements(RequirementsStrategy.OR)) ).build(consumer, copperToSilverChestUpgrade); ResourceLocation silverToGoldChestUpgrade = prefix(IronChestsItems.UPGRADES.get(IronChestsUpgradeType.SILVER_TO_GOLD).get(), folder); ConditionalRecipe.builder() .addCondition(not(new TagEmptyCondition("forge:ingots/silver"))) - .addRecipe(ShapedRecipeBuilder.shapedRecipe(IronChestsItems.UPGRADES.get(IronChestsUpgradeType.SILVER_TO_GOLD).get()) - .key('M', Tags.Items.INGOTS_GOLD) - .key('S', INGOTS_SILVER) - .key('G', Tags.Items.GLASS) - .patternLine("MGM") - .patternLine("GSG") - .patternLine("MGM") - .addCriterion("has_item", hasItem(Tags.Items.GLASS))::build) + .addRecipe(ShapedRecipeBuilder.shaped(IronChestsItems.UPGRADES.get(IronChestsUpgradeType.SILVER_TO_GOLD).get()) + .define('M', Tags.Items.INGOTS_GOLD) + .define('S', INGOTS_SILVER) + .define('G', Tags.Items.GLASS) + .pattern("MGM") + .pattern("GSG") + .pattern("MGM") + .unlockedBy("has_item", has(Tags.Items.GLASS))::save) .setAdvancement(location("recipes/ironchest/upgrades/silver_to_gold_chest_upgrade"), ConditionalAdvancement.builder() .addCondition(not(new TagEmptyCondition("forge:ingots/silver"))) - .addAdvancement(Advancement.Builder.builder() - .withParentId(new ResourceLocation("recipes/root")) - .withRewards(AdvancementRewards.Builder.recipe(silverToGoldChestUpgrade)) - .withCriterion("has_item", hasItem(Tags.Items.GLASS)) - .withCriterion("has_the_recipe", RecipeUnlockedTrigger.create(silverToGoldChestUpgrade)) - .withRequirementsStrategy(IRequirementsStrategy.OR)) + .addAdvancement(Advancement.Builder.advancement() + .parent(new ResourceLocation("recipes/root")) + .rewards(AdvancementRewards.Builder.recipe(silverToGoldChestUpgrade)) + .addCriterion("has_item", has(Tags.Items.GLASS)) + .addCriterion("has_the_recipe", RecipeUnlockedTrigger.unlocked(silverToGoldChestUpgrade)) + .requirements(RequirementsStrategy.OR)) ).build(consumer, silverToGoldChestUpgrade); } - protected static ResourceLocation prefix(IItemProvider item, String prefix) { + protected static ResourceLocation prefix(ItemLike item, String prefix) { ResourceLocation loc = Objects.requireNonNull(item.asItem().getRegistryName()); return location(prefix + loc.getPath()); } diff --git a/src/main/java/com/progwml6/ironchest/common/inventory/DirtChestSlot.java b/src/main/java/com/progwml6/ironchest/common/inventory/DirtChestSlot.java index 44fa618..bc4294c 100644 --- a/src/main/java/com/progwml6/ironchest/common/inventory/DirtChestSlot.java +++ b/src/main/java/com/progwml6/ironchest/common/inventory/DirtChestSlot.java @@ -1,19 +1,19 @@ package com.progwml6.ironchest.common.inventory; -import net.minecraft.block.Blocks; -import net.minecraft.inventory.IInventory; -import net.minecraft.inventory.container.Slot; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; +import net.minecraft.world.level.block.Blocks; +import net.minecraft.world.Container; +import net.minecraft.world.inventory.Slot; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; public class DirtChestSlot extends Slot { - public DirtChestSlot(IInventory inventoryIn, int slotIndex, int xPosition, int yPosition) { + public DirtChestSlot(Container inventoryIn, int slotIndex, int xPosition, int yPosition) { super(inventoryIn, slotIndex, xPosition, yPosition); } @Override - public boolean isItemValid(ItemStack stack) { - return stack.isEmpty() || stack.getItem() == Item.getItemFromBlock(Blocks.DIRT); + public boolean mayPlace(ItemStack stack) { + return stack.isEmpty() || stack.getItem() == Item.byBlock(Blocks.DIRT); } } \ No newline at end of file diff --git a/src/main/java/com/progwml6/ironchest/common/inventory/IronChestContainer.java b/src/main/java/com/progwml6/ironchest/common/inventory/IronChestContainer.java index b577ed9..5e77f6d 100644 --- a/src/main/java/com/progwml6/ironchest/common/inventory/IronChestContainer.java +++ b/src/main/java/com/progwml6/ironchest/common/inventory/IronChestContainer.java @@ -1,99 +1,99 @@ package com.progwml6.ironchest.common.inventory; import com.progwml6.ironchest.common.block.IronChestsTypes; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.entity.player.PlayerInventory; -import net.minecraft.inventory.IInventory; -import net.minecraft.inventory.Inventory; -import net.minecraft.inventory.container.Container; -import net.minecraft.inventory.container.ContainerType; -import net.minecraft.inventory.container.Slot; -import net.minecraft.item.ItemStack; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.entity.player.Inventory; +import net.minecraft.world.Container; +import net.minecraft.world.SimpleContainer; +import net.minecraft.world.inventory.AbstractContainerMenu; +import net.minecraft.world.inventory.MenuType; +import net.minecraft.world.inventory.Slot; +import net.minecraft.world.item.ItemStack; import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.OnlyIn; -public class IronChestContainer extends Container { +public class IronChestContainer extends AbstractContainerMenu { - private final IInventory inventory; + private final Container inventory; private final IronChestsTypes chestType; - private IronChestContainer(ContainerType containerType, int windowId, PlayerInventory playerInventory) { - this(containerType, windowId, playerInventory, new Inventory(IronChestsTypes.WOOD.size), IronChestsTypes.WOOD); + private IronChestContainer(MenuType containerType, int windowId, Inventory playerInventory) { + this(containerType, windowId, playerInventory, new SimpleContainer(IronChestsTypes.WOOD.size), IronChestsTypes.WOOD); } - public static IronChestContainer createIronContainer(int windowId, PlayerInventory playerInventory) { - return new IronChestContainer(IronChestsContainerTypes.IRON_CHEST.get(), windowId, playerInventory, new Inventory(IronChestsTypes.IRON.size), IronChestsTypes.IRON); + public static IronChestContainer createIronContainer(int windowId, Inventory playerInventory) { + return new IronChestContainer(IronChestsContainerTypes.IRON_CHEST.get(), windowId, playerInventory, new SimpleContainer(IronChestsTypes.IRON.size), IronChestsTypes.IRON); } - public static IronChestContainer createIronContainer(int windowId, PlayerInventory playerInventory, IInventory inventory) { + public static IronChestContainer createIronContainer(int windowId, Inventory playerInventory, Container inventory) { return new IronChestContainer(IronChestsContainerTypes.IRON_CHEST.get(), windowId, playerInventory, inventory, IronChestsTypes.IRON); } - public static IronChestContainer createGoldContainer(int windowId, PlayerInventory playerInventory) { - return new IronChestContainer(IronChestsContainerTypes.GOLD_CHEST.get(), windowId, playerInventory, new Inventory(IronChestsTypes.GOLD.size), IronChestsTypes.GOLD); + public static IronChestContainer createGoldContainer(int windowId, Inventory playerInventory) { + return new IronChestContainer(IronChestsContainerTypes.GOLD_CHEST.get(), windowId, playerInventory, new SimpleContainer(IronChestsTypes.GOLD.size), IronChestsTypes.GOLD); } - public static IronChestContainer createGoldContainer(int windowId, PlayerInventory playerInventory, IInventory inventory) { + public static IronChestContainer createGoldContainer(int windowId, Inventory playerInventory, Container inventory) { return new IronChestContainer(IronChestsContainerTypes.GOLD_CHEST.get(), windowId, playerInventory, inventory, IronChestsTypes.GOLD); } - public static IronChestContainer createDiamondContainer(int windowId, PlayerInventory playerInventory) { - return new IronChestContainer(IronChestsContainerTypes.DIAMOND_CHEST.get(), windowId, playerInventory, new Inventory(IronChestsTypes.DIAMOND.size), IronChestsTypes.DIAMOND); + public static IronChestContainer createDiamondContainer(int windowId, Inventory playerInventory) { + return new IronChestContainer(IronChestsContainerTypes.DIAMOND_CHEST.get(), windowId, playerInventory, new SimpleContainer(IronChestsTypes.DIAMOND.size), IronChestsTypes.DIAMOND); } - public static IronChestContainer createDiamondContainer(int windowId, PlayerInventory playerInventory, IInventory inventory) { + public static IronChestContainer createDiamondContainer(int windowId, Inventory playerInventory, Container inventory) { return new IronChestContainer(IronChestsContainerTypes.DIAMOND_CHEST.get(), windowId, playerInventory, inventory, IronChestsTypes.DIAMOND); } - public static IronChestContainer createCrystalContainer(int windowId, PlayerInventory playerInventory) { - return new IronChestContainer(IronChestsContainerTypes.CRYSTAL_CHEST.get(), windowId, playerInventory, new Inventory(IronChestsTypes.CRYSTAL.size), IronChestsTypes.CRYSTAL); + public static IronChestContainer createCrystalContainer(int windowId, Inventory playerInventory) { + return new IronChestContainer(IronChestsContainerTypes.CRYSTAL_CHEST.get(), windowId, playerInventory, new SimpleContainer(IronChestsTypes.CRYSTAL.size), IronChestsTypes.CRYSTAL); } - public static IronChestContainer createCrystalContainer(int windowId, PlayerInventory playerInventory, IInventory inventory) { + public static IronChestContainer createCrystalContainer(int windowId, Inventory playerInventory, Container inventory) { return new IronChestContainer(IronChestsContainerTypes.CRYSTAL_CHEST.get(), windowId, playerInventory, inventory, IronChestsTypes.CRYSTAL); } - public static IronChestContainer createCopperContainer(int windowId, PlayerInventory playerInventory) { - return new IronChestContainer(IronChestsContainerTypes.COPPER_CHEST.get(), windowId, playerInventory, new Inventory(IronChestsTypes.COPPER.size), IronChestsTypes.COPPER); + public static IronChestContainer createCopperContainer(int windowId, Inventory playerInventory) { + return new IronChestContainer(IronChestsContainerTypes.COPPER_CHEST.get(), windowId, playerInventory, new SimpleContainer(IronChestsTypes.COPPER.size), IronChestsTypes.COPPER); } - public static IronChestContainer createCopperContainer(int windowId, PlayerInventory playerInventory, IInventory inventory) { + public static IronChestContainer createCopperContainer(int windowId, Inventory playerInventory, Container inventory) { return new IronChestContainer(IronChestsContainerTypes.COPPER_CHEST.get(), windowId, playerInventory, inventory, IronChestsTypes.COPPER); } - public static IronChestContainer createSilverContainer(int windowId, PlayerInventory playerInventory) { - return new IronChestContainer(IronChestsContainerTypes.SILVER_CHEST.get(), windowId, playerInventory, new Inventory(IronChestsTypes.CRYSTAL.size), IronChestsTypes.SILVER); + public static IronChestContainer createSilverContainer(int windowId, Inventory playerInventory) { + return new IronChestContainer(IronChestsContainerTypes.SILVER_CHEST.get(), windowId, playerInventory, new SimpleContainer(IronChestsTypes.CRYSTAL.size), IronChestsTypes.SILVER); } - public static IronChestContainer createSilverContainer(int windowId, PlayerInventory playerInventory, IInventory inventory) { + public static IronChestContainer createSilverContainer(int windowId, Inventory playerInventory, Container inventory) { return new IronChestContainer(IronChestsContainerTypes.SILVER_CHEST.get(), windowId, playerInventory, inventory, IronChestsTypes.SILVER); } - public static IronChestContainer createObsidianContainer(int windowId, PlayerInventory playerInventory) { - return new IronChestContainer(IronChestsContainerTypes.OBSIDIAN_CHEST.get(), windowId, playerInventory, new Inventory(IronChestsTypes.OBSIDIAN.size), IronChestsTypes.OBSIDIAN); + public static IronChestContainer createObsidianContainer(int windowId, Inventory playerInventory) { + return new IronChestContainer(IronChestsContainerTypes.OBSIDIAN_CHEST.get(), windowId, playerInventory, new SimpleContainer(IronChestsTypes.OBSIDIAN.size), IronChestsTypes.OBSIDIAN); } - public static IronChestContainer createObsidianContainer(int windowId, PlayerInventory playerInventory, IInventory inventory) { + public static IronChestContainer createObsidianContainer(int windowId, Inventory playerInventory, Container inventory) { return new IronChestContainer(IronChestsContainerTypes.OBSIDIAN_CHEST.get(), windowId, playerInventory, inventory, IronChestsTypes.OBSIDIAN); } - public static IronChestContainer createDirtContainer(int windowId, PlayerInventory playerInventory) { - return new IronChestContainer(IronChestsContainerTypes.DIRT_CHEST.get(), windowId, playerInventory, new Inventory(IronChestsTypes.DIRT.size), IronChestsTypes.DIRT); + public static IronChestContainer createDirtContainer(int windowId, Inventory playerInventory) { + return new IronChestContainer(IronChestsContainerTypes.DIRT_CHEST.get(), windowId, playerInventory, new SimpleContainer(IronChestsTypes.DIRT.size), IronChestsTypes.DIRT); } - public static IronChestContainer createDirtContainer(int windowId, PlayerInventory playerInventory, IInventory inventory) { + public static IronChestContainer createDirtContainer(int windowId, Inventory playerInventory, Container inventory) { return new IronChestContainer(IronChestsContainerTypes.DIRT_CHEST.get(), windowId, playerInventory, inventory, IronChestsTypes.DIRT); } - public IronChestContainer(ContainerType containerType, int windowId, PlayerInventory playerInventory, IInventory inventory, IronChestsTypes chestType) { + public IronChestContainer(MenuType containerType, int windowId, Inventory playerInventory, Container inventory, IronChestsTypes chestType) { super(containerType, windowId); - assertInventorySize(inventory, chestType.size); + checkContainerSize(inventory, chestType.size); this.inventory = inventory; this.chestType = chestType; - inventory.openInventory(playerInventory.player); + inventory.startOpen(playerInventory.player); if (chestType == IronChestsTypes.DIRT) { this.addSlot(new DirtChestSlot(inventory, 0, 12 + 4 * 18, 8 + 2 * 18)); @@ -121,33 +121,33 @@ public class IronChestContainer extends Container { } @Override - public boolean canInteractWith(PlayerEntity playerIn) { - return this.inventory.isUsableByPlayer(playerIn); + public boolean stillValid(Player playerIn) { + return this.inventory.stillValid(playerIn); } @Override - public ItemStack transferStackInSlot(PlayerEntity playerIn, int index) { + public ItemStack quickMoveStack(Player playerIn, int index) { ItemStack itemstack = ItemStack.EMPTY; - Slot slot = this.inventorySlots.get(index); + Slot slot = this.slots.get(index); - if (slot != null && slot.getHasStack()) { - ItemStack itemstack1 = slot.getStack(); + if (slot != null && slot.hasItem()) { + ItemStack itemstack1 = slot.getItem(); itemstack = itemstack1.copy(); if (index < this.chestType.size) { - if (!this.mergeItemStack(itemstack1, this.chestType.size, this.inventorySlots.size(), true)) { + if (!this.moveItemStackTo(itemstack1, this.chestType.size, this.slots.size(), true)) { return ItemStack.EMPTY; } } - else if (!this.mergeItemStack(itemstack1, 0, this.chestType.size, false)) { + else if (!this.moveItemStackTo(itemstack1, 0, this.chestType.size, false)) { return ItemStack.EMPTY; } if (itemstack1.isEmpty()) { - slot.putStack(ItemStack.EMPTY); + slot.set(ItemStack.EMPTY); } else { - slot.onSlotChanged(); + slot.setChanged(); } } @@ -155,9 +155,9 @@ public class IronChestContainer extends Container { } @Override - public void onContainerClosed(PlayerEntity playerIn) { - super.onContainerClosed(playerIn); - this.inventory.closeInventory(playerIn); + public void removed(Player playerIn) { + super.removed(playerIn); + this.inventory.stopOpen(playerIn); } @OnlyIn(Dist.CLIENT) diff --git a/src/main/java/com/progwml6/ironchest/common/inventory/IronChestsContainerTypes.java b/src/main/java/com/progwml6/ironchest/common/inventory/IronChestsContainerTypes.java index 78cccb5..b801596 100644 --- a/src/main/java/com/progwml6/ironchest/common/inventory/IronChestsContainerTypes.java +++ b/src/main/java/com/progwml6/ironchest/common/inventory/IronChestsContainerTypes.java @@ -1,28 +1,28 @@ package com.progwml6.ironchest.common.inventory; import com.progwml6.ironchest.IronChests; -import net.minecraft.inventory.container.ContainerType; +import net.minecraft.world.inventory.MenuType; import net.minecraftforge.fml.RegistryObject; import net.minecraftforge.registries.DeferredRegister; import net.minecraftforge.registries.ForgeRegistries; public class IronChestsContainerTypes { - public static final DeferredRegister> CONTAINERS = DeferredRegister.create(ForgeRegistries.CONTAINERS, IronChests.MODID); + public static final DeferredRegister> CONTAINERS = DeferredRegister.create(ForgeRegistries.CONTAINERS, IronChests.MODID); - public static final RegistryObject> IRON_CHEST = CONTAINERS.register("iron_chest", () -> new ContainerType<>(IronChestContainer::createIronContainer)); + public static final RegistryObject> IRON_CHEST = CONTAINERS.register("iron_chest", () -> new MenuType<>(IronChestContainer::createIronContainer)); - public static final RegistryObject> GOLD_CHEST = CONTAINERS.register("gold_chest", () -> new ContainerType<>(IronChestContainer::createGoldContainer)); + public static final RegistryObject> GOLD_CHEST = CONTAINERS.register("gold_chest", () -> new MenuType<>(IronChestContainer::createGoldContainer)); - public static final RegistryObject> DIAMOND_CHEST = CONTAINERS.register("diamond_chest", () -> new ContainerType<>(IronChestContainer::createDiamondContainer)); + public static final RegistryObject> DIAMOND_CHEST = CONTAINERS.register("diamond_chest", () -> new MenuType<>(IronChestContainer::createDiamondContainer)); - public static final RegistryObject> CRYSTAL_CHEST = CONTAINERS.register("crystal_chest", () -> new ContainerType<>(IronChestContainer::createCrystalContainer)); + public static final RegistryObject> CRYSTAL_CHEST = CONTAINERS.register("crystal_chest", () -> new MenuType<>(IronChestContainer::createCrystalContainer)); - public static final RegistryObject> COPPER_CHEST = CONTAINERS.register("copper_chest", () -> new ContainerType<>(IronChestContainer::createCopperContainer)); + public static final RegistryObject> COPPER_CHEST = CONTAINERS.register("copper_chest", () -> new MenuType<>(IronChestContainer::createCopperContainer)); - public static final RegistryObject> SILVER_CHEST = CONTAINERS.register("silver_chest", () -> new ContainerType<>(IronChestContainer::createSilverContainer)); + public static final RegistryObject> SILVER_CHEST = CONTAINERS.register("silver_chest", () -> new MenuType<>(IronChestContainer::createSilverContainer)); - public static final RegistryObject> OBSIDIAN_CHEST = CONTAINERS.register("obsidian_chest", () -> new ContainerType<>(IronChestContainer::createObsidianContainer)); + public static final RegistryObject> OBSIDIAN_CHEST = CONTAINERS.register("obsidian_chest", () -> new MenuType<>(IronChestContainer::createObsidianContainer)); - public static final RegistryObject> DIRT_CHEST = CONTAINERS.register("dirt_chest", () -> new ContainerType<>(IronChestContainer::createDirtContainer)); + public static final RegistryObject> DIRT_CHEST = CONTAINERS.register("dirt_chest", () -> new MenuType<>(IronChestContainer::createDirtContainer)); } diff --git a/src/main/java/com/progwml6/ironchest/common/item/ChestUpgradeItem.java b/src/main/java/com/progwml6/ironchest/common/item/ChestUpgradeItem.java index 5f5e003..8fe3255 100644 --- a/src/main/java/com/progwml6/ironchest/common/item/ChestUpgradeItem.java +++ b/src/main/java/com/progwml6/ironchest/common/item/ChestUpgradeItem.java @@ -3,26 +3,28 @@ package com.progwml6.ironchest.common.item; import com.progwml6.ironchest.common.block.GenericIronChestBlock; import com.progwml6.ironchest.common.block.IronChestsTypes; import com.progwml6.ironchest.common.block.tileentity.GenericIronChestTileEntity; -import net.minecraft.block.BlockState; -import net.minecraft.block.ChestBlock; -import net.minecraft.client.util.ITooltipFlag; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.item.Item; -import net.minecraft.item.ItemStack; -import net.minecraft.item.ItemUseContext; -import net.minecraft.tileentity.ChestTileEntity; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.ActionResultType; -import net.minecraft.util.Direction; -import net.minecraft.util.NonNullList; -import net.minecraft.util.math.BlockPos; -import net.minecraft.util.text.ITextComponent; +import net.minecraft.world.level.block.state.BlockState; +import net.minecraft.world.level.block.ChestBlock; +import net.minecraft.world.item.TooltipFlag; +import net.minecraft.world.entity.player.Player; +import net.minecraft.world.item.Item; +import net.minecraft.world.item.ItemStack; +import net.minecraft.world.item.context.UseOnContext; +import net.minecraft.world.level.block.entity.ChestBlockEntity; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.world.InteractionResult; +import net.minecraft.core.Direction; +import net.minecraft.core.NonNullList; +import net.minecraft.core.BlockPos; +import net.minecraft.network.chat.Component; import net.minecraft.util.text.TextFormatting; import net.minecraft.util.text.TranslationTextComponent; -import net.minecraft.world.World; +import net.minecraft.world.level.Level; import java.util.List; +import net.minecraft.world.item.Item.Properties; + public class ChestUpgradeItem extends Item { private final IronChestsUpgradeType type; @@ -33,47 +35,47 @@ public class ChestUpgradeItem extends Item { } @Override - public void addInformation(ItemStack stack, World worldIn, List tooltip, ITooltipFlag flagIn) { - super.addInformation(stack, worldIn, tooltip, flagIn); + public void appendHoverText(ItemStack stack, Level worldIn, List tooltip, TooltipFlag flagIn) { + super.appendHoverText(stack, worldIn, tooltip, flagIn); //tooltip.add(new TranslationTextComponent(this.getTranslationKey() + ".desc").applyTextStyle(TextFormatting.GRAY)); } @Override - public ActionResultType onItemUseFirst(ItemStack stack, ItemUseContext context) { - PlayerEntity entityPlayer = context.getPlayer(); - BlockPos blockPos = context.getPos(); - World world = context.getWorld(); - ItemStack itemStack = context.getItem(); + public InteractionResult onItemUseFirst(ItemStack stack, UseOnContext context) { + Player entityPlayer = context.getPlayer(); + BlockPos blockPos = context.getClickedPos(); + Level world = context.getLevel(); + ItemStack itemStack = context.getItemInHand(); - if (world.isRemote) { - return ActionResultType.PASS; + if (world.isClientSide) { + return InteractionResult.PASS; } if (entityPlayer == null) { - return ActionResultType.PASS; + return InteractionResult.PASS; } if (this.type.canUpgrade(IronChestsTypes.WOOD)) { if (!(world.getBlockState(blockPos).getBlock() instanceof ChestBlock)) { - return ActionResultType.PASS; + return InteractionResult.PASS; } } else { - if (world.getBlockState(blockPos).getBlock().getDefaultState() != IronChestsTypes.get(this.type.source).getDefaultState()) { - return ActionResultType.PASS; + if (world.getBlockState(blockPos).getBlock().defaultBlockState() != IronChestsTypes.get(this.type.source).defaultBlockState()) { + return InteractionResult.PASS; } } - TileEntity tileEntity = world.getTileEntity(blockPos); + BlockEntity tileEntity = world.getBlockEntity(blockPos); if (this.type.canUpgrade(IronChestsTypes.WOOD)) { - if (!(tileEntity instanceof ChestTileEntity)) { - return ActionResultType.PASS; + if (!(tileEntity instanceof ChestBlockEntity)) { + return InteractionResult.PASS; } } GenericIronChestTileEntity newChest = null; - ITextComponent customName = null; + Component customName = null; NonNullList chestContents = NonNullList.withSize(27, ItemStack.EMPTY); Direction chestFacing = Direction.NORTH; @@ -83,43 +85,43 @@ public class ChestUpgradeItem extends Item { BlockState chestState = world.getBlockState(blockPos); if (GenericIronChestTileEntity.getPlayersUsing(world, blockPos) > 0) { - return ActionResultType.PASS; + return InteractionResult.PASS; } if (!chest.canOpen(entityPlayer)) { - return ActionResultType.PASS; + return InteractionResult.PASS; } chestContents = chest.getItems(); - chestFacing = chestState.get(GenericIronChestBlock.FACING); + chestFacing = chestState.getValue(GenericIronChestBlock.FACING); customName = chest.getCustomName(); newChest = this.type.target.makeEntity(); if (newChest == null) { - return ActionResultType.PASS; + return InteractionResult.PASS; } } - else if (tileEntity instanceof ChestTileEntity) { + else if (tileEntity instanceof ChestBlockEntity) { BlockState chestState = world.getBlockState(blockPos); - chestFacing = chestState.get(ChestBlock.FACING); - ChestTileEntity chest = (ChestTileEntity) tileEntity; + chestFacing = chestState.getValue(ChestBlock.FACING); + ChestBlockEntity chest = (ChestBlockEntity) tileEntity; - if (ChestTileEntity.getPlayersUsing(world, blockPos) > 0) { - return ActionResultType.PASS; + if (ChestBlockEntity.getOpenCount(world, blockPos) > 0) { + return InteractionResult.PASS; } if (!chest.canOpen(entityPlayer)) { - return ActionResultType.PASS; + return InteractionResult.PASS; } if (!this.type.canUpgrade(IronChestsTypes.WOOD)) { - return ActionResultType.PASS; + return InteractionResult.PASS; } - chestContents = NonNullList.withSize(chest.getSizeInventory(), ItemStack.EMPTY); + chestContents = NonNullList.withSize(chest.getContainerSize(), ItemStack.EMPTY); for (int slot = 0; slot < chestContents.size(); slot++) { - chestContents.set(slot, chest.getStackInSlot(slot)); + chestContents.set(slot, chest.getItem(slot)); } customName = chest.getCustomName(); @@ -128,19 +130,19 @@ public class ChestUpgradeItem extends Item { } } - tileEntity.updateContainingBlockInfo(); + tileEntity.clearCache(); - world.removeTileEntity(blockPos); + world.removeBlockEntity(blockPos); world.removeBlock(blockPos, false); - BlockState iBlockState = IronChestsTypes.get(this.type.target).getDefaultState().with(GenericIronChestBlock.FACING, chestFacing); + BlockState iBlockState = IronChestsTypes.get(this.type.target).defaultBlockState().setValue(GenericIronChestBlock.FACING, chestFacing); - world.setBlockState(blockPos, iBlockState, 3); - world.setTileEntity(blockPos, newChest); + world.setBlock(blockPos, iBlockState, 3); + world.setBlockEntity(blockPos, newChest); - world.notifyBlockUpdate(blockPos, iBlockState, iBlockState, 3); + world.sendBlockUpdated(blockPos, iBlockState, iBlockState, 3); - TileEntity tileEntity2 = world.getTileEntity(blockPos); + BlockEntity tileEntity2 = world.getBlockEntity(blockPos); if (tileEntity2 instanceof GenericIronChestTileEntity) { if (customName != null) { @@ -150,11 +152,11 @@ public class ChestUpgradeItem extends Item { ((GenericIronChestTileEntity) tileEntity2).setItems(chestContents); } - if (!entityPlayer.abilities.isCreativeMode) { + if (!entityPlayer.abilities.instabuild) { itemStack.shrink(1); } - return ActionResultType.SUCCESS; + return InteractionResult.SUCCESS; } } diff --git a/src/main/java/com/progwml6/ironchest/common/item/IronChestsItems.java b/src/main/java/com/progwml6/ironchest/common/item/IronChestsItems.java index e734c7b..ef6c59f 100644 --- a/src/main/java/com/progwml6/ironchest/common/item/IronChestsItems.java +++ b/src/main/java/com/progwml6/ironchest/common/item/IronChestsItems.java @@ -2,7 +2,7 @@ package com.progwml6.ironchest.common.item; import com.google.common.collect.ImmutableMap; import com.progwml6.ironchest.IronChests; -import net.minecraft.item.Item; +import net.minecraft.world.item.Item; import net.minecraftforge.fml.RegistryObject; import net.minecraftforge.registries.DeferredRegister; import net.minecraftforge.registries.ForgeRegistries; @@ -19,7 +19,7 @@ public class IronChestsItems { public static final ImmutableMap> UPGRADES = ImmutableMap.copyOf(Arrays.stream(IronChestsUpgradeType.values()) .collect(Collectors.toMap(Function.identity(), type -> register(type.name().toLowerCase(Locale.ROOT) + "_chest_upgrade", - () -> new ChestUpgradeItem(type, new Item.Properties().group(IronChests.IRONCHESTS_ITEM_GROUP).maxStackSize(1)))))); + () -> new ChestUpgradeItem(type, new Item.Properties().tab(IronChests.IRONCHESTS_ITEM_GROUP).stacksTo(1)))))); private static RegistryObject register(final String name, final Supplier sup) { return ITEMS.register(name, sup); diff --git a/src/main/java/com/progwml6/ironchest/common/network/InventoryTopStacksSyncPacket.java b/src/main/java/com/progwml6/ironchest/common/network/InventoryTopStacksSyncPacket.java index 5527634..4d6c8e0 100644 --- a/src/main/java/com/progwml6/ironchest/common/network/InventoryTopStacksSyncPacket.java +++ b/src/main/java/com/progwml6/ironchest/common/network/InventoryTopStacksSyncPacket.java @@ -3,12 +3,12 @@ package com.progwml6.ironchest.common.network; import com.progwml6.ironchest.common.block.tileentity.CrystalChestTileEntity; import com.progwml6.ironchest.common.network.helper.IThreadsafePacket; import net.minecraft.client.Minecraft; -import net.minecraft.item.ItemStack; -import net.minecraft.network.PacketBuffer; -import net.minecraft.tileentity.TileEntity; -import net.minecraft.util.NonNullList; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.World; +import net.minecraft.world.item.ItemStack; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.world.level.block.entity.BlockEntity; +import net.minecraft.core.NonNullList; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.Level; import net.minecraftforge.fml.network.NetworkEvent.Context; public class InventoryTopStacksSyncPacket implements IThreadsafePacket { @@ -21,12 +21,12 @@ public class InventoryTopStacksSyncPacket implements IThreadsafePacket { this.pos = pos; } - public InventoryTopStacksSyncPacket(PacketBuffer buffer) { + public InventoryTopStacksSyncPacket(FriendlyByteBuf buffer) { int size = buffer.readInt(); NonNullList topStacks = NonNullList.withSize(size, ItemStack.EMPTY); for (int item = 0; item < size; item++) { - ItemStack itemStack = buffer.readItemStack(); + ItemStack itemStack = buffer.readItem(); topStacks.set(item, itemStack); } @@ -37,11 +37,11 @@ public class InventoryTopStacksSyncPacket implements IThreadsafePacket { } @Override - public void encode(PacketBuffer packetBuffer) { + public void encode(FriendlyByteBuf packetBuffer) { packetBuffer.writeInt(this.topStacks.size()); for (ItemStack stack : this.topStacks) { - packetBuffer.writeItemStack(stack); + packetBuffer.writeItem(stack); } packetBuffer.writeBlockPos(this.pos); @@ -58,15 +58,15 @@ public class InventoryTopStacksSyncPacket implements IThreadsafePacket { private static class HandleClient { private static void handle(InventoryTopStacksSyncPacket packet) { - World world = Minecraft.getInstance().world; + Level world = Minecraft.getInstance().level; if (world != null) { - TileEntity te = world.getTileEntity(packet.pos); + BlockEntity te = world.getBlockEntity(packet.pos); if (te != null) { if (te instanceof CrystalChestTileEntity) { ((CrystalChestTileEntity) te).receiveMessageFromServer(packet.topStacks); - Minecraft.getInstance().worldRenderer.notifyBlockUpdate(null, packet.pos, null, null, 0); + Minecraft.getInstance().levelRenderer.blockChanged(null, packet.pos, null, null, 0); } } } diff --git a/src/main/java/com/progwml6/ironchest/common/network/IronChestNetwork.java b/src/main/java/com/progwml6/ironchest/common/network/IronChestNetwork.java index 21fd765..ed0d97b 100644 --- a/src/main/java/com/progwml6/ironchest/common/network/IronChestNetwork.java +++ b/src/main/java/com/progwml6/ironchest/common/network/IronChestNetwork.java @@ -2,16 +2,16 @@ package com.progwml6.ironchest.common.network; import com.progwml6.ironchest.IronChests; import com.progwml6.ironchest.common.network.helper.ISimplePacket; -import net.minecraft.entity.Entity; -import net.minecraft.entity.player.PlayerEntity; -import net.minecraft.entity.player.ServerPlayerEntity; -import net.minecraft.network.IPacket; -import net.minecraft.network.PacketBuffer; -import net.minecraft.util.ResourceLocation; -import net.minecraft.util.math.BlockPos; -import net.minecraft.world.IWorld; -import net.minecraft.world.chunk.Chunk; -import net.minecraft.world.server.ServerWorld; +import net.minecraft.world.entity.Entity; +import net.minecraft.world.entity.player.Player; +import net.minecraft.server.level.ServerPlayer; +import net.minecraft.network.protocol.Packet; +import net.minecraft.network.FriendlyByteBuf; +import net.minecraft.resources.ResourceLocation; +import net.minecraft.core.BlockPos; +import net.minecraft.world.level.LevelAccessor; +import net.minecraft.world.level.chunk.LevelChunk; +import net.minecraft.server.level.ServerLevel; import net.minecraftforge.common.util.FakePlayer; import net.minecraftforge.fml.network.NetworkDirection; import net.minecraftforge.fml.network.NetworkEvent; @@ -71,7 +71,7 @@ public class IronChestNetwork { * @param decoder Packet decoder, typically the constructor * @param Packet class type */ - public void registerPacket(Class clazz, Function decoder, @Nullable NetworkDirection direction) { + public void registerPacket(Class clazz, Function decoder, @Nullable NetworkDirection direction) { registerPacket(clazz, ISimplePacket::encode, decoder, ISimplePacket::handle, direction); } @@ -85,7 +85,7 @@ public class IronChestNetwork { * @param direction Network direction for validation. Pass null for no direction * @param Packet class type */ - public void registerPacket(Class clazz, BiConsumer encoder, Function decoder, BiConsumer> consumer, @Nullable NetworkDirection direction) { + public void registerPacket(Class clazz, BiConsumer encoder, Function decoder, BiConsumer> consumer, @Nullable NetworkDirection direction) { this.network.registerMessage(this.id++, clazz, encoder, decoder, consumer, Optional.ofNullable(direction)); } @@ -116,9 +116,9 @@ public class IronChestNetwork { * @param player Player receiving the packet * @param packet Packet */ - public void sendVanillaPacket(IPacket packet, Entity player) { - if (player instanceof ServerPlayerEntity && ((ServerPlayerEntity) player).connection != null) { - ((ServerPlayerEntity) player).connection.sendPacket(packet); + public void sendVanillaPacket(Packet packet, Entity player) { + if (player instanceof ServerPlayer && ((ServerPlayer) player).connection != null) { + ((ServerPlayer) player).connection.send(packet); } } @@ -128,9 +128,9 @@ public class IronChestNetwork { * @param msg Packet * @param player Player to send */ - public void sendTo(Object msg, PlayerEntity player) { - if (player instanceof ServerPlayerEntity) { - sendTo(msg, (ServerPlayerEntity) player); + public void sendTo(Object msg, Player player) { + if (player instanceof ServerPlayer) { + sendTo(msg, (ServerPlayer) player); } } @@ -140,9 +140,9 @@ public class IronChestNetwork { * @param msg Packet * @param player Player to send */ - public void sendTo(Object msg, ServerPlayerEntity player) { + public void sendTo(Object msg, ServerPlayer player) { if (!(player instanceof FakePlayer)) { - network.sendTo(msg, player.connection.netManager, NetworkDirection.PLAY_TO_CLIENT); + network.sendTo(msg, player.connection.connection, NetworkDirection.PLAY_TO_CLIENT); } } @@ -153,8 +153,8 @@ public class IronChestNetwork { * @param serverWorld World instance * @param position Position within range */ - public void sendToClientsAround(Object msg, ServerWorld serverWorld, BlockPos position) { - Chunk chunk = serverWorld.getChunkAt(position); + public void sendToClientsAround(Object msg, ServerLevel serverWorld, BlockPos position) { + LevelChunk chunk = serverWorld.getChunkAt(position); network.send(PacketDistributor.TRACKING_CHUNK.with(() -> chunk), msg); } @@ -185,9 +185,9 @@ public class IronChestNetwork { * @param world World instance * @param position Target position */ - public void sendToClientsAround(Object msg, @Nullable IWorld world, BlockPos position) { - if (world instanceof ServerWorld) { - sendToClientsAround(msg, (ServerWorld) world, position); + public void sendToClientsAround(Object msg, @Nullable LevelAccessor world, BlockPos position) { + if (world instanceof ServerLevel) { + sendToClientsAround(msg, (ServerLevel) world, position); } } } diff --git a/src/main/java/com/progwml6/ironchest/common/network/helper/ISimplePacket.java b/src/main/java/com/progwml6/ironchest/common/network/helper/ISimplePacket.java index 67bfeda..7008bbf 100644 --- a/src/main/java/com/progwml6/ironchest/common/network/helper/ISimplePacket.java +++ b/src/main/java/com/progwml6/ironchest/common/network/helper/ISimplePacket.java @@ -1,6 +1,6 @@ package com.progwml6.ironchest.common.network.helper; -import net.minecraft.network.PacketBuffer; +import net.minecraft.network.FriendlyByteBuf; import net.minecraftforge.fml.network.NetworkEvent; import java.util.function.Supplier; @@ -13,7 +13,7 @@ public interface ISimplePacket { * Encodes a packet for the buffer * @param buf Buffer instance */ - void encode(PacketBuffer buf); + void encode(FriendlyByteBuf buf); /** * Handles receiving the packet diff --git a/src/main/resources/META-INF/accesstransformer.cfg b/src/main/resources/META-INF/accesstransformer.cfg index 2c2f0d2..69a8465 100644 --- a/src/main/resources/META-INF/accesstransformer.cfg +++ b/src/main/resources/META-INF/accesstransformer.cfg @@ -1 +1 @@ -public net.minecraft.entity.ai.goal.GoalSelector field_220892_d # goals \ No newline at end of file +public net.minecraft.world.entity.ai.goal.GoalSelector f_25345_ # goals \ No newline at end of file