Start working on updating Iron Chests to 1.17.1

This commit is contained in:
Alexander Behrhof 2021-07-26 21:27:26 -04:00
parent 6206a33628
commit 3c4cefdad3
40 changed files with 873 additions and 854 deletions

View File

@ -23,10 +23,11 @@ repositories {
group = "com.progwml6.ironchest" 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 { minecraft {
mappings channel: 'snapshot', version: mappings_version mappings channel: 'official', version: mappings_version
accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg') accessTransformer = file('src/main/resources/META-INF/accesstransformer.cfg')

View File

@ -7,16 +7,16 @@ org.gradle.daemon=false
mod_version=11.2 mod_version=11.2
# Minecraft Version Information # Minecraft Version Information
minecraft_version=1.16.5 minecraft_version=1.17.1
minecraft_range=[1.16.5,1.17) minecraft_range=[1.17.1,1.18)
# Forge Version Information # Forge Version Information
loader_range=[33.0,) loader_range=[33.0,)
forge_version=36.1.1 forge_version=37.0.1
forge_range=[36.1.1,) forge_range=[37.0.1,)
# Mappings Information # Mappings Information
mappings_version=20200916-1.16.2 mappings_version=1.17.1
# Build dependencies # Build dependencies
jei_version=1.16.4:7.6.1.65 jei_version=1.16.4:7.6.1.65

View File

@ -8,10 +8,10 @@ import com.progwml6.ironchest.common.data.IronChestsRecipeProvider;
import com.progwml6.ironchest.common.inventory.IronChestsContainerTypes; import com.progwml6.ironchest.common.inventory.IronChestsContainerTypes;
import com.progwml6.ironchest.common.item.IronChestsItems; import com.progwml6.ironchest.common.item.IronChestsItems;
import com.progwml6.ironchest.common.network.IronChestNetwork; 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.data.DataGenerator;
import net.minecraft.item.ItemGroup; import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.eventbus.api.IEventBus; import net.minecraftforge.eventbus.api.IEventBus;
@ -28,10 +28,10 @@ public class IronChests {
public static final String MODID = "ironchest"; 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 @Override
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public ItemStack createIcon() { public ItemStack makeIcon() {
return new ItemStack(IronChestsBlocks.IRON_CHEST.get()); return new ItemStack(IronChestsBlocks.IRON_CHEST.get());
} }
}); });
@ -59,14 +59,14 @@ public class IronChests {
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
private void setupClient(final FMLClientSetupEvent event) { private void setupClient(final FMLClientSetupEvent event) {
ScreenManager.registerFactory(IronChestsContainerTypes.IRON_CHEST.get(), IronChestScreen::new); MenuScreens.register(IronChestsContainerTypes.IRON_CHEST.get(), IronChestScreen::new);
ScreenManager.registerFactory(IronChestsContainerTypes.GOLD_CHEST.get(), IronChestScreen::new); MenuScreens.register(IronChestsContainerTypes.GOLD_CHEST.get(), IronChestScreen::new);
ScreenManager.registerFactory(IronChestsContainerTypes.DIAMOND_CHEST.get(), IronChestScreen::new); MenuScreens.register(IronChestsContainerTypes.DIAMOND_CHEST.get(), IronChestScreen::new);
ScreenManager.registerFactory(IronChestsContainerTypes.CRYSTAL_CHEST.get(), IronChestScreen::new); MenuScreens.register(IronChestsContainerTypes.CRYSTAL_CHEST.get(), IronChestScreen::new);
ScreenManager.registerFactory(IronChestsContainerTypes.COPPER_CHEST.get(), IronChestScreen::new); MenuScreens.register(IronChestsContainerTypes.COPPER_CHEST.get(), IronChestScreen::new);
ScreenManager.registerFactory(IronChestsContainerTypes.SILVER_CHEST.get(), IronChestScreen::new); MenuScreens.register(IronChestsContainerTypes.SILVER_CHEST.get(), IronChestScreen::new);
ScreenManager.registerFactory(IronChestsContainerTypes.OBSIDIAN_CHEST.get(), IronChestScreen::new); MenuScreens.register(IronChestsContainerTypes.OBSIDIAN_CHEST.get(), IronChestScreen::new);
ScreenManager.registerFactory(IronChestsContainerTypes.DIRT_CHEST.get(), IronChestScreen::new); MenuScreens.register(IronChestsContainerTypes.DIRT_CHEST.get(), IronChestScreen::new);
ClientRegistry.bindTileEntityRenderer(IronChestsTileEntityTypes.IRON_CHEST.get(), IronChestTileEntityRenderer::new); ClientRegistry.bindTileEntityRenderer(IronChestsTileEntityTypes.IRON_CHEST.get(), IronChestTileEntityRenderer::new);
ClientRegistry.bindTileEntityRenderer(IronChestsTileEntityTypes.GOLD_CHEST.get(), IronChestTileEntityRenderer::new); ClientRegistry.bindTileEntityRenderer(IronChestsTileEntityTypes.GOLD_CHEST.get(), IronChestTileEntityRenderer::new);

View File

@ -2,8 +2,8 @@ package com.progwml6.ironchest.client.model;
import com.progwml6.ironchest.IronChests; import com.progwml6.ironchest.IronChests;
import com.progwml6.ironchest.common.block.IronChestsTypes; import com.progwml6.ironchest.common.block.IronChestsTypes;
import net.minecraft.client.renderer.Atlases; import net.minecraft.client.renderer.Sheets;
import net.minecraft.util.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.client.event.TextureStitchEvent; import net.minecraftforge.client.event.TextureStitchEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.eventbus.api.SubscribeEvent;
@ -50,7 +50,7 @@ public class IronChestsModels {
@SubscribeEvent @SubscribeEvent
public static void onStitch(TextureStitchEvent.Pre event) { public static void onStitch(TextureStitchEvent.Pre event) {
if (!event.getMap().getTextureLocation().equals(Atlases.CHEST_ATLAS)) { if (!event.getMap().location().equals(Sheets.CHEST_SHEET)) {
return; return;
} }

View File

@ -1,19 +1,19 @@
package com.progwml6.ironchest.client.model.inventory; package com.progwml6.ironchest.client.model.inventory;
import com.mojang.blaze3d.matrix.MatrixStack; import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.model.ItemCameraTransforms; import net.minecraft.client.renderer.block.model.ItemTransforms;
import net.minecraft.client.renderer.tileentity.ItemStackTileEntityRenderer; import net.minecraft.client.renderer.BlockEntityWithoutLevelRenderer;
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; import net.minecraft.client.renderer.blockentity.BlockEntityRenderDispatcher;
import net.minecraft.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.tileentity.TileEntity; import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.api.distmarker.OnlyIn;
import java.util.function.Supplier; import java.util.function.Supplier;
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public class IronChestItemStackRenderer<T extends TileEntity> extends ItemStackTileEntityRenderer { public class IronChestItemStackRenderer<T extends BlockEntity> extends BlockEntityWithoutLevelRenderer {
private final Supplier<T> te; private final Supplier<T> te;
@ -22,7 +22,7 @@ public class IronChestItemStackRenderer<T extends TileEntity> extends ItemStackT
} }
@Override @Override
public void func_239207_a_(ItemStack itemStackIn, ItemCameraTransforms.TransformType transformType, MatrixStack matrixStackIn, IRenderTypeBuffer bufferIn, int combinedLightIn, int combinedOverlayIn) { public void renderByItem(ItemStack itemStackIn, ItemTransforms.TransformType transformType, PoseStack matrixStackIn, MultiBufferSource bufferIn, int combinedLightIn, int combinedOverlayIn) {
TileEntityRendererDispatcher.instance.renderItem(this.te.get(), matrixStackIn, bufferIn, combinedLightIn, combinedOverlayIn); BlockEntityRenderDispatcher.instance.renderItem(this.te.get(), matrixStackIn, bufferIn, combinedLightIn, combinedOverlayIn);
} }
} }

View File

@ -1,6 +1,6 @@
package com.progwml6.ironchest.client.model.inventory; package com.progwml6.ironchest.client.model.inventory;
import net.minecraft.util.math.vector.Vector3f; import com.mojang.math.Vector3f;
public class ModelItem { public class ModelItem {
private final Vector3f center; private final Vector3f center;

View File

@ -1,50 +1,50 @@
package com.progwml6.ironchest.client.render; package com.progwml6.ironchest.client.render;
import com.google.common.primitives.SignedBytes; import com.google.common.primitives.SignedBytes;
import com.mojang.blaze3d.matrix.MatrixStack; import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.IVertexBuilder; import com.mojang.blaze3d.vertex.VertexConsumer;
import com.progwml6.ironchest.client.model.IronChestsModels; import com.progwml6.ironchest.client.model.IronChestsModels;
import com.progwml6.ironchest.client.model.inventory.ModelItem; import com.progwml6.ironchest.client.model.inventory.ModelItem;
import com.progwml6.ironchest.common.block.GenericIronChestBlock; import com.progwml6.ironchest.common.block.GenericIronChestBlock;
import com.progwml6.ironchest.common.block.IronChestsTypes; import com.progwml6.ironchest.common.block.IronChestsTypes;
import com.progwml6.ironchest.common.block.tileentity.CrystalChestTileEntity; import com.progwml6.ironchest.common.block.tileentity.CrystalChestTileEntity;
import com.progwml6.ironchest.common.block.tileentity.GenericIronChestTileEntity; import com.progwml6.ironchest.common.block.tileentity.GenericIronChestTileEntity;
import net.minecraft.block.Block; import net.minecraft.world.level.block.Block;
import net.minecraft.block.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.Atlases; import net.minecraft.client.renderer.Sheets;
import net.minecraft.client.renderer.IRenderTypeBuffer; import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.RenderType; 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.ItemCameraTransforms;
import net.minecraft.client.renderer.model.ModelRenderer; import net.minecraft.client.model.geom.ModelPart;
import net.minecraft.client.renderer.model.RenderMaterial; import net.minecraft.client.resources.model.Material;
import net.minecraft.client.renderer.texture.OverlayTexture; import net.minecraft.client.renderer.texture.OverlayTexture;
import net.minecraft.client.renderer.tileentity.DualBrightnessCallback; import net.minecraft.client.renderer.blockentity.BrightnessCombiner;
import net.minecraft.client.renderer.tileentity.TileEntityRenderer; import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
import net.minecraft.client.renderer.tileentity.TileEntityRendererDispatcher; import net.minecraft.client.renderer.blockentity.BlockEntityRenderDispatcher;
import net.minecraft.entity.EntityType; import net.minecraft.world.entity.EntityType;
import net.minecraft.entity.item.ItemEntity; import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.tileentity.IChestLid; import net.minecraft.world.level.block.entity.LidBlockEntity;
import net.minecraft.tileentity.TileEntity; import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.tileentity.TileEntityMerger; import net.minecraft.world.level.block.DoubleBlockCombiner;
import net.minecraft.util.Direction; import net.minecraft.core.Direction;
import net.minecraft.util.math.vector.Vector3d; import net.minecraft.world.phys.Vec3;
import net.minecraft.util.math.vector.Vector3f; import com.mojang.math.Vector3f;
import net.minecraft.world.World; import net.minecraft.world.level.Level;
import java.util.Arrays; import java.util.Arrays;
import java.util.List; import java.util.List;
public class IronChestTileEntityRenderer<T extends TileEntity & IChestLid> extends TileEntityRenderer<T> { public class IronChestTileEntityRenderer<T extends BlockEntity & LidBlockEntity> extends BlockEntityRenderer<T> {
private final ModelRenderer chestLid; private final ModelPart chestLid;
private final ModelRenderer chestBottom; private final ModelPart chestBottom;
private final ModelRenderer chestLock; private final ModelPart chestLock;
private static ItemEntity customItem; private static ItemEntity customItem;
private static ItemRenderer itemRenderer; private static ItemEntityRenderer itemRenderer;
private static final List<ModelItem> MODEL_ITEMS = Arrays.asList( private static final List<ModelItem> MODEL_ITEMS = Arrays.asList(
new ModelItem(new Vector3f(0.3F, 0.45F, 0.3F), 3.0F), new ModelItem(new Vector3f(0.3F, 0.45F, 0.3F), 3.0F),
@ -58,28 +58,28 @@ public class IronChestTileEntityRenderer<T extends TileEntity & IChestLid> exten
new ModelItem(new Vector3f(0.5F, 0.32F, 0.5F), 3.0F) new ModelItem(new Vector3f(0.5F, 0.32F, 0.5F), 3.0F)
); );
public IronChestTileEntityRenderer(TileEntityRendererDispatcher tileEntityRendererDispatcher) { public IronChestTileEntityRenderer(BlockEntityRenderDispatcher tileEntityRendererDispatcher) {
super(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.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.addBox(1.0F, 0.0F, 0.0F, 14.0F, 5.0F, 14.0F, 0.0F);
this.chestLid.rotationPointY = 9.0F; this.chestLid.y = 9.0F;
this.chestLid.rotationPointZ = 1.0F; this.chestLid.z = 1.0F;
this.chestLock = new ModelRenderer(64, 64, 0, 0); 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.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 @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; GenericIronChestTileEntity tileEntity = (GenericIronChestTileEntity) tileEntityIn;
World world = tileEntity.getWorld(); Level world = tileEntity.getLevel();
boolean flag = world != null; 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(); Block block = blockstate.getBlock();
IronChestsTypes chestType = IronChestsTypes.IRON; IronChestsTypes chestType = IronChestsTypes.IRON;
IronChestsTypes actualType = GenericIronChestBlock.getTypeFromBlock(block); IronChestsTypes actualType = GenericIronChestBlock.getTypeFromBlock(block);
@ -91,32 +91,32 @@ public class IronChestTileEntityRenderer<T extends TileEntity & IChestLid> exten
if (block instanceof GenericIronChestBlock) { if (block instanceof GenericIronChestBlock) {
GenericIronChestBlock ironChestBlock = (GenericIronChestBlock) block; GenericIronChestBlock ironChestBlock = (GenericIronChestBlock) block;
matrixStackIn.push(); matrixStackIn.pushPose();
float f = blockstate.get(GenericIronChestBlock.FACING).getHorizontalAngle(); float f = blockstate.getValue(GenericIronChestBlock.FACING).toYRot();
matrixStackIn.translate(0.5D, 0.5D, 0.5D); 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); matrixStackIn.translate(-0.5D, -0.5D, -0.5D);
TileEntityMerger.ICallbackWrapper<? extends GenericIronChestTileEntity> iCallbackWrapper; DoubleBlockCombiner.NeighborCombineResult<? extends GenericIronChestTileEntity> iCallbackWrapper;
if (flag) { if (flag) {
iCallbackWrapper = ironChestBlock.getWrapper(blockstate, world, tileEntity.getPos(), true); iCallbackWrapper = ironChestBlock.getWrapper(blockstate, world, tileEntity.getBlockPos(), true);
} else { } 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 = 1.0F - f1 * f1 * 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)); Material material = new Material(Sheets.CHEST_SHEET, IronChestsModels.chooseChestTexture(chestType));
IVertexBuilder ivertexbuilder = material.getBuffer(bufferIn, RenderType::getEntityCutout); VertexConsumer ivertexbuilder = material.buffer(bufferIn, RenderType::entityCutout);
this.handleModelRender(matrixStackIn, ivertexbuilder, this.chestLid, this.chestLock, this.chestBottom, f1, i, combinedOverlayIn); 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; float rotation = (float) (360D * (System.currentTimeMillis() & 0x3FFFL) / 0x3FFFL) - partialTicks;
CrystalChestTileEntity crystalChestTileEntity = (CrystalChestTileEntity) tileEntity; CrystalChestTileEntity crystalChestTileEntity = (CrystalChestTileEntity) tileEntity;
@ -132,9 +132,9 @@ public class IronChestTileEntityRenderer<T extends TileEntity & IChestLid> exten
} }
} }
private void handleModelRender(MatrixStack matrixStackIn, IVertexBuilder iVertexBuilder, ModelRenderer firstModel, ModelRenderer secondModel, ModelRenderer thirdModel, float f1, int p_228871_7_, int p_228871_8_) { private void handleModelRender(PoseStack matrixStackIn, VertexConsumer iVertexBuilder, ModelPart firstModel, ModelPart secondModel, ModelPart thirdModel, float f1, int p_228871_7_, int p_228871_8_) {
firstModel.rotateAngleX = -(f1 * ((float) Math.PI / 2F)); firstModel.xRot = -(f1 * ((float) Math.PI / 2F));
secondModel.rotateAngleX = firstModel.rotateAngleX; secondModel.xRot = firstModel.xRot;
firstModel.render(matrixStackIn, iVertexBuilder, p_228871_7_, p_228871_8_); firstModel.render(matrixStackIn, iVertexBuilder, p_228871_7_, p_228871_8_);
secondModel.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_); thirdModel.render(matrixStackIn, iVertexBuilder, p_228871_7_, p_228871_8_);
@ -149,18 +149,18 @@ public class IronChestTileEntityRenderer<T extends TileEntity & IChestLid> exten
* @param modelItem Model items for render information * @param modelItem Model items for render information
* @param light Model light * @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 no stack, skip
if (item.isEmpty()) return; if (item.isEmpty()) return;
customItem.setItem(item); customItem.setItem(item);
// start rendering // start rendering
matrices.push(); matrices.pushPose();
Vector3f center = modelItem.getCenter(); 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 // scale
float scale = modelItem.getSizeScaled(); float scale = modelItem.getSizeScaled();
@ -168,9 +168,9 @@ public class IronChestTileEntityRenderer<T extends TileEntity & IChestLid> exten
// render the actual item // render the actual item
if (itemRenderer == null) { if (itemRenderer == null) {
itemRenderer = new ItemRenderer(Minecraft.getInstance().getRenderManager(), Minecraft.getInstance().getItemRenderer()) { itemRenderer = new ItemEntityRenderer(Minecraft.getInstance().getEntityRenderDispatcher(), Minecraft.getInstance().getItemRenderer()) {
@Override @Override
public int getModelCount(ItemStack stack) { public int getRenderAmount(ItemStack stack) {
return SignedBytes.saturatedCast(Math.min(stack.getCount() / 32, 15) + 1); return SignedBytes.saturatedCast(Math.min(stack.getCount() / 32, 15) + 1);
} }
@ -187,6 +187,6 @@ public class IronChestTileEntityRenderer<T extends TileEntity & IChestLid> exten
} }
itemRenderer.render(customItem, 0F, partialTicks, matrices, buffer, light); itemRenderer.render(customItem, 0F, partialTicks, matrices, buffer, light);
matrices.pop(); matrices.popPose();
} }
} }

View File

@ -1,18 +1,18 @@
package com.progwml6.ironchest.client.screen; 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.mojang.blaze3d.systems.RenderSystem;
import com.progwml6.ironchest.common.block.IronChestsTypes; import com.progwml6.ironchest.common.block.IronChestsTypes;
import com.progwml6.ironchest.common.inventory.IronChestContainer; import com.progwml6.ironchest.common.inventory.IronChestContainer;
import net.minecraft.client.gui.IHasContainer; import net.minecraft.client.gui.screens.inventory.MenuAccess;
import net.minecraft.client.gui.screen.inventory.ContainerScreen; import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
import net.minecraft.entity.player.PlayerInventory; import net.minecraft.world.entity.player.Inventory;
import net.minecraft.util.text.ITextComponent; import net.minecraft.network.chat.Component;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.api.distmarker.OnlyIn;
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public class IronChestScreen extends ContainerScreen<IronChestContainer> implements IHasContainer<IronChestContainer> { public class IronChestScreen extends AbstractContainerScreen<IronChestContainer> implements MenuAccess<IronChestContainer> {
private final IronChestsTypes chestType; private final IronChestsTypes chestType;
@ -20,12 +20,12 @@ public class IronChestScreen extends ContainerScreen<IronChestContainer> impleme
private final int textureYSize; private final int textureYSize;
public IronChestScreen(IronChestContainer container, PlayerInventory playerInventory, ITextComponent title) { public IronChestScreen(IronChestContainer container, Inventory playerInventory, Component title) {
super(container, playerInventory, title); super(container, playerInventory, title);
this.chestType = container.getChestType(); this.chestType = container.getChestType();
this.xSize = container.getChestType().xSize; this.imageWidth = container.getChestType().xSize;
this.ySize = container.getChestType().ySize; this.imageHeight = container.getChestType().ySize;
this.textureXSize = container.getChestType().textureXSize; this.textureXSize = container.getChestType().textureXSize;
this.textureYSize = container.getChestType().textureYSize; this.textureYSize = container.getChestType().textureYSize;
@ -33,29 +33,29 @@ public class IronChestScreen extends ContainerScreen<IronChestContainer> impleme
} }
@Override @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); this.renderBackground(matrixStack);
super.render(matrixStack, mouseX, mouseY, partialTicks); super.render(matrixStack, mouseX, mouseY, partialTicks);
this.renderHoveredTooltip(matrixStack, mouseX, mouseY); this.renderTooltip(matrixStack, mouseX, mouseY);
} }
@Override @Override
protected void drawGuiContainerForegroundLayer(MatrixStack matrixStack, int mouseX, int mouseY) { protected void renderLabels(PoseStack matrixStack, int mouseX, int mouseY) {
this.font.func_243248_b(matrixStack, this.title, 8.0F, 6.0F, 4210752); 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 @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); 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 x = (this.width - this.imageWidth) / 2;
int y = (this.height - this.ySize) / 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);
} }
} }

View File

@ -1,8 +1,8 @@
package com.progwml6.ironchest.common.ai; package com.progwml6.ironchest.common.ai;
import net.minecraft.entity.ai.goal.CatSitOnBlockGoal; import net.minecraft.world.entity.ai.goal.CatSitOnBlockGoal;
import net.minecraft.entity.ai.goal.PrioritizedGoal; import net.minecraft.world.entity.ai.goal.WrappedGoal;
import net.minecraft.entity.passive.CatEntity; import net.minecraft.world.entity.animal.Cat;
import net.minecraftforge.event.entity.living.LivingEvent; import net.minecraftforge.event.entity.living.LivingEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent; import net.minecraftforge.eventbus.api.SubscribeEvent;
@ -12,18 +12,18 @@ public class CatsSitOnChestsHandler {
@SubscribeEvent @SubscribeEvent
public void changeSittingTaskForOcelots(final LivingEvent.LivingUpdateEvent evt) { public void changeSittingTaskForOcelots(final LivingEvent.LivingUpdateEvent evt) {
if (evt.getEntityLiving().ticksExisted < 5 && evt.getEntityLiving() instanceof CatEntity) { if (evt.getEntityLiving().tickCount < 5 && evt.getEntityLiving() instanceof Cat) {
HashSet<PrioritizedGoal> goals = new HashSet<>(); HashSet<WrappedGoal> 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) { if (goal.getGoal().getClass() == CatSitOnBlockGoal.class) {
goals.add(goal); goals.add(goal);
} }
} }
for (PrioritizedGoal goal : goals) { for (WrappedGoal goal : goals) {
catEntity.goalSelector.removeGoal(goal.getGoal()); catEntity.goalSelector.removeGoal(goal.getGoal());
catEntity.goalSelector.addGoal(goal.getPriority(), new IronChestCatSitOnBlockGoal(catEntity, 0.4F)); catEntity.goalSelector.addGoal(goal.getPriority(), new IronChestCatSitOnBlockGoal(catEntity, 0.4F));
} }

View File

@ -2,22 +2,22 @@ package com.progwml6.ironchest.common.ai;
import com.progwml6.ironchest.common.block.GenericIronChestBlock; import com.progwml6.ironchest.common.block.GenericIronChestBlock;
import com.progwml6.ironchest.common.block.tileentity.GenericIronChestTileEntity; import com.progwml6.ironchest.common.block.tileentity.GenericIronChestTileEntity;
import net.minecraft.block.Block; import net.minecraft.world.level.block.Block;
import net.minecraft.block.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.entity.ai.goal.CatSitOnBlockGoal; import net.minecraft.world.entity.ai.goal.CatSitOnBlockGoal;
import net.minecraft.entity.passive.CatEntity; import net.minecraft.world.entity.animal.Cat;
import net.minecraft.util.math.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.world.IWorldReader; import net.minecraft.world.level.LevelReader;
public class IronChestCatSitOnBlockGoal extends CatSitOnBlockGoal { 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_); super(catEntity, p_i50330_2_);
} }
@Override @Override
protected boolean shouldMoveTo(IWorldReader worldIn, BlockPos pos) { protected boolean isValidTarget(LevelReader worldIn, BlockPos pos) {
if (!worldIn.isAirBlock(pos.up())) { if (!worldIn.isEmptyBlock(pos.above())) {
return false; return false;
} }
else { else {
@ -28,7 +28,7 @@ public class IronChestCatSitOnBlockGoal extends CatSitOnBlockGoal {
return GenericIronChestTileEntity.getPlayersUsing(worldIn, pos) < 1; return GenericIronChestTileEntity.getPlayersUsing(worldIn, pos) < 1;
} }
return super.shouldMoveTo(worldIn, pos); return super.isValidTarget(worldIn, pos);
} }
} }
} }

View File

@ -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.CopperChestTileEntity;
import com.progwml6.ironchest.common.block.tileentity.IronChestsTileEntityTypes; import com.progwml6.ironchest.common.block.tileentity.IronChestsTileEntityTypes;
import net.minecraft.block.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.tileentity.TileEntity; import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.IBlockReader; import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.block.state.BlockBehaviour.Properties;
public class CopperChestBlock extends GenericIronChestBlock { public class CopperChestBlock extends GenericIronChestBlock {
@ -13,7 +15,7 @@ public class CopperChestBlock extends GenericIronChestBlock {
} }
@Override @Override
public TileEntity createTileEntity(BlockState state, IBlockReader world) { public BlockEntity createTileEntity(BlockState state, BlockGetter world) {
return new CopperChestTileEntity(); return new CopperChestTileEntity();
} }
} }

View File

@ -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.CrystalChestTileEntity;
import com.progwml6.ironchest.common.block.tileentity.IronChestsTileEntityTypes; import com.progwml6.ironchest.common.block.tileentity.IronChestsTileEntityTypes;
import net.minecraft.block.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.tileentity.TileEntity; import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.IBlockReader; import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.block.state.BlockBehaviour.Properties;
public class CrystalChestBlock extends GenericIronChestBlock { public class CrystalChestBlock extends GenericIronChestBlock {
@ -14,7 +16,7 @@ public class CrystalChestBlock extends GenericIronChestBlock {
@Override @Override
public TileEntity createTileEntity(BlockState state, IBlockReader world) { public BlockEntity createTileEntity(BlockState state, BlockGetter world) {
return new CrystalChestTileEntity(); return new CrystalChestTileEntity();
} }
} }

View File

@ -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.DiamondChestTileEntity;
import com.progwml6.ironchest.common.block.tileentity.IronChestsTileEntityTypes; import com.progwml6.ironchest.common.block.tileentity.IronChestsTileEntityTypes;
import net.minecraft.block.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.tileentity.TileEntity; import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.IBlockReader; import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.block.state.BlockBehaviour.Properties;
public class DiamondChestBlock extends GenericIronChestBlock { public class DiamondChestBlock extends GenericIronChestBlock {
@ -13,7 +15,7 @@ public class DiamondChestBlock extends GenericIronChestBlock {
} }
@Override @Override
public TileEntity createTileEntity(BlockState state, IBlockReader world) { public BlockEntity createTileEntity(BlockState state, BlockGetter world) {
return new DiamondChestTileEntity(); return new DiamondChestTileEntity();
} }
} }

View File

@ -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.DirtChestTileEntity;
import com.progwml6.ironchest.common.block.tileentity.IronChestsTileEntityTypes; import com.progwml6.ironchest.common.block.tileentity.IronChestsTileEntityTypes;
import com.progwml6.ironchest.common.block.tileentity.ObsidianChestTileEntity; import com.progwml6.ironchest.common.block.tileentity.ObsidianChestTileEntity;
import net.minecraft.block.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.tileentity.TileEntity; import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.IBlockReader; import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.block.state.BlockBehaviour.Properties;
public class DirtChestBlock extends GenericIronChestBlock { public class DirtChestBlock extends GenericIronChestBlock {
@ -14,7 +16,7 @@ public class DirtChestBlock extends GenericIronChestBlock {
} }
@Override @Override
public TileEntity createTileEntity(BlockState state, IBlockReader world) { public BlockEntity createTileEntity(BlockState state, BlockGetter world) {
return new DirtChestTileEntity(); return new DirtChestTileEntity();
} }
} }

View File

@ -2,48 +2,48 @@ package com.progwml6.ironchest.common.block;
import com.progwml6.ironchest.common.block.tileentity.GenericIronChestTileEntity; import com.progwml6.ironchest.common.block.tileentity.GenericIronChestTileEntity;
import it.unimi.dsi.fastutil.floats.Float2FloatFunction; import it.unimi.dsi.fastutil.floats.Float2FloatFunction;
import net.minecraft.block.Block; import net.minecraft.world.level.block.Block;
import net.minecraft.block.BlockRenderType; import net.minecraft.world.level.block.RenderShape;
import net.minecraft.block.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.block.HorizontalBlock; import net.minecraft.world.level.block.HorizontalDirectionalBlock;
import net.minecraft.block.IWaterLoggable; import net.minecraft.world.level.block.SimpleWaterloggedBlock;
import net.minecraft.entity.LivingEntity; import net.minecraft.world.entity.LivingEntity;
import net.minecraft.entity.passive.CatEntity; import net.minecraft.world.entity.animal.Cat;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.world.entity.player.Player;
import net.minecraft.fluid.Fluids; import net.minecraft.world.level.material.Fluids;
import net.minecraft.fluid.FluidState; import net.minecraft.world.level.material.FluidState;
import net.minecraft.inventory.IInventory; import net.minecraft.world.Container;
import net.minecraft.inventory.InventoryHelper; import net.minecraft.world.Containers;
import net.minecraft.inventory.container.Container; import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.inventory.container.INamedContainerProvider; import net.minecraft.world.MenuProvider;
import net.minecraft.item.BlockItemUseContext; import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.item.Item; import net.minecraft.world.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.pathfinding.PathType; import net.minecraft.world.level.pathfinder.PathComputationType;
import net.minecraft.state.BooleanProperty; import net.minecraft.world.level.block.state.properties.BooleanProperty;
import net.minecraft.state.DirectionProperty; import net.minecraft.world.level.block.state.properties.DirectionProperty;
import net.minecraft.state.StateContainer; import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.state.properties.BlockStateProperties; import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.stats.Stat; import net.minecraft.stats.Stat;
import net.minecraft.stats.Stats; import net.minecraft.stats.Stats;
import net.minecraft.tileentity.IChestLid; import net.minecraft.world.level.block.entity.LidBlockEntity;
import net.minecraft.tileentity.TileEntity; import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.tileentity.TileEntityMerger; import net.minecraft.world.level.block.DoubleBlockCombiner;
import net.minecraft.tileentity.TileEntityType; import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.util.ActionResultType; import net.minecraft.world.InteractionResult;
import net.minecraft.util.Direction; import net.minecraft.core.Direction;
import net.minecraft.util.Hand; import net.minecraft.world.InteractionHand;
import net.minecraft.util.Mirror; import net.minecraft.world.level.block.Mirror;
import net.minecraft.util.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.Rotation; import net.minecraft.world.level.block.Rotation;
import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.world.phys.AABB;
import net.minecraft.util.math.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.util.math.BlockRayTraceResult; import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.util.math.shapes.ISelectionContext; import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.util.math.shapes.VoxelShape; import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraft.world.IBlockReader; import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.IWorld; import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.World; import net.minecraft.world.level.Level;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.api.distmarker.OnlyIn;
@ -52,97 +52,99 @@ import java.util.List;
import java.util.function.BiPredicate; import java.util.function.BiPredicate;
import java.util.function.Supplier; 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; 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 IronChestsTypes type;
private final Supplier<TileEntityType<? extends GenericIronChestTileEntity>> tileEntityTypeSupplier; private final Supplier<BlockEntityType<? extends GenericIronChestTileEntity>> tileEntityTypeSupplier;
public GenericIronChestBlock(IronChestsTypes typeIn, Supplier<TileEntityType<? extends GenericIronChestTileEntity>> tileEntityTypeSupplierIn, Properties propertiesIn) { public GenericIronChestBlock(IronChestsTypes typeIn, Supplier<BlockEntityType<? extends GenericIronChestTileEntity>> tileEntityTypeSupplierIn, Properties propertiesIn) {
super(propertiesIn); super(propertiesIn);
this.type = typeIn; this.type = typeIn;
this.tileEntityTypeSupplier = tileEntityTypeSupplierIn; 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 @Override
public BlockRenderType getRenderType(BlockState state) { public RenderShape getRenderShape(BlockState state) {
return BlockRenderType.ENTITYBLOCK_ANIMATED; return RenderShape.ENTITYBLOCK_ANIMATED;
} }
@Override @Override
public BlockState updatePostPlacement(BlockState stateIn, Direction facing, BlockState facingState, IWorld worldIn, BlockPos currentPos, BlockPos facingPos) { public BlockState updateShape(BlockState stateIn, Direction facing, BlockState facingState, LevelAccessor worldIn, BlockPos currentPos, BlockPos facingPos) {
if (stateIn.get(WATERLOGGED)) { if (stateIn.getValue(WATERLOGGED)) {
worldIn.getPendingFluidTicks().scheduleTick(currentPos, Fluids.WATER, Fluids.WATER.getTickRate(worldIn)); 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 @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; return IRON_CHEST_SHAPE;
} }
@Override @Override
public BlockState getStateForPlacement(BlockItemUseContext context) { public BlockState getStateForPlacement(BlockPlaceContext context) {
Direction direction = context.getPlacementHorizontalFacing().getOpposite(); Direction direction = context.getHorizontalDirection().getOpposite();
FluidState ifluidstate = context.getWorld().getFluidState(context.getPos()); 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 @Override
public FluidState getFluidState(BlockState state) { 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 @Override
public void onBlockPlacedBy(World worldIn, BlockPos pos, BlockState state, LivingEntity placer, ItemStack stack) { public void setPlacedBy(Level worldIn, BlockPos pos, BlockState state, LivingEntity placer, ItemStack stack) {
TileEntity tileentity = worldIn.getTileEntity(pos); BlockEntity tileentity = worldIn.getBlockEntity(pos);
if (tileentity instanceof GenericIronChestTileEntity) { if (tileentity instanceof GenericIronChestTileEntity) {
((GenericIronChestTileEntity) tileentity).wasPlaced(placer, stack); ((GenericIronChestTileEntity) tileentity).wasPlaced(placer, stack);
if (stack.hasDisplayName()) { if (stack.hasCustomHoverName()) {
((GenericIronChestTileEntity) tileentity).setCustomName(stack.getDisplayName()); ((GenericIronChestTileEntity) tileentity).setCustomName(stack.getHoverName());
} }
} }
} }
@Override @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()) { if (state.getBlock() != newState.getBlock()) {
TileEntity tileentity = worldIn.getTileEntity(pos); BlockEntity tileentity = worldIn.getBlockEntity(pos);
if (tileentity instanceof GenericIronChestTileEntity) { if (tileentity instanceof GenericIronChestTileEntity) {
((GenericIronChestTileEntity) tileentity).removeAdornments(); ((GenericIronChestTileEntity) tileentity).removeAdornments();
InventoryHelper.dropInventoryItems(worldIn, pos, (GenericIronChestTileEntity) tileentity); Containers.dropContents(worldIn, pos, (GenericIronChestTileEntity) tileentity);
worldIn.updateComparatorOutputLevel(pos, this); worldIn.updateNeighbourForOutputSignal(pos, this);
} }
super.onReplaced(state, worldIn, pos, newState, isMoving); super.onRemove(state, worldIn, pos, newState, isMoving);
} }
} }
@Override @Override
public ActionResultType onBlockActivated(BlockState state, World worldIn, BlockPos pos, PlayerEntity player, Hand handIn, BlockRayTraceResult hit) { public InteractionResult use(BlockState state, Level worldIn, BlockPos pos, Player player, InteractionHand handIn, BlockHitResult hit) {
if (!worldIn.isRemote) { if (!worldIn.isClientSide) {
INamedContainerProvider inamedcontainerprovider = this.getContainer(state, worldIn, pos); MenuProvider inamedcontainerprovider = this.getMenuProvider(state, worldIn, pos);
if (inamedcontainerprovider != null) { if (inamedcontainerprovider != null) {
player.openContainer(inamedcontainerprovider); player.openMenu(inamedcontainerprovider);
player.addStat(this.getOpenStat()); player.awardStat(this.getOpenStat());
} }
} }
return ActionResultType.SUCCESS; return InteractionResult.SUCCESS;
} }
protected Stat<ResourceLocation> getOpenStat() { protected Stat<ResourceLocation> getOpenStat() {
@ -151,9 +153,9 @@ public class GenericIronChestBlock extends Block implements IWaterLoggable {
@Override @Override
@Nullable @Nullable
public INamedContainerProvider getContainer(BlockState state, World world, BlockPos pos) { public MenuProvider getMenuProvider(BlockState state, Level world, BlockPos pos) {
TileEntity tileentity = world.getTileEntity(pos); BlockEntity tileentity = world.getBlockEntity(pos);
return tileentity instanceof INamedContainerProvider ? (INamedContainerProvider) tileentity : null; return tileentity instanceof MenuProvider ? (MenuProvider) tileentity : null;
} }
@Override @Override
@ -162,25 +164,25 @@ public class GenericIronChestBlock extends Block implements IWaterLoggable {
} }
@Override @Override
public boolean eventReceived(BlockState state, World worldIn, BlockPos pos, int id, int param) { public boolean triggerEvent(BlockState state, Level worldIn, BlockPos pos, int id, int param) {
super.eventReceived(state, worldIn, pos, id, param); super.triggerEvent(state, worldIn, pos, id, param);
TileEntity tileentity = worldIn.getTileEntity(pos); BlockEntity tileentity = worldIn.getBlockEntity(pos);
return tileentity == null ? false : tileentity.receiveClientEvent(id, param); 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); return isBelowSolidBlock(iWorld, blockPos) || isCatSittingOn(iWorld, blockPos);
} }
private static boolean isBelowSolidBlock(IBlockReader iBlockReader, BlockPos worldIn) { private static boolean isBelowSolidBlock(BlockGetter iBlockReader, BlockPos worldIn) {
BlockPos blockpos = worldIn.up(); BlockPos blockpos = worldIn.above();
return iBlockReader.getBlockState(blockpos).isNormalCube(iBlockReader, blockpos); return iBlockReader.getBlockState(blockpos).isRedstoneConductor(iBlockReader, blockpos);
} }
private static boolean isCatSittingOn(IWorld iWorld, BlockPos blockPos) { private static boolean isCatSittingOn(LevelAccessor iWorld, BlockPos blockPos) {
List<CatEntity> 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))); List<Cat> 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()) { if (!list.isEmpty()) {
for (CatEntity catentity : list) { for (Cat catentity : list) {
if (catentity.isSleeping()) { if (catentity.isSleeping()) {
return true; return true;
} }
@ -191,37 +193,37 @@ public class GenericIronChestBlock extends Block implements IWaterLoggable {
} }
@Override @Override
public boolean hasComparatorInputOverride(BlockState state) { public boolean hasAnalogOutputSignal(BlockState state) {
return true; return true;
} }
@Override @Override
public int getComparatorInputOverride(BlockState blockState, World worldIn, BlockPos pos) { public int getAnalogOutputSignal(BlockState blockState, Level worldIn, BlockPos pos) {
return Container.calcRedstoneFromInventory((IInventory) worldIn.getTileEntity(pos)); return AbstractContainerMenu.getRedstoneSignalFromContainer((Container) worldIn.getBlockEntity(pos));
} }
@Override @Override
public BlockState rotate(BlockState state, Rotation rot) { 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 @Override
public BlockState mirror(BlockState state, Mirror mirrorIn) { public BlockState mirror(BlockState state, Mirror mirrorIn) {
return state.rotate(mirrorIn.toRotation(state.get(FACING))); return state.rotate(mirrorIn.getRotation(state.getValue(FACING)));
} }
@Override @Override
protected void fillStateContainer(StateContainer.Builder<Block, BlockState> builder) { protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
builder.add(FACING, WATERLOGGED); builder.add(FACING, WATERLOGGED);
} }
@Override @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; return false;
} }
public static IronChestsTypes getTypeFromItem(Item itemIn) { public static IronChestsTypes getTypeFromItem(Item itemIn) {
return getTypeFromBlock(Block.getBlockFromItem(itemIn)); return getTypeFromBlock(Block.byItem(itemIn));
} }
public static IronChestsTypes getTypeFromBlock(Block blockIn) { public static IronChestsTypes getTypeFromBlock(Block blockIn) {
@ -233,29 +235,29 @@ public class GenericIronChestBlock extends Block implements IWaterLoggable {
} }
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public static TileEntityMerger.ICallback<GenericIronChestTileEntity, Float2FloatFunction> getLid(final IChestLid p_226917_0_) { public static DoubleBlockCombiner.Combiner<GenericIronChestTileEntity, Float2FloatFunction> getLid(final LidBlockEntity p_226917_0_) {
return new TileEntityMerger.ICallback<GenericIronChestTileEntity, Float2FloatFunction>() { return new DoubleBlockCombiner.Combiner<GenericIronChestTileEntity, Float2FloatFunction>() {
@Override @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 (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 @Override
public Float2FloatFunction func_225538_a_(GenericIronChestTileEntity p_225538_1_) { public Float2FloatFunction acceptSingle(GenericIronChestTileEntity p_225538_1_) {
return p_225538_1_::getLidAngle; return p_225538_1_::getOpenNess;
} }
@Override @Override
public Float2FloatFunction func_225537_b_() { public Float2FloatFunction acceptNone() {
return p_226917_0_::getLidAngle; return p_226917_0_::getOpenNess;
} }
}; };
} }
public TileEntityMerger.ICallbackWrapper<? extends GenericIronChestTileEntity> getWrapper(BlockState blockState, World world, BlockPos blockPos, boolean p_225536_4_) { public DoubleBlockCombiner.NeighborCombineResult<? extends GenericIronChestTileEntity> getWrapper(BlockState blockState, Level world, BlockPos blockPos, boolean p_225536_4_) {
BiPredicate<IWorld, BlockPos> biPredicate; BiPredicate<LevelAccessor, BlockPos> biPredicate;
if (p_225536_4_) { if (p_225536_4_) {
biPredicate = (p_226918_0_, p_226918_1_) -> false; biPredicate = (p_226918_0_, p_226918_1_) -> false;
} }
@ -263,15 +265,15 @@ public class GenericIronChestBlock extends Block implements IWaterLoggable {
biPredicate = GenericIronChestBlock::isBlocked; 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) { public static DoubleBlockCombiner.BlockType getMergerType(BlockState blockState) {
return TileEntityMerger.Type.SINGLE; return DoubleBlockCombiner.BlockType.SINGLE;
} }
public static Direction getDirectionToAttached(BlockState state) { public static Direction getDirectionToAttached(BlockState state) {
Direction direction = state.get(FACING); Direction direction = state.getValue(FACING);
return direction.rotateYCCW(); return direction.getCounterClockWise();
} }
} }

View File

@ -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.GoldChestTileEntity;
import com.progwml6.ironchest.common.block.tileentity.IronChestsTileEntityTypes; import com.progwml6.ironchest.common.block.tileentity.IronChestsTileEntityTypes;
import net.minecraft.block.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.tileentity.TileEntity; import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.IBlockReader; import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.block.state.BlockBehaviour.Properties;
public class GoldChestBlock extends GenericIronChestBlock { public class GoldChestBlock extends GenericIronChestBlock {
@ -13,7 +15,7 @@ public class GoldChestBlock extends GenericIronChestBlock {
} }
@Override @Override
public TileEntity createTileEntity(BlockState state, IBlockReader world) { public BlockEntity createTileEntity(BlockState state, BlockGetter world) {
return new GoldChestTileEntity(); return new GoldChestTileEntity();
} }
} }

View File

@ -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.IronChestTileEntity;
import com.progwml6.ironchest.common.block.tileentity.IronChestsTileEntityTypes; import com.progwml6.ironchest.common.block.tileentity.IronChestsTileEntityTypes;
import net.minecraft.block.Block; import net.minecraft.world.level.block.Block;
import net.minecraft.block.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.tileentity.TileEntity; import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.IBlockReader; import net.minecraft.world.level.BlockGetter;
public class IronChestBlock extends GenericIronChestBlock { public class IronChestBlock extends GenericIronChestBlock {
@ -14,7 +14,7 @@ public class IronChestBlock extends GenericIronChestBlock {
} }
@Override @Override
public TileEntity createTileEntity(BlockState state, IBlockReader world) { public BlockEntity createTileEntity(BlockState state, BlockGetter world) {
return new IronChestTileEntity(); return new IronChestTileEntity();
} }
} }

View File

@ -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.ObsidianChestTileEntity;
import com.progwml6.ironchest.common.block.tileentity.SilverChestTileEntity; import com.progwml6.ironchest.common.block.tileentity.SilverChestTileEntity;
import com.progwml6.ironchest.common.item.IronChestsItems; import com.progwml6.ironchest.common.item.IronChestsItems;
import net.minecraft.block.Block; import net.minecraft.world.level.block.Block;
import net.minecraft.block.material.Material; import net.minecraft.world.level.material.Material;
import net.minecraft.client.renderer.tileentity.ItemStackTileEntityRenderer; import net.minecraft.client.renderer.BlockEntityWithoutLevelRenderer;
import net.minecraft.item.BlockItem; import net.minecraft.world.item.BlockItem;
import net.minecraft.item.Item; import net.minecraft.world.item.Item;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.fml.RegistryObject; import net.minecraftforge.fml.RegistryObject;
@ -32,38 +32,38 @@ public class IronChestsBlocks {
public static final DeferredRegister<Item> ITEMS = IronChestsItems.ITEMS; public static final DeferredRegister<Item> ITEMS = IronChestsItems.ITEMS;
public static final RegistryObject<IronChestBlock> IRON_CHEST = register( public static final RegistryObject<IronChestBlock> 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()); () -> ironChestRenderer());
public static final RegistryObject<GoldChestBlock> GOLD_CHEST = register( public static final RegistryObject<GoldChestBlock> 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()); () -> goldChestRenderer());
public static final RegistryObject<DiamondChestBlock> DIAMOND_CHEST = register( public static final RegistryObject<DiamondChestBlock> 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()); () -> diamondChestRenderer());
public static final RegistryObject<CopperChestBlock> COPPER_CHEST = register( public static final RegistryObject<CopperChestBlock> 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()); () -> copperChestRenderer());
public static final RegistryObject<SilverChestBlock> SILVER_CHEST = register( public static final RegistryObject<SilverChestBlock> 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()); () -> silverChestRenderer());
public static final RegistryObject<CrystalChestBlock> CRYSTAL_CHEST = register( public static final RegistryObject<CrystalChestBlock> 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()); () -> crystalChestRenderer());
public static final RegistryObject<ObsidianChestBlock> OBSIDIAN_CHEST = register( public static final RegistryObject<ObsidianChestBlock> 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()); () -> obsidianChestRenderer());
public static final RegistryObject<DirtChestBlock> DIRT_CHEST = register( public static final RegistryObject<DirtChestBlock> 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()); () -> dirtChestRenderer());
private static <T extends Block> RegistryObject<T> register(String name, Supplier<? extends T> sup, Supplier<Callable<ItemStackTileEntityRenderer>> renderMethod) { private static <T extends Block> RegistryObject<T> register(String name, Supplier<? extends T> sup, Supplier<Callable<BlockEntityWithoutLevelRenderer>> renderMethod) {
return register(name, sup, block -> item(block, renderMethod)); return register(name, sup, block -> item(block, renderMethod));
} }
@ -77,47 +77,47 @@ public class IronChestsBlocks {
return BLOCKS.register(name, sup); return BLOCKS.register(name, sup);
} }
private static Supplier<BlockItem> item(final RegistryObject<? extends Block> block, final Supplier<Callable<ItemStackTileEntityRenderer>> renderMethod) { private static Supplier<BlockItem> item(final RegistryObject<? extends Block> block, final Supplier<Callable<BlockEntityWithoutLevelRenderer>> renderMethod) {
return () -> new BlockItem(block.get(), new Item.Properties().group(IronChests.IRONCHESTS_ITEM_GROUP).setISTER(renderMethod)); return () -> new BlockItem(block.get(), new Item.Properties().tab(IronChests.IRONCHESTS_ITEM_GROUP).setISTER(renderMethod));
} }
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
private static Callable<ItemStackTileEntityRenderer> ironChestRenderer() { private static Callable<BlockEntityWithoutLevelRenderer> ironChestRenderer() {
return () -> new IronChestItemStackRenderer(IronChestTileEntity::new); return () -> new IronChestItemStackRenderer(IronChestTileEntity::new);
} }
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
private static Callable<ItemStackTileEntityRenderer> goldChestRenderer() { private static Callable<BlockEntityWithoutLevelRenderer> goldChestRenderer() {
return () -> new IronChestItemStackRenderer(GoldChestTileEntity::new); return () -> new IronChestItemStackRenderer(GoldChestTileEntity::new);
} }
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
private static Callable<ItemStackTileEntityRenderer> diamondChestRenderer() { private static Callable<BlockEntityWithoutLevelRenderer> diamondChestRenderer() {
return () -> new IronChestItemStackRenderer(DiamondChestTileEntity::new); return () -> new IronChestItemStackRenderer(DiamondChestTileEntity::new);
} }
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
private static Callable<ItemStackTileEntityRenderer> copperChestRenderer() { private static Callable<BlockEntityWithoutLevelRenderer> copperChestRenderer() {
return () -> new IronChestItemStackRenderer(CopperChestTileEntity::new); return () -> new IronChestItemStackRenderer(CopperChestTileEntity::new);
} }
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
private static Callable<ItemStackTileEntityRenderer> silverChestRenderer() { private static Callable<BlockEntityWithoutLevelRenderer> silverChestRenderer() {
return () -> new IronChestItemStackRenderer(SilverChestTileEntity::new); return () -> new IronChestItemStackRenderer(SilverChestTileEntity::new);
} }
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
private static Callable<ItemStackTileEntityRenderer> crystalChestRenderer() { private static Callable<BlockEntityWithoutLevelRenderer> crystalChestRenderer() {
return () -> new IronChestItemStackRenderer(CrystalChestTileEntity::new); return () -> new IronChestItemStackRenderer(CrystalChestTileEntity::new);
} }
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
private static Callable<ItemStackTileEntityRenderer> obsidianChestRenderer() { private static Callable<BlockEntityWithoutLevelRenderer> obsidianChestRenderer() {
return () -> new IronChestItemStackRenderer(ObsidianChestTileEntity::new); return () -> new IronChestItemStackRenderer(ObsidianChestTileEntity::new);
} }
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
private static Callable<ItemStackTileEntityRenderer> dirtChestRenderer() { private static Callable<BlockEntityWithoutLevelRenderer> dirtChestRenderer() {
return () -> new IronChestItemStackRenderer(DirtChestTileEntity::new); return () -> new IronChestItemStackRenderer(DirtChestTileEntity::new);
} }
} }

View File

@ -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.IronChestTileEntity;
import com.progwml6.ironchest.common.block.tileentity.ObsidianChestTileEntity; import com.progwml6.ironchest.common.block.tileentity.ObsidianChestTileEntity;
import com.progwml6.ironchest.common.block.tileentity.SilverChestTileEntity; import com.progwml6.ironchest.common.block.tileentity.SilverChestTileEntity;
import net.minecraft.block.Block; import net.minecraft.world.level.block.Block;
import net.minecraft.block.Blocks; import net.minecraft.world.level.block.Blocks;
import net.minecraft.util.IStringSerializable; import net.minecraft.util.StringRepresentable;
import net.minecraft.util.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import java.util.Locale; 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), 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), 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 @Override
public String getString() { public String getSerializedName() {
return this.getEnglishName(); return this.getEnglishName();
} }

View File

@ -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.IronChestsTileEntityTypes;
import com.progwml6.ironchest.common.block.tileentity.ObsidianChestTileEntity; import com.progwml6.ironchest.common.block.tileentity.ObsidianChestTileEntity;
import com.progwml6.ironchest.common.block.tileentity.SilverChestTileEntity; import com.progwml6.ironchest.common.block.tileentity.SilverChestTileEntity;
import net.minecraft.block.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.tileentity.TileEntity; import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.IBlockReader; import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.block.state.BlockBehaviour.Properties;
public class ObsidianChestBlock extends GenericIronChestBlock { public class ObsidianChestBlock extends GenericIronChestBlock {
@ -14,7 +16,7 @@ public class ObsidianChestBlock extends GenericIronChestBlock {
} }
@Override @Override
public TileEntity createTileEntity(BlockState state, IBlockReader world) { public BlockEntity createTileEntity(BlockState state, BlockGetter world) {
return new ObsidianChestTileEntity(); return new ObsidianChestTileEntity();
} }
} }

View File

@ -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.CopperChestTileEntity;
import com.progwml6.ironchest.common.block.tileentity.IronChestsTileEntityTypes; import com.progwml6.ironchest.common.block.tileentity.IronChestsTileEntityTypes;
import com.progwml6.ironchest.common.block.tileentity.SilverChestTileEntity; import com.progwml6.ironchest.common.block.tileentity.SilverChestTileEntity;
import net.minecraft.block.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.tileentity.TileEntity; import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.IBlockReader; import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.block.state.BlockBehaviour.Properties;
public class SilverChestBlock extends GenericIronChestBlock { public class SilverChestBlock extends GenericIronChestBlock {
@ -14,7 +16,7 @@ public class SilverChestBlock extends GenericIronChestBlock {
} }
@Override @Override
public TileEntity createTileEntity(BlockState state, IBlockReader world) { public BlockEntity createTileEntity(BlockState state, BlockGetter world) {
return new SilverChestTileEntity(); return new SilverChestTileEntity();
} }
} }

View File

@ -3,8 +3,8 @@ package com.progwml6.ironchest.common.block.tileentity;
import com.progwml6.ironchest.common.block.IronChestsBlocks; import com.progwml6.ironchest.common.block.IronChestsBlocks;
import com.progwml6.ironchest.common.block.IronChestsTypes; import com.progwml6.ironchest.common.block.IronChestsTypes;
import com.progwml6.ironchest.common.inventory.IronChestContainer; import com.progwml6.ironchest.common.inventory.IronChestContainer;
import net.minecraft.entity.player.PlayerInventory; import net.minecraft.world.entity.player.Inventory;
import net.minecraft.inventory.container.Container; import net.minecraft.world.inventory.AbstractContainerMenu;
public class CopperChestTileEntity extends GenericIronChestTileEntity { public class CopperChestTileEntity extends GenericIronChestTileEntity {
@ -13,7 +13,7 @@ public class CopperChestTileEntity extends GenericIronChestTileEntity {
} }
@Override @Override
protected Container createMenu(int id, PlayerInventory playerInventory) { protected AbstractContainerMenu createMenu(int id, Inventory playerInventory) {
return IronChestContainer.createCopperContainer(id, playerInventory, this); return IronChestContainer.createCopperContainer(id, playerInventory, this);
} }
} }

View File

@ -5,12 +5,12 @@ import com.progwml6.ironchest.common.block.IronChestsTypes;
import com.progwml6.ironchest.common.inventory.IronChestContainer; import com.progwml6.ironchest.common.inventory.IronChestContainer;
import com.progwml6.ironchest.common.network.InventoryTopStacksSyncPacket; import com.progwml6.ironchest.common.network.InventoryTopStacksSyncPacket;
import com.progwml6.ironchest.common.network.IronChestNetwork; import com.progwml6.ironchest.common.network.IronChestNetwork;
import net.minecraft.block.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.entity.player.PlayerInventory; import net.minecraft.world.entity.player.Inventory;
import net.minecraft.inventory.container.Container; import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.util.NonNullList; import net.minecraft.core.NonNullList;
import net.minecraft.world.server.ServerWorld; import net.minecraft.server.level.ServerLevel;
import net.minecraftforge.fml.network.PacketDistributor; import net.minecraftforge.fml.network.PacketDistributor;
import java.util.Collections; import java.util.Collections;
@ -29,7 +29,7 @@ public class CrystalChestTileEntity extends GenericIronChestTileEntity {
} }
@Override @Override
protected Container createMenu(int id, PlayerInventory playerInventory) { protected AbstractContainerMenu createMenu(int id, Inventory playerInventory) {
return IronChestContainer.createCrystalContainer(id, playerInventory, this); return IronChestContainer.createCrystalContainer(id, playerInventory, this);
} }
@ -37,7 +37,7 @@ public class CrystalChestTileEntity extends GenericIronChestTileEntity {
public void tick() { public void tick() {
super.tick(); super.tick();
if (!this.world.isRemote && this.inventoryTouched) { if (!this.level.isClientSide && this.inventoryTouched) {
this.inventoryTouched = false; this.inventoryTouched = false;
this.sortTopStacks(); this.sortTopStacks();
@ -52,10 +52,10 @@ public class CrystalChestTileEntity extends GenericIronChestTileEntity {
} }
@Override @Override
public ItemStack getStackInSlot(int index) { public ItemStack getItem(int index) {
this.inventoryTouched = true; this.inventoryTouched = true;
return super.getStackInSlot(index); return super.getItem(index);
} }
public NonNullList<ItemStack> getTopItems() { public NonNullList<ItemStack> getTopItems() {
@ -63,25 +63,25 @@ public class CrystalChestTileEntity extends GenericIronChestTileEntity {
} }
private void sortTopStacks() { private void sortTopStacks() {
if (!this.getChestType().isTransparent() || (this.world != null && this.world.isRemote)) { if (!this.getChestType().isTransparent() || (this.level != null && this.level.isClientSide)) {
return; return;
} }
NonNullList<ItemStack> tempCopy = NonNullList.<ItemStack>withSize(this.getSizeInventory(), ItemStack.EMPTY); NonNullList<ItemStack> tempCopy = NonNullList.<ItemStack>withSize(this.getContainerSize(), ItemStack.EMPTY);
boolean hasStuff = false; boolean hasStuff = false;
int compressedIdx = 0; int compressedIdx = 0;
mainLoop: mainLoop:
for (int i = 0; i < this.getSizeInventory(); i++) { for (int i = 0; i < this.getContainerSize(); i++) {
ItemStack itemStack = this.getItems().get(i); ItemStack itemStack = this.getItems().get(i);
if (!itemStack.isEmpty()) { if (!itemStack.isEmpty()) {
for (int j = 0; j < compressedIdx; j++) { for (int j = 0; j < compressedIdx; j++) {
ItemStack tempCopyStack = tempCopy.get(j); ItemStack tempCopyStack = tempCopy.get(j);
if (ItemStack.areItemsEqualIgnoreDurability(tempCopyStack, itemStack)) { if (ItemStack.isSameIgnoreDurability(tempCopyStack, itemStack)) {
if (itemStack.getCount() != tempCopyStack.getCount()) { if (itemStack.getCount() != tempCopyStack.getCount()) {
tempCopyStack.grow(itemStack.getCount()); tempCopyStack.grow(itemStack.getCount());
} }
@ -105,10 +105,10 @@ public class CrystalChestTileEntity extends GenericIronChestTileEntity {
this.getTopItems().set(i, ItemStack.EMPTY); this.getTopItems().set(i, ItemStack.EMPTY);
} }
if (this.world != null) { if (this.level != null) {
BlockState iblockstate = this.world.getBlockState(this.pos); BlockState iblockstate = this.level.getBlockState(this.worldPosition);
this.world.notifyBlockUpdate(this.pos, iblockstate, iblockstate, 3); this.level.sendBlockUpdated(this.worldPosition, iblockstate, iblockstate, 3);
} }
return; return;
@ -146,10 +146,10 @@ public class CrystalChestTileEntity extends GenericIronChestTileEntity {
this.getTopItems().set(i, ItemStack.EMPTY); this.getTopItems().set(i, ItemStack.EMPTY);
} }
if (this.world != null) { if (this.level != null) {
BlockState iblockstate = this.world.getBlockState(this.pos); BlockState iblockstate = this.level.getBlockState(this.worldPosition);
this.world.notifyBlockUpdate(this.pos, iblockstate, iblockstate, 3); this.level.sendBlockUpdated(this.worldPosition, iblockstate, iblockstate, 3);
} }
sendTopStacksPacket(); sendTopStacksPacket();
@ -181,8 +181,8 @@ public class CrystalChestTileEntity extends GenericIronChestTileEntity {
protected void sendTopStacksPacket() { protected void sendTopStacksPacket() {
NonNullList<ItemStack> stacks = this.buildItemStackDataList(); NonNullList<ItemStack> stacks = this.buildItemStackDataList();
if (this.world != null && this.world instanceof ServerWorld && !this.world.isRemote) { if (this.level != null && this.level instanceof ServerLevel && !this.level.isClientSide) {
IronChestNetwork.getInstance().sendToClientsAround(new InventoryTopStacksSyncPacket(stacks, this.pos), (ServerWorld) this.world, this.pos); IronChestNetwork.getInstance().sendToClientsAround(new InventoryTopStacksSyncPacket(stacks, this.worldPosition), (ServerLevel) this.level, this.worldPosition);
} }
} }

View File

@ -3,8 +3,8 @@ package com.progwml6.ironchest.common.block.tileentity;
import com.progwml6.ironchest.common.block.IronChestsBlocks; import com.progwml6.ironchest.common.block.IronChestsBlocks;
import com.progwml6.ironchest.common.block.IronChestsTypes; import com.progwml6.ironchest.common.block.IronChestsTypes;
import com.progwml6.ironchest.common.inventory.IronChestContainer; import com.progwml6.ironchest.common.inventory.IronChestContainer;
import net.minecraft.entity.player.PlayerInventory; import net.minecraft.world.entity.player.Inventory;
import net.minecraft.inventory.container.Container; import net.minecraft.world.inventory.AbstractContainerMenu;
public class DiamondChestTileEntity extends GenericIronChestTileEntity { public class DiamondChestTileEntity extends GenericIronChestTileEntity {
@ -13,7 +13,7 @@ public class DiamondChestTileEntity extends GenericIronChestTileEntity {
} }
@Override @Override
protected Container createMenu(int id, PlayerInventory playerInventory) { protected AbstractContainerMenu createMenu(int id, Inventory playerInventory) {
return IronChestContainer.createDiamondContainer(id, playerInventory, this); return IronChestContainer.createDiamondContainer(id, playerInventory, this);
} }
} }

View File

@ -3,16 +3,16 @@ package com.progwml6.ironchest.common.block.tileentity;
import com.progwml6.ironchest.common.block.IronChestsBlocks; import com.progwml6.ironchest.common.block.IronChestsBlocks;
import com.progwml6.ironchest.common.block.IronChestsTypes; import com.progwml6.ironchest.common.block.IronChestsTypes;
import com.progwml6.ironchest.common.inventory.IronChestContainer; import com.progwml6.ironchest.common.inventory.IronChestContainer;
import net.minecraft.client.resources.I18n; import net.minecraft.client.resources.language.I18n;
import net.minecraft.entity.LivingEntity; import net.minecraft.world.entity.LivingEntity;
import net.minecraft.entity.player.PlayerInventory; import net.minecraft.world.entity.player.Inventory;
import net.minecraft.inventory.container.Container; import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.item.Items; import net.minecraft.world.item.Items;
import net.minecraft.nbt.ListNBT; import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.StringNBT; import net.minecraft.nbt.StringTag;
import net.minecraft.util.text.ITextComponent; import net.minecraft.network.chat.Component;
import net.minecraft.util.text.TranslationTextComponent; import net.minecraft.network.chat.TranslatableComponent;
public class DirtChestTileEntity extends GenericIronChestTileEntity { public class DirtChestTileEntity extends GenericIronChestTileEntity {
@ -29,7 +29,7 @@ public class DirtChestTileEntity extends GenericIronChestTileEntity {
} }
@Override @Override
protected Container createMenu(int id, PlayerInventory playerInventory) { protected AbstractContainerMenu createMenu(int id, Inventory playerInventory) {
return IronChestContainer.createDirtContainer(id, playerInventory, this); return IronChestContainer.createDirtContainer(id, playerInventory, this);
} }
@ -47,24 +47,24 @@ public class DirtChestTileEntity extends GenericIronChestTileEntity {
@Override @Override
public void removeAdornments() { 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); this.getItems().set(0, ItemStack.EMPTY);
} }
} }
private static void createBookData() { 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(); ListTag pages = new ListTag();
pages.add(StringNBT.valueOf(ITextComponent.Serializer.toJson(new TranslationTextComponent("book.ironchest.dirtchest9000.page1")))); pages.add(StringTag.valueOf(Component.Serializer.toJson(new TranslatableComponent("book.ironchest.dirtchest9000.page1"))));
pages.add(StringNBT.valueOf(ITextComponent.Serializer.toJson(new TranslationTextComponent("book.ironchest.dirtchest9000.page2")))); pages.add(StringTag.valueOf(Component.Serializer.toJson(new TranslatableComponent("book.ironchest.dirtchest9000.page2"))));
pages.add(StringNBT.valueOf(ITextComponent.Serializer.toJson(new TranslationTextComponent("book.ironchest.dirtchest9000.page3")))); pages.add(StringTag.valueOf(Component.Serializer.toJson(new TranslatableComponent("book.ironchest.dirtchest9000.page3"))));
pages.add(StringNBT.valueOf(ITextComponent.Serializer.toJson(new TranslationTextComponent("book.ironchest.dirtchest9000.page4")))); pages.add(StringTag.valueOf(Component.Serializer.toJson(new TranslatableComponent("book.ironchest.dirtchest9000.page4"))));
pages.add(StringNBT.valueOf(ITextComponent.Serializer.toJson(new TranslationTextComponent("book.ironchest.dirtchest9000.page5")))); pages.add(StringTag.valueOf(Component.Serializer.toJson(new TranslatableComponent("book.ironchest.dirtchest9000.page5"))));
dirtChest9000GuideBook.setTagInfo("pages", pages); dirtChest9000GuideBook.addTagElement("pages", pages);
bookDataCreated = true; bookDataCreated = true;
} }

View File

@ -4,39 +4,39 @@ import com.progwml6.ironchest.IronChests;
import com.progwml6.ironchest.common.block.GenericIronChestBlock; import com.progwml6.ironchest.common.block.GenericIronChestBlock;
import com.progwml6.ironchest.common.block.IronChestsTypes; import com.progwml6.ironchest.common.block.IronChestsTypes;
import com.progwml6.ironchest.common.inventory.IronChestContainer; import com.progwml6.ironchest.common.inventory.IronChestContainer;
import net.minecraft.block.Block; import net.minecraft.world.level.block.Block;
import net.minecraft.block.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.entity.LivingEntity; import net.minecraft.world.entity.LivingEntity;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.world.entity.player.Player;
import net.minecraft.entity.player.PlayerInventory; import net.minecraft.world.entity.player.Inventory;
import net.minecraft.inventory.ItemStackHelper; import net.minecraft.world.ContainerHelper;
import net.minecraft.inventory.container.Container; import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.nbt.CompoundNBT; import net.minecraft.nbt.CompoundTag;
import net.minecraft.tileentity.IChestLid; import net.minecraft.world.level.block.entity.LidBlockEntity;
import net.minecraft.tileentity.ITickableTileEntity; import net.minecraft.world.level.block.entity.TickableBlockEntity;
import net.minecraft.tileentity.LockableLootTileEntity; import net.minecraft.world.level.block.entity.RandomizableContainerBlockEntity;
import net.minecraft.tileentity.LockableTileEntity; import net.minecraft.world.level.block.entity.BaseContainerBlockEntity;
import net.minecraft.tileentity.TileEntity; import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.tileentity.TileEntityType; import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.util.NonNullList; import net.minecraft.core.NonNullList;
import net.minecraft.util.SoundCategory; import net.minecraft.sounds.SoundSource;
import net.minecraft.util.SoundEvent; import net.minecraft.sounds.SoundEvent;
import net.minecraft.util.SoundEvents; import net.minecraft.sounds.SoundEvents;
import net.minecraft.util.math.AxisAlignedBB; import net.minecraft.world.phys.AABB;
import net.minecraft.util.math.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.Mth;
import net.minecraft.util.text.ITextComponent; import net.minecraft.network.chat.Component;
import net.minecraft.util.text.TranslationTextComponent; import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.world.IBlockReader; import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.World; import net.minecraft.world.level.Level;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn; import net.minecraftforge.api.distmarker.OnlyIn;
import java.util.function.Supplier; import java.util.function.Supplier;
@OnlyIn(value = Dist.CLIENT, _interface = IChestLid.class) @OnlyIn(value = Dist.CLIENT, _interface = LidBlockEntity.class)
public class GenericIronChestTileEntity extends LockableLootTileEntity implements IChestLid, ITickableTileEntity { public class GenericIronChestTileEntity extends RandomizableContainerBlockEntity implements LidBlockEntity, TickableBlockEntity {
private NonNullList<ItemStack> chestContents; private NonNullList<ItemStack> chestContents;
protected float lidAngle; protected float lidAngle;
@ -46,7 +46,7 @@ public class GenericIronChestTileEntity extends LockableLootTileEntity implement
private IronChestsTypes chestType; private IronChestsTypes chestType;
private Supplier<Block> blockToUse; private Supplier<Block> blockToUse;
protected GenericIronChestTileEntity(TileEntityType<?> typeIn, IronChestsTypes chestTypeIn, Supplier<Block> blockToUseIn) { protected GenericIronChestTileEntity(BlockEntityType<?> typeIn, IronChestsTypes chestTypeIn, Supplier<Block> blockToUseIn) {
super(typeIn); super(typeIn);
this.chestContents = NonNullList.<ItemStack>withSize(chestTypeIn.size, ItemStack.EMPTY); this.chestContents = NonNullList.<ItemStack>withSize(chestTypeIn.size, ItemStack.EMPTY);
@ -55,7 +55,7 @@ public class GenericIronChestTileEntity extends LockableLootTileEntity implement
} }
@Override @Override
public int getSizeInventory() { public int getContainerSize() {
return this.getItems().size(); return this.getItems().size();
} }
@ -71,27 +71,27 @@ public class GenericIronChestTileEntity extends LockableLootTileEntity implement
} }
@Override @Override
protected ITextComponent getDefaultName() { protected Component getDefaultName() {
return new TranslationTextComponent(IronChests.MODID + ".container." + this.chestType.getId() + "_chest"); return new TranslatableComponent(IronChests.MODID + ".container." + this.chestType.getId() + "_chest");
} }
@Override @Override
public void read(BlockState state, CompoundNBT compound) { public void load(BlockState state, CompoundTag compound) {
super.read(state, 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)) { if (!this.tryLoadLootTable(compound)) {
ItemStackHelper.loadAllItems(compound, this.chestContents); ContainerHelper.loadAllItems(compound, this.chestContents);
} }
} }
@Override @Override
public CompoundNBT write(CompoundNBT compound) { public CompoundTag save(CompoundTag compound) {
super.write(compound); super.save(compound);
if (!this.checkLootAndWrite(compound)) { if (!this.trySaveLootTable(compound)) {
ItemStackHelper.saveAllItems(compound, this.chestContents); ContainerHelper.saveAllItems(compound, this.chestContents);
} }
return compound; return compound;
@ -99,15 +99,15 @@ public class GenericIronChestTileEntity extends LockableLootTileEntity implement
@Override @Override
public void tick() { public void tick() {
int i = this.pos.getX(); int i = this.worldPosition.getX();
int j = this.pos.getY(); int j = this.worldPosition.getY();
int k = this.pos.getZ(); int k = this.worldPosition.getZ();
++this.ticksSinceSync; ++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; this.prevLidAngle = this.lidAngle;
float f = 0.1F; float f = 0.1F;
if (this.numPlayersUsing > 0 && this.lidAngle == 0.0F) { 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) { 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; float f2 = 0.5F;
if (this.lidAngle < 0.5F && f1 >= 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) { 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) { public static int getNumberOfPlayersUsing(Level worldIn, BaseContainerBlockEntity lockableTileEntity, int ticksSinceSync, int x, int y, int z, int numPlayersUsing) {
if (!worldIn.isRemote && numPlayersUsing != 0 && (ticksSinceSync + x + y + z) % 200 == 0) { if (!worldIn.isClientSide && numPlayersUsing != 0 && (ticksSinceSync + x + y + z) % 200 == 0) {
numPlayersUsing = getNumberOfPlayersUsing(worldIn, lockableTileEntity, x, y, z); numPlayersUsing = getNumberOfPlayersUsing(worldIn, lockableTileEntity, x, y, z);
} }
return numPlayersUsing; 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; 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)))) { 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.openContainer instanceof IronChestContainer) { if (playerentity.containerMenu instanceof IronChestContainer) {
++i; ++i;
} }
} }
@ -155,26 +155,26 @@ public class GenericIronChestTileEntity extends LockableLootTileEntity implement
} }
private void playSound(SoundEvent soundIn) { private void playSound(SoundEvent soundIn) {
double d0 = (double) this.pos.getX() + 0.5D; double d0 = (double) this.worldPosition.getX() + 0.5D;
double d1 = (double) this.pos.getY() + 0.5D; double d1 = (double) this.worldPosition.getY() + 0.5D;
double d2 = (double) this.pos.getZ() + 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 @Override
public boolean receiveClientEvent(int id, int type) { public boolean triggerEvent(int id, int type) {
if (id == 1) { if (id == 1) {
this.numPlayersUsing = type; this.numPlayersUsing = type;
return true; return true;
} }
else { else {
return super.receiveClientEvent(id, type); return super.triggerEvent(id, type);
} }
} }
@Override @Override
public void openInventory(PlayerEntity player) { public void startOpen(Player player) {
if (!player.isSpectator()) { if (!player.isSpectator()) {
if (this.numPlayersUsing < 0) { if (this.numPlayersUsing < 0) {
this.numPlayersUsing = 0; this.numPlayersUsing = 0;
@ -186,7 +186,7 @@ public class GenericIronChestTileEntity extends LockableLootTileEntity implement
} }
@Override @Override
public void closeInventory(PlayerEntity player) { public void stopOpen(Player player) {
if (!player.isSpectator()) { if (!player.isSpectator()) {
--this.numPlayersUsing; --this.numPlayersUsing;
this.onOpenOrClose(); this.onOpenOrClose();
@ -197,8 +197,8 @@ public class GenericIronChestTileEntity extends LockableLootTileEntity implement
Block block = this.getBlockState().getBlock(); Block block = this.getBlockState().getBlock();
if (block instanceof GenericIronChestBlock) { if (block instanceof GenericIronChestBlock) {
this.world.addBlockEvent(this.pos, block, 1, this.numPlayersUsing); this.level.blockEvent(this.worldPosition, block, 1, this.numPlayersUsing);
this.world.notifyNeighborsOfStateChange(this.pos, block); this.level.updateNeighborsAt(this.worldPosition, block);
} }
} }
@ -220,14 +220,14 @@ public class GenericIronChestTileEntity extends LockableLootTileEntity implement
@Override @Override
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)
public float getLidAngle(float partialTicks) { public float getOpenNess(float partialTicks) {
return MathHelper.lerp(partialTicks, this.prevLidAngle, this.lidAngle); 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); BlockState blockstate = reader.getBlockState(posIn);
if (blockstate.hasTileEntity()) { if (blockstate.hasTileEntity()) {
TileEntity tileentity = reader.getTileEntity(posIn); BlockEntity tileentity = reader.getBlockEntity(posIn);
if (tileentity instanceof GenericIronChestTileEntity) { if (tileentity instanceof GenericIronChestTileEntity) {
return ((GenericIronChestTileEntity) tileentity).numPlayersUsing; return ((GenericIronChestTileEntity) tileentity).numPlayersUsing;
} }
@ -237,7 +237,7 @@ public class GenericIronChestTileEntity extends LockableLootTileEntity implement
} }
@Override @Override
protected Container createMenu(int windowId, PlayerInventory playerInventory) { protected AbstractContainerMenu createMenu(int windowId, Inventory playerInventory) {
return IronChestContainer.createIronContainer(windowId, playerInventory, this); return IronChestContainer.createIronContainer(windowId, playerInventory, this);
} }
@ -250,7 +250,7 @@ public class GenericIronChestTileEntity extends LockableLootTileEntity implement
public IronChestsTypes getChestType() { public IronChestsTypes getChestType() {
IronChestsTypes type = IronChestsTypes.IRON; IronChestsTypes type = IronChestsTypes.IRON;
if (this.hasWorld()) { if (this.hasLevel()) {
IronChestsTypes typeFromBlock = GenericIronChestBlock.getTypeFromBlock(this.getBlockState().getBlock()); IronChestsTypes typeFromBlock = GenericIronChestBlock.getTypeFromBlock(this.getBlockState().getBlock());
if (typeFromBlock != null) { if (typeFromBlock != null) {

View File

@ -3,8 +3,8 @@ package com.progwml6.ironchest.common.block.tileentity;
import com.progwml6.ironchest.common.block.IronChestsBlocks; import com.progwml6.ironchest.common.block.IronChestsBlocks;
import com.progwml6.ironchest.common.block.IronChestsTypes; import com.progwml6.ironchest.common.block.IronChestsTypes;
import com.progwml6.ironchest.common.inventory.IronChestContainer; import com.progwml6.ironchest.common.inventory.IronChestContainer;
import net.minecraft.entity.player.PlayerInventory; import net.minecraft.world.entity.player.Inventory;
import net.minecraft.inventory.container.Container; import net.minecraft.world.inventory.AbstractContainerMenu;
public class GoldChestTileEntity extends GenericIronChestTileEntity { public class GoldChestTileEntity extends GenericIronChestTileEntity {
@ -13,7 +13,7 @@ public class GoldChestTileEntity extends GenericIronChestTileEntity {
} }
@Override @Override
protected Container createMenu(int id, PlayerInventory playerInventory) { protected AbstractContainerMenu createMenu(int id, Inventory playerInventory) {
return IronChestContainer.createGoldContainer(id, playerInventory, this); return IronChestContainer.createGoldContainer(id, playerInventory, this);
} }
} }

View File

@ -3,36 +3,36 @@ package com.progwml6.ironchest.common.block.tileentity;
import com.google.common.collect.Sets; import com.google.common.collect.Sets;
import com.progwml6.ironchest.IronChests; import com.progwml6.ironchest.IronChests;
import com.progwml6.ironchest.common.block.IronChestsBlocks; 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.fml.RegistryObject;
import net.minecraftforge.registries.DeferredRegister; import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries; import net.minecraftforge.registries.ForgeRegistries;
public class IronChestsTileEntityTypes { public class IronChestsTileEntityTypes {
public static final DeferredRegister<TileEntityType<?>> TILE_ENTITIES = DeferredRegister.create(ForgeRegistries.TILE_ENTITIES, IronChests.MODID); public static final DeferredRegister<BlockEntityType<?>> TILE_ENTITIES = DeferredRegister.create(ForgeRegistries.TILE_ENTITIES, IronChests.MODID);
public static final RegistryObject<TileEntityType<IronChestTileEntity>> IRON_CHEST = TILE_ENTITIES.register( public static final RegistryObject<BlockEntityType<IronChestTileEntity>> IRON_CHEST = TILE_ENTITIES.register(
"iron_chest", () -> new TileEntityType<>(IronChestTileEntity::new, Sets.newHashSet(IronChestsBlocks.IRON_CHEST.get()), null)); "iron_chest", () -> new BlockEntityType<>(IronChestTileEntity::new, Sets.newHashSet(IronChestsBlocks.IRON_CHEST.get()), null));
public static final RegistryObject<TileEntityType<GoldChestTileEntity>> GOLD_CHEST = TILE_ENTITIES.register( public static final RegistryObject<BlockEntityType<GoldChestTileEntity>> GOLD_CHEST = TILE_ENTITIES.register(
"gold_chest", () -> new TileEntityType<>(GoldChestTileEntity::new, Sets.newHashSet(IronChestsBlocks.GOLD_CHEST.get()), null)); "gold_chest", () -> new BlockEntityType<>(GoldChestTileEntity::new, Sets.newHashSet(IronChestsBlocks.GOLD_CHEST.get()), null));
public static final RegistryObject<TileEntityType<DiamondChestTileEntity>> DIAMOND_CHEST = TILE_ENTITIES.register( public static final RegistryObject<BlockEntityType<DiamondChestTileEntity>> DIAMOND_CHEST = TILE_ENTITIES.register(
"diamond_chest", () -> new TileEntityType<>(DiamondChestTileEntity::new, Sets.newHashSet(IronChestsBlocks.DIAMOND_CHEST.get()), null)); "diamond_chest", () -> new BlockEntityType<>(DiamondChestTileEntity::new, Sets.newHashSet(IronChestsBlocks.DIAMOND_CHEST.get()), null));
public static final RegistryObject<TileEntityType<CopperChestTileEntity>> COPPER_CHEST = TILE_ENTITIES.register( public static final RegistryObject<BlockEntityType<CopperChestTileEntity>> COPPER_CHEST = TILE_ENTITIES.register(
"copper_chest", () -> new TileEntityType<>(CopperChestTileEntity::new, Sets.newHashSet(IronChestsBlocks.COPPER_CHEST.get()), null)); "copper_chest", () -> new BlockEntityType<>(CopperChestTileEntity::new, Sets.newHashSet(IronChestsBlocks.COPPER_CHEST.get()), null));
public static final RegistryObject<TileEntityType<SilverChestTileEntity>> SILVER_CHEST = TILE_ENTITIES.register( public static final RegistryObject<BlockEntityType<SilverChestTileEntity>> SILVER_CHEST = TILE_ENTITIES.register(
"silver_chest", () -> new TileEntityType<>(SilverChestTileEntity::new, Sets.newHashSet(IronChestsBlocks.SILVER_CHEST.get()), null)); "silver_chest", () -> new BlockEntityType<>(SilverChestTileEntity::new, Sets.newHashSet(IronChestsBlocks.SILVER_CHEST.get()), null));
public static final RegistryObject<TileEntityType<CrystalChestTileEntity>> CRYSTAL_CHEST = TILE_ENTITIES.register( public static final RegistryObject<BlockEntityType<CrystalChestTileEntity>> CRYSTAL_CHEST = TILE_ENTITIES.register(
"crystal_chest", () -> new TileEntityType<>(CrystalChestTileEntity::new, Sets.newHashSet(IronChestsBlocks.CRYSTAL_CHEST.get()), null)); "crystal_chest", () -> new BlockEntityType<>(CrystalChestTileEntity::new, Sets.newHashSet(IronChestsBlocks.CRYSTAL_CHEST.get()), null));
public static final RegistryObject<TileEntityType<ObsidianChestTileEntity>> OBSIDIAN_CHEST = TILE_ENTITIES.register( public static final RegistryObject<BlockEntityType<ObsidianChestTileEntity>> OBSIDIAN_CHEST = TILE_ENTITIES.register(
"obsidian_chest", () -> new TileEntityType<>(ObsidianChestTileEntity::new, Sets.newHashSet(IronChestsBlocks.OBSIDIAN_CHEST.get()), null)); "obsidian_chest", () -> new BlockEntityType<>(ObsidianChestTileEntity::new, Sets.newHashSet(IronChestsBlocks.OBSIDIAN_CHEST.get()), null));
public static final RegistryObject<TileEntityType<DirtChestTileEntity>> DIRT_CHEST = TILE_ENTITIES.register( public static final RegistryObject<BlockEntityType<DirtChestTileEntity>> DIRT_CHEST = TILE_ENTITIES.register(
"dirt_chest", () -> new TileEntityType<>(DirtChestTileEntity::new, Sets.newHashSet(IronChestsBlocks.DIRT_CHEST.get()), null)); "dirt_chest", () -> new BlockEntityType<>(DirtChestTileEntity::new, Sets.newHashSet(IronChestsBlocks.DIRT_CHEST.get()), null));
} }

View File

@ -3,8 +3,8 @@ package com.progwml6.ironchest.common.block.tileentity;
import com.progwml6.ironchest.common.block.IronChestsBlocks; import com.progwml6.ironchest.common.block.IronChestsBlocks;
import com.progwml6.ironchest.common.block.IronChestsTypes; import com.progwml6.ironchest.common.block.IronChestsTypes;
import com.progwml6.ironchest.common.inventory.IronChestContainer; import com.progwml6.ironchest.common.inventory.IronChestContainer;
import net.minecraft.entity.player.PlayerInventory; import net.minecraft.world.entity.player.Inventory;
import net.minecraft.inventory.container.Container; import net.minecraft.world.inventory.AbstractContainerMenu;
public class ObsidianChestTileEntity extends GenericIronChestTileEntity { public class ObsidianChestTileEntity extends GenericIronChestTileEntity {
@ -13,7 +13,7 @@ public class ObsidianChestTileEntity extends GenericIronChestTileEntity {
} }
@Override @Override
protected Container createMenu(int id, PlayerInventory playerInventory) { protected AbstractContainerMenu createMenu(int id, Inventory playerInventory) {
return IronChestContainer.createObsidianContainer(id, playerInventory, this); return IronChestContainer.createObsidianContainer(id, playerInventory, this);
} }
} }

View File

@ -3,8 +3,8 @@ package com.progwml6.ironchest.common.block.tileentity;
import com.progwml6.ironchest.common.block.IronChestsBlocks; import com.progwml6.ironchest.common.block.IronChestsBlocks;
import com.progwml6.ironchest.common.block.IronChestsTypes; import com.progwml6.ironchest.common.block.IronChestsTypes;
import com.progwml6.ironchest.common.inventory.IronChestContainer; import com.progwml6.ironchest.common.inventory.IronChestContainer;
import net.minecraft.entity.player.PlayerInventory; import net.minecraft.world.entity.player.Inventory;
import net.minecraft.inventory.container.Container; import net.minecraft.world.inventory.AbstractContainerMenu;
public class SilverChestTileEntity extends GenericIronChestTileEntity { public class SilverChestTileEntity extends GenericIronChestTileEntity {
@ -13,7 +13,7 @@ public class SilverChestTileEntity extends GenericIronChestTileEntity {
} }
@Override @Override
protected Container createMenu(int id, PlayerInventory playerInventory) { protected AbstractContainerMenu createMenu(int id, Inventory playerInventory) {
return IronChestContainer.createSilverContainer(id, playerInventory, this); return IronChestContainer.createSilverContainer(id, playerInventory, this);
} }
} }

View File

@ -6,18 +6,18 @@ import com.progwml6.ironchest.common.item.IronChestsItems;
import com.progwml6.ironchest.common.item.IronChestsUpgradeType; import com.progwml6.ironchest.common.item.IronChestsUpgradeType;
import net.minecraft.advancements.Advancement; import net.minecraft.advancements.Advancement;
import net.minecraft.advancements.AdvancementRewards; import net.minecraft.advancements.AdvancementRewards;
import net.minecraft.advancements.IRequirementsStrategy; import net.minecraft.advancements.RequirementsStrategy;
import net.minecraft.advancements.criterion.RecipeUnlockedTrigger; import net.minecraft.advancements.critereon.RecipeUnlockedTrigger;
import net.minecraft.block.Blocks; import net.minecraft.world.level.block.Blocks;
import net.minecraft.data.DataGenerator; import net.minecraft.data.DataGenerator;
import net.minecraft.data.IFinishedRecipe; import net.minecraft.data.recipes.FinishedRecipe;
import net.minecraft.data.RecipeProvider; import net.minecraft.data.recipes.RecipeProvider;
import net.minecraft.data.ShapedRecipeBuilder; import net.minecraft.data.recipes.ShapedRecipeBuilder;
import net.minecraft.item.Item; import net.minecraft.world.item.Item;
import net.minecraft.item.crafting.Ingredient; import net.minecraft.world.item.crafting.Ingredient;
import net.minecraft.tags.ItemTags; import net.minecraft.tags.ItemTags;
import net.minecraft.util.IItemProvider; import net.minecraft.world.level.ItemLike;
import net.minecraft.util.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraftforge.common.Tags; import net.minecraftforge.common.Tags;
import net.minecraftforge.common.crafting.ConditionalAdvancement; import net.minecraftforge.common.crafting.ConditionalAdvancement;
import net.minecraftforge.common.crafting.ConditionalRecipe; import net.minecraftforge.common.crafting.ConditionalRecipe;
@ -37,327 +37,327 @@ public class IronChestsRecipeProvider extends RecipeProvider implements IConditi
} }
@Override @Override
protected void registerRecipes(Consumer<IFinishedRecipe> consumer) { protected void buildShapelessRecipes(Consumer<FinishedRecipe> consumer) {
this.addChestsRecipes(consumer); this.addChestsRecipes(consumer);
this.addUpgradesRecipes(consumer); this.addUpgradesRecipes(consumer);
} }
private void addChestsRecipes(Consumer<IFinishedRecipe> consumer) { private void addChestsRecipes(Consumer<FinishedRecipe> consumer) {
String folder = "chests/"; String folder = "chests/";
ShapedRecipeBuilder.shapedRecipe(IronChestsBlocks.IRON_CHEST.get()) ShapedRecipeBuilder.shaped(IronChestsBlocks.IRON_CHEST.get())
.key('M', Tags.Items.INGOTS_IRON) .define('M', Tags.Items.INGOTS_IRON)
.key('S', Tags.Items.CHESTS_WOODEN) .define('S', Tags.Items.CHESTS_WOODEN)
.patternLine("MMM") .pattern("MMM")
.patternLine("MSM") .pattern("MSM")
.patternLine("MMM") .pattern("MMM")
.addCriterion("has_iron_ingot", hasItem(Tags.Items.INGOTS_IRON)) .unlockedBy("has_iron_ingot", has(Tags.Items.INGOTS_IRON))
.build(consumer, location(folder + "vanilla_iron_chest")); .save(consumer, location(folder + "vanilla_iron_chest"));
ShapedRecipeBuilder.shapedRecipe(IronChestsBlocks.GOLD_CHEST.get()) ShapedRecipeBuilder.shaped(IronChestsBlocks.GOLD_CHEST.get())
.key('M', Tags.Items.INGOTS_GOLD) .define('M', Tags.Items.INGOTS_GOLD)
.key('S', IronChestsBlocks.IRON_CHEST.get()) .define('S', IronChestsBlocks.IRON_CHEST.get())
.patternLine("MMM") .pattern("MMM")
.patternLine("MSM") .pattern("MSM")
.patternLine("MMM") .pattern("MMM")
.addCriterion("has_gold_ingot", hasItem(Tags.Items.INGOTS_GOLD)) .unlockedBy("has_gold_ingot", has(Tags.Items.INGOTS_GOLD))
.build(consumer, location(folder + "iron_gold_chest")); .save(consumer, location(folder + "iron_gold_chest"));
ShapedRecipeBuilder.shapedRecipe(IronChestsBlocks.DIAMOND_CHEST.get()) ShapedRecipeBuilder.shaped(IronChestsBlocks.DIAMOND_CHEST.get())
.key('M', Tags.Items.GEMS_DIAMOND) .define('M', Tags.Items.GEMS_DIAMOND)
.key('S', IronChestsBlocks.GOLD_CHEST.get()) .define('S', IronChestsBlocks.GOLD_CHEST.get())
.key('G', Tags.Items.GLASS) .define('G', Tags.Items.GLASS)
.patternLine("GGG") .pattern("GGG")
.patternLine("MSM") .pattern("MSM")
.patternLine("GGG") .pattern("GGG")
.addCriterion("has_diamonds", hasItem(Tags.Items.GEMS_DIAMOND)) .unlockedBy("has_diamonds", has(Tags.Items.GEMS_DIAMOND))
.build(consumer, location(folder + "gold_diamond_chest")); .save(consumer, location(folder + "gold_diamond_chest"));
ShapedRecipeBuilder.shapedRecipe(IronChestsBlocks.OBSIDIAN_CHEST.get()) ShapedRecipeBuilder.shaped(IronChestsBlocks.OBSIDIAN_CHEST.get())
.key('M', Blocks.OBSIDIAN) .define('M', Blocks.OBSIDIAN)
.key('S', IronChestsBlocks.DIAMOND_CHEST.get()) .define('S', IronChestsBlocks.DIAMOND_CHEST.get())
.patternLine("MMM") .pattern("MMM")
.patternLine("MSM") .pattern("MSM")
.patternLine("MMM") .pattern("MMM")
.addCriterion("has_obsidian", hasItem(Blocks.OBSIDIAN)) .unlockedBy("has_obsidian", has(Blocks.OBSIDIAN))
.build(consumer, location(folder + "diamond_obsidian_chest")); .save(consumer, location(folder + "diamond_obsidian_chest"));
ShapedRecipeBuilder.shapedRecipe(IronChestsBlocks.CRYSTAL_CHEST.get()) ShapedRecipeBuilder.shaped(IronChestsBlocks.CRYSTAL_CHEST.get())
.key('G', Tags.Items.GLASS) .define('G', Tags.Items.GLASS)
.key('S', IronChestsBlocks.DIAMOND_CHEST.get()) .define('S', IronChestsBlocks.DIAMOND_CHEST.get())
.patternLine("GGG") .pattern("GGG")
.patternLine("GSG") .pattern("GSG")
.patternLine("GGG") .pattern("GGG")
.addCriterion("has_glass", hasItem(Tags.Items.GLASS)) .unlockedBy("has_glass", has(Tags.Items.GLASS))
.build(consumer, location(folder + "diamond_crystal_chest")); .save(consumer, location(folder + "diamond_crystal_chest"));
ShapedRecipeBuilder.shapedRecipe(IronChestsBlocks.DIRT_CHEST.get()) ShapedRecipeBuilder.shaped(IronChestsBlocks.DIRT_CHEST.get())
.key('M', Ingredient.fromItems(Blocks.DIRT, Blocks.COARSE_DIRT, Blocks.PODZOL)) .define('M', Ingredient.of(Blocks.DIRT, Blocks.COARSE_DIRT, Blocks.PODZOL))
.key('S', Tags.Items.CHESTS_WOODEN) .define('S', Tags.Items.CHESTS_WOODEN)
.patternLine("MMM") .pattern("MMM")
.patternLine("MSM") .pattern("MSM")
.patternLine("MMM") .pattern("MMM")
.addCriterion("has_iron_ingot", hasItem(Blocks.DIRT)) .unlockedBy("has_iron_ingot", has(Blocks.DIRT))
.build(consumer, location(folder + "vanilla_dirt_chest")); .save(consumer, location(folder + "vanilla_dirt_chest"));
ResourceLocation copperToIronChest = location(folder + "copper_iron_chest"); ResourceLocation copperToIronChest = location(folder + "copper_iron_chest");
ConditionalRecipe.builder() ConditionalRecipe.builder()
.addCondition(not(new TagEmptyCondition("forge:ingots/copper"))) .addCondition(not(new TagEmptyCondition("forge:ingots/copper")))
.addRecipe(ShapedRecipeBuilder.shapedRecipe(IronChestsBlocks.IRON_CHEST.get()) .addRecipe(ShapedRecipeBuilder.shaped(IronChestsBlocks.IRON_CHEST.get())
.key('M', Tags.Items.INGOTS_IRON) .define('M', Tags.Items.INGOTS_IRON)
.key('S', IronChestsBlocks.COPPER_CHEST.get()) .define('S', IronChestsBlocks.COPPER_CHEST.get())
.key('G', Tags.Items.GLASS) .define('G', Tags.Items.GLASS)
.patternLine("MGM") .pattern("MGM")
.patternLine("GSG") .pattern("GSG")
.patternLine("MGM") .pattern("MGM")
.addCriterion("has_item", hasItem(Tags.Items.INGOTS_IRON))::build) .unlockedBy("has_item", has(Tags.Items.INGOTS_IRON))::save)
.setAdvancement(location("recipes/ironchest/chests/copper_iron_chest"), ConditionalAdvancement.builder() .setAdvancement(location("recipes/ironchest/chests/copper_iron_chest"), ConditionalAdvancement.builder()
.addCondition(not(new TagEmptyCondition("forge:ingots/copper"))) .addCondition(not(new TagEmptyCondition("forge:ingots/copper")))
.addAdvancement(Advancement.Builder.builder() .addAdvancement(Advancement.Builder.advancement()
.withParentId(new ResourceLocation("recipes/root")) .parent(new ResourceLocation("recipes/root"))
.withRewards(AdvancementRewards.Builder.recipe(copperToIronChest)) .rewards(AdvancementRewards.Builder.recipe(copperToIronChest))
.withCriterion("has_item", hasItem(Tags.Items.INGOTS_IRON)) .addCriterion("has_item", has(Tags.Items.INGOTS_IRON))
.withCriterion("has_the_recipe", RecipeUnlockedTrigger.create(copperToIronChest)) .addCriterion("has_the_recipe", RecipeUnlockedTrigger.unlocked(copperToIronChest))
.withRequirementsStrategy(IRequirementsStrategy.OR)) .requirements(RequirementsStrategy.OR))
).build(consumer, copperToIronChest); ).build(consumer, copperToIronChest);
ResourceLocation copperToSilverChest = location(folder + "copper_silver_chest"); ResourceLocation copperToSilverChest = location(folder + "copper_silver_chest");
ConditionalRecipe.builder() ConditionalRecipe.builder()
.addCondition(not(new TagEmptyCondition("forge:ingots/silver"))) .addCondition(not(new TagEmptyCondition("forge:ingots/silver")))
.addRecipe(ShapedRecipeBuilder.shapedRecipe(IronChestsBlocks.SILVER_CHEST.get()) .addRecipe(ShapedRecipeBuilder.shaped(IronChestsBlocks.SILVER_CHEST.get())
.key('M', INGOTS_SILVER) .define('M', INGOTS_SILVER)
.key('S', IronChestsBlocks.COPPER_CHEST.get()) .define('S', IronChestsBlocks.COPPER_CHEST.get())
.patternLine("MMM") .pattern("MMM")
.patternLine("MSM") .pattern("MSM")
.patternLine("MMM") .pattern("MMM")
.addCriterion("has_item", hasItem(INGOTS_SILVER))::build) .unlockedBy("has_item", has(INGOTS_SILVER))::save)
.setAdvancement(location("recipes/ironchest/chests/copper_silver_chest"), ConditionalAdvancement.builder() .setAdvancement(location("recipes/ironchest/chests/copper_silver_chest"), ConditionalAdvancement.builder()
.addCondition(not(new TagEmptyCondition("forge:ingots/silver"))) .addCondition(not(new TagEmptyCondition("forge:ingots/silver")))
.addAdvancement(Advancement.Builder.builder() .addAdvancement(Advancement.Builder.advancement()
.withParentId(new ResourceLocation("recipes/root")) .parent(new ResourceLocation("recipes/root"))
.withRewards(AdvancementRewards.Builder.recipe(copperToSilverChest)) .rewards(AdvancementRewards.Builder.recipe(copperToSilverChest))
.withCriterion("has_item", hasItem(INGOTS_SILVER)) .addCriterion("has_item", has(INGOTS_SILVER))
.withCriterion("has_the_recipe", RecipeUnlockedTrigger.create(copperToSilverChest)) .addCriterion("has_the_recipe", RecipeUnlockedTrigger.unlocked(copperToSilverChest))
.withRequirementsStrategy(IRequirementsStrategy.OR)) .requirements(RequirementsStrategy.OR))
).build(consumer, copperToSilverChest); ).build(consumer, copperToSilverChest);
ResourceLocation ironToSilverChest = location(folder + "iron_silver_chest"); ResourceLocation ironToSilverChest = location(folder + "iron_silver_chest");
ConditionalRecipe.builder() ConditionalRecipe.builder()
.addCondition(not(new TagEmptyCondition("forge:ingots/silver"))) .addCondition(not(new TagEmptyCondition("forge:ingots/silver")))
.addRecipe(ShapedRecipeBuilder.shapedRecipe(IronChestsBlocks.SILVER_CHEST.get()) .addRecipe(ShapedRecipeBuilder.shaped(IronChestsBlocks.SILVER_CHEST.get())
.key('M', INGOTS_SILVER) .define('M', INGOTS_SILVER)
.key('S', IronChestsBlocks.IRON_CHEST.get()) .define('S', IronChestsBlocks.IRON_CHEST.get())
.key('G', Tags.Items.GLASS) .define('G', Tags.Items.GLASS)
.patternLine("MGM") .pattern("MGM")
.patternLine("MSM") .pattern("MSM")
.patternLine("MGM") .pattern("MGM")
.addCriterion("has_item", hasItem(INGOTS_SILVER))::build) .unlockedBy("has_item", has(INGOTS_SILVER))::save)
.setAdvancement(location("recipes/ironchest/chests/iron_silver_chest"), ConditionalAdvancement.builder() .setAdvancement(location("recipes/ironchest/chests/iron_silver_chest"), ConditionalAdvancement.builder()
.addCondition(not(new TagEmptyCondition("forge:ingots/silver"))) .addCondition(not(new TagEmptyCondition("forge:ingots/silver")))
.addAdvancement(Advancement.Builder.builder() .addAdvancement(Advancement.Builder.advancement()
.withParentId(new ResourceLocation("recipes/root")) .parent(new ResourceLocation("recipes/root"))
.withRewards(AdvancementRewards.Builder.recipe(ironToSilverChest)) .rewards(AdvancementRewards.Builder.recipe(ironToSilverChest))
.withCriterion("has_item", hasItem(INGOTS_SILVER)) .addCriterion("has_item", has(INGOTS_SILVER))
.withCriterion("has_the_recipe", RecipeUnlockedTrigger.create(ironToSilverChest)) .addCriterion("has_the_recipe", RecipeUnlockedTrigger.unlocked(ironToSilverChest))
.withRequirementsStrategy(IRequirementsStrategy.OR)) .requirements(RequirementsStrategy.OR))
).build(consumer, ironToSilverChest); ).build(consumer, ironToSilverChest);
ResourceLocation vanillaToCopperChest = location(folder + "vanilla_copper_chest"); ResourceLocation vanillaToCopperChest = location(folder + "vanilla_copper_chest");
ConditionalRecipe.builder() ConditionalRecipe.builder()
.addCondition(not(new TagEmptyCondition("forge:ingots/copper"))) .addCondition(not(new TagEmptyCondition("forge:ingots/copper")))
.addRecipe(ShapedRecipeBuilder.shapedRecipe(IronChestsBlocks.COPPER_CHEST.get()) .addRecipe(ShapedRecipeBuilder.shaped(IronChestsBlocks.COPPER_CHEST.get())
.key('M', INGOTS_COPPER) .define('M', INGOTS_COPPER)
.key('S', Tags.Items.CHESTS_WOODEN) .define('S', Tags.Items.CHESTS_WOODEN)
.patternLine("MMM") .pattern("MMM")
.patternLine("MSM") .pattern("MSM")
.patternLine("MMM") .pattern("MMM")
.addCriterion("has_item", hasItem(INGOTS_COPPER))::build) .unlockedBy("has_item", has(INGOTS_COPPER))::save)
.setAdvancement(location("recipes/ironchest/chests/vanilla_copper_chest"), ConditionalAdvancement.builder() .setAdvancement(location("recipes/ironchest/chests/vanilla_copper_chest"), ConditionalAdvancement.builder()
.addCondition(not(new TagEmptyCondition("forge:ingots/silver"))) .addCondition(not(new TagEmptyCondition("forge:ingots/silver")))
.addAdvancement(Advancement.Builder.builder() .addAdvancement(Advancement.Builder.advancement()
.withParentId(new ResourceLocation("recipes/root")) .parent(new ResourceLocation("recipes/root"))
.withRewards(AdvancementRewards.Builder.recipe(vanillaToCopperChest)) .rewards(AdvancementRewards.Builder.recipe(vanillaToCopperChest))
.withCriterion("has_item", hasItem(INGOTS_COPPER)) .addCriterion("has_item", has(INGOTS_COPPER))
.withCriterion("has_the_recipe", RecipeUnlockedTrigger.create(vanillaToCopperChest)) .addCriterion("has_the_recipe", RecipeUnlockedTrigger.unlocked(vanillaToCopperChest))
.withRequirementsStrategy(IRequirementsStrategy.OR)) .requirements(RequirementsStrategy.OR))
).build(consumer, vanillaToCopperChest); ).build(consumer, vanillaToCopperChest);
ResourceLocation silverToGoldChest = location(folder + "silver_gold_chest"); ResourceLocation silverToGoldChest = location(folder + "silver_gold_chest");
ConditionalRecipe.builder() ConditionalRecipe.builder()
.addCondition(not(new TagEmptyCondition("forge:ingots/copper"))) .addCondition(not(new TagEmptyCondition("forge:ingots/copper")))
.addRecipe(ShapedRecipeBuilder.shapedRecipe(IronChestsBlocks.GOLD_CHEST.get()) .addRecipe(ShapedRecipeBuilder.shaped(IronChestsBlocks.GOLD_CHEST.get())
.key('M', Tags.Items.INGOTS_GOLD) .define('M', Tags.Items.INGOTS_GOLD)
.key('S', IronChestsBlocks.SILVER_CHEST.get()) .define('S', IronChestsBlocks.SILVER_CHEST.get())
.key('G', Tags.Items.GLASS) .define('G', Tags.Items.GLASS)
.patternLine("MGM") .pattern("MGM")
.patternLine("GSG") .pattern("GSG")
.patternLine("MGM") .pattern("MGM")
.addCriterion("has_item", hasItem(INGOTS_SILVER))::build) .unlockedBy("has_item", has(INGOTS_SILVER))::save)
.setAdvancement(location("recipes/ironchest/chests/silver_gold_chest"), ConditionalAdvancement.builder() .setAdvancement(location("recipes/ironchest/chests/silver_gold_chest"), ConditionalAdvancement.builder()
.addCondition(not(new TagEmptyCondition("forge:ingots/silver"))) .addCondition(not(new TagEmptyCondition("forge:ingots/silver")))
.addAdvancement(Advancement.Builder.builder() .addAdvancement(Advancement.Builder.advancement()
.withParentId(new ResourceLocation("recipes/root")) .parent(new ResourceLocation("recipes/root"))
.withRewards(AdvancementRewards.Builder.recipe(silverToGoldChest)) .rewards(AdvancementRewards.Builder.recipe(silverToGoldChest))
.withCriterion("has_item", hasItem(INGOTS_SILVER)) .addCriterion("has_item", has(INGOTS_SILVER))
.withCriterion("has_the_recipe", RecipeUnlockedTrigger.create(silverToGoldChest)) .addCriterion("has_the_recipe", RecipeUnlockedTrigger.unlocked(silverToGoldChest))
.withRequirementsStrategy(IRequirementsStrategy.OR)) .requirements(RequirementsStrategy.OR))
).build(consumer, silverToGoldChest); ).build(consumer, silverToGoldChest);
ResourceLocation silverToDiamondChest = location(folder + "silver_diamond_chest"); ResourceLocation silverToDiamondChest = location(folder + "silver_diamond_chest");
ConditionalRecipe.builder() ConditionalRecipe.builder()
.addCondition(not(new TagEmptyCondition("forge:ingots/copper"))) .addCondition(not(new TagEmptyCondition("forge:ingots/copper")))
.addRecipe(ShapedRecipeBuilder.shapedRecipe(IronChestsBlocks.DIAMOND_CHEST.get()) .addRecipe(ShapedRecipeBuilder.shaped(IronChestsBlocks.DIAMOND_CHEST.get())
.key('M', Tags.Items.GEMS_DIAMOND) .define('M', Tags.Items.GEMS_DIAMOND)
.key('S', IronChestsBlocks.SILVER_CHEST.get()) .define('S', IronChestsBlocks.SILVER_CHEST.get())
.key('G', Tags.Items.GLASS) .define('G', Tags.Items.GLASS)
.patternLine("GGG") .pattern("GGG")
.patternLine("GSG") .pattern("GSG")
.patternLine("MMM") .pattern("MMM")
.addCriterion("has_item", hasItem(Tags.Items.GEMS_DIAMOND))::build) .unlockedBy("has_item", has(Tags.Items.GEMS_DIAMOND))::save)
.setAdvancement(location("recipes/ironchest/chests/silver_diamond_chest"), ConditionalAdvancement.builder() .setAdvancement(location("recipes/ironchest/chests/silver_diamond_chest"), ConditionalAdvancement.builder()
.addCondition(not(new TagEmptyCondition("forge:ingots/silver"))) .addCondition(not(new TagEmptyCondition("forge:ingots/silver")))
.addAdvancement(Advancement.Builder.builder() .addAdvancement(Advancement.Builder.advancement()
.withParentId(new ResourceLocation("recipes/root")) .parent(new ResourceLocation("recipes/root"))
.withRewards(AdvancementRewards.Builder.recipe(silverToDiamondChest)) .rewards(AdvancementRewards.Builder.recipe(silverToDiamondChest))
.withCriterion("has_item", hasItem(Tags.Items.GEMS_DIAMOND)) .addCriterion("has_item", has(Tags.Items.GEMS_DIAMOND))
.withCriterion("has_the_recipe", RecipeUnlockedTrigger.create(silverToDiamondChest)) .addCriterion("has_the_recipe", RecipeUnlockedTrigger.unlocked(silverToDiamondChest))
.withRequirementsStrategy(IRequirementsStrategy.OR)) .requirements(RequirementsStrategy.OR))
).build(consumer, silverToDiamondChest); ).build(consumer, silverToDiamondChest);
} }
private void addUpgradesRecipes(Consumer<IFinishedRecipe> consumer) { private void addUpgradesRecipes(Consumer<FinishedRecipe> consumer) {
String folder = "upgrades/"; String folder = "upgrades/";
ShapedRecipeBuilder.shapedRecipe(IronChestsItems.UPGRADES.get(IronChestsUpgradeType.WOOD_TO_IRON).get()) ShapedRecipeBuilder.shaped(IronChestsItems.UPGRADES.get(IronChestsUpgradeType.WOOD_TO_IRON).get())
.key('M', Tags.Items.INGOTS_IRON) .define('M', Tags.Items.INGOTS_IRON)
.key('P', ItemTags.PLANKS) .define('P', ItemTags.PLANKS)
.patternLine("MMM") .pattern("MMM")
.patternLine("MPM") .pattern("MPM")
.patternLine("MMM") .pattern("MMM")
.addCriterion("has_iron_ingot", hasItem(Tags.Items.INGOTS_IRON)) .unlockedBy("has_iron_ingot", has(Tags.Items.INGOTS_IRON))
.build(consumer, prefix(IronChestsItems.UPGRADES.get(IronChestsUpgradeType.WOOD_TO_IRON).get(), folder)); .save(consumer, prefix(IronChestsItems.UPGRADES.get(IronChestsUpgradeType.WOOD_TO_IRON).get(), folder));
ShapedRecipeBuilder.shapedRecipe(IronChestsItems.UPGRADES.get(IronChestsUpgradeType.IRON_TO_GOLD).get()) ShapedRecipeBuilder.shaped(IronChestsItems.UPGRADES.get(IronChestsUpgradeType.IRON_TO_GOLD).get())
.key('I', Tags.Items.INGOTS_IRON) .define('I', Tags.Items.INGOTS_IRON)
.key('G', Tags.Items.INGOTS_GOLD) .define('G', Tags.Items.INGOTS_GOLD)
.patternLine("GGG") .pattern("GGG")
.patternLine("GIG") .pattern("GIG")
.patternLine("GGG") .pattern("GGG")
.addCriterion("has_iron_ingot", hasItem(Tags.Items.INGOTS_IRON)) .unlockedBy("has_iron_ingot", has(Tags.Items.INGOTS_IRON))
.build(consumer, prefix(IronChestsItems.UPGRADES.get(IronChestsUpgradeType.IRON_TO_GOLD).get(), folder)); .save(consumer, prefix(IronChestsItems.UPGRADES.get(IronChestsUpgradeType.IRON_TO_GOLD).get(), folder));
ShapedRecipeBuilder.shapedRecipe(IronChestsItems.UPGRADES.get(IronChestsUpgradeType.GOLD_TO_DIAMOND).get()) ShapedRecipeBuilder.shaped(IronChestsItems.UPGRADES.get(IronChestsUpgradeType.GOLD_TO_DIAMOND).get())
.key('M', Tags.Items.GEMS_DIAMOND) .define('M', Tags.Items.GEMS_DIAMOND)
.key('S', Tags.Items.INGOTS_GOLD) .define('S', Tags.Items.INGOTS_GOLD)
.key('G', Tags.Items.GLASS) .define('G', Tags.Items.GLASS)
.patternLine("GGG") .pattern("GGG")
.patternLine("MSM") .pattern("MSM")
.patternLine("GGG") .pattern("GGG")
.addCriterion("has_glass", hasItem(Tags.Items.GLASS)) .unlockedBy("has_glass", has(Tags.Items.GLASS))
.build(consumer, prefix(IronChestsItems.UPGRADES.get(IronChestsUpgradeType.GOLD_TO_DIAMOND).get(), folder)); .save(consumer, prefix(IronChestsItems.UPGRADES.get(IronChestsUpgradeType.GOLD_TO_DIAMOND).get(), folder));
ShapedRecipeBuilder.shapedRecipe(IronChestsItems.UPGRADES.get(IronChestsUpgradeType.DIAMOND_TO_OBSIDIAN).get()) ShapedRecipeBuilder.shaped(IronChestsItems.UPGRADES.get(IronChestsUpgradeType.DIAMOND_TO_OBSIDIAN).get())
.key('S', Blocks.OBSIDIAN) .define('S', Blocks.OBSIDIAN)
.key('G', Tags.Items.GLASS) .define('G', Tags.Items.GLASS)
.patternLine("GGG") .pattern("GGG")
.patternLine("GSG") .pattern("GSG")
.patternLine("GGG") .pattern("GGG")
.addCriterion("has_glass", hasItem(Tags.Items.GLASS)) .unlockedBy("has_glass", has(Tags.Items.GLASS))
.build(consumer, prefix(IronChestsItems.UPGRADES.get(IronChestsUpgradeType.DIAMOND_TO_OBSIDIAN).get(), folder)); .save(consumer, prefix(IronChestsItems.UPGRADES.get(IronChestsUpgradeType.DIAMOND_TO_OBSIDIAN).get(), folder));
ShapedRecipeBuilder.shapedRecipe(IronChestsItems.UPGRADES.get(IronChestsUpgradeType.DIAMOND_TO_CRYSTAL).get()) ShapedRecipeBuilder.shaped(IronChestsItems.UPGRADES.get(IronChestsUpgradeType.DIAMOND_TO_CRYSTAL).get())
.key('M', Blocks.OBSIDIAN) .define('M', Blocks.OBSIDIAN)
.key('G', Tags.Items.GLASS) .define('G', Tags.Items.GLASS)
.patternLine("MMM") .pattern("MMM")
.patternLine("MGM") .pattern("MGM")
.patternLine("MMM") .pattern("MMM")
.addCriterion("has_glass", hasItem(Tags.Items.GLASS)) .unlockedBy("has_glass", has(Tags.Items.GLASS))
.build(consumer, prefix(IronChestsItems.UPGRADES.get(IronChestsUpgradeType.DIAMOND_TO_CRYSTAL).get(), folder)); .save(consumer, prefix(IronChestsItems.UPGRADES.get(IronChestsUpgradeType.DIAMOND_TO_CRYSTAL).get(), folder));
ResourceLocation woodToCopperChestUpgradeId = prefix(IronChestsItems.UPGRADES.get(IronChestsUpgradeType.WOOD_TO_COPPER).get(), folder); ResourceLocation woodToCopperChestUpgradeId = prefix(IronChestsItems.UPGRADES.get(IronChestsUpgradeType.WOOD_TO_COPPER).get(), folder);
ConditionalRecipe.builder() ConditionalRecipe.builder()
.addCondition(not(new TagEmptyCondition("forge:ingots/copper"))) .addCondition(not(new TagEmptyCondition("forge:ingots/copper")))
.addRecipe(ShapedRecipeBuilder.shapedRecipe(IronChestsItems.UPGRADES.get(IronChestsUpgradeType.WOOD_TO_COPPER).get()) .addRecipe(ShapedRecipeBuilder.shaped(IronChestsItems.UPGRADES.get(IronChestsUpgradeType.WOOD_TO_COPPER).get())
.key('M', INGOTS_COPPER) .define('M', INGOTS_COPPER)
.key('S', ItemTags.PLANKS) .define('S', ItemTags.PLANKS)
.patternLine("MMM") .pattern("MMM")
.patternLine("MSM") .pattern("MSM")
.patternLine("MMM") .pattern("MMM")
.addCriterion("has_item", hasItem(ItemTags.PLANKS))::build) .unlockedBy("has_item", has(ItemTags.PLANKS))::save)
.setAdvancement(location("recipes/ironchest/upgrades/wood_to_copper_chest_upgrade"), ConditionalAdvancement.builder() .setAdvancement(location("recipes/ironchest/upgrades/wood_to_copper_chest_upgrade"), ConditionalAdvancement.builder()
.addCondition(not(new TagEmptyCondition("forge:ingots/copper"))) .addCondition(not(new TagEmptyCondition("forge:ingots/copper")))
.addAdvancement(Advancement.Builder.builder() .addAdvancement(Advancement.Builder.advancement()
.withParentId(new ResourceLocation("recipes/root")) .parent(new ResourceLocation("recipes/root"))
.withRewards(AdvancementRewards.Builder.recipe(woodToCopperChestUpgradeId)) .rewards(AdvancementRewards.Builder.recipe(woodToCopperChestUpgradeId))
.withCriterion("has_item", hasItem(ItemTags.PLANKS)) .addCriterion("has_item", has(ItemTags.PLANKS))
.withCriterion("has_the_recipe", RecipeUnlockedTrigger.create(woodToCopperChestUpgradeId)) .addCriterion("has_the_recipe", RecipeUnlockedTrigger.unlocked(woodToCopperChestUpgradeId))
.withRequirementsStrategy(IRequirementsStrategy.OR)) .requirements(RequirementsStrategy.OR))
).build(consumer, woodToCopperChestUpgradeId); ).build(consumer, woodToCopperChestUpgradeId);
ResourceLocation copperToIronChestUpgrade = prefix(IronChestsItems.UPGRADES.get(IronChestsUpgradeType.COPPER_TO_IRON).get(), folder); ResourceLocation copperToIronChestUpgrade = prefix(IronChestsItems.UPGRADES.get(IronChestsUpgradeType.COPPER_TO_IRON).get(), folder);
ConditionalRecipe.builder() ConditionalRecipe.builder()
.addCondition(not(new TagEmptyCondition("forge:ingots/copper"))) .addCondition(not(new TagEmptyCondition("forge:ingots/copper")))
.addRecipe(ShapedRecipeBuilder.shapedRecipe(IronChestsItems.UPGRADES.get(IronChestsUpgradeType.COPPER_TO_IRON).get()) .addRecipe(ShapedRecipeBuilder.shaped(IronChestsItems.UPGRADES.get(IronChestsUpgradeType.COPPER_TO_IRON).get())
.key('M', Tags.Items.INGOTS_IRON) .define('M', Tags.Items.INGOTS_IRON)
.key('S', INGOTS_COPPER) .define('S', INGOTS_COPPER)
.key('G', Tags.Items.GLASS) .define('G', Tags.Items.GLASS)
.patternLine("MGM") .pattern("MGM")
.patternLine("GSG") .pattern("GSG")
.patternLine("MGM") .pattern("MGM")
.addCriterion("has_item", hasItem(ItemTags.PLANKS))::build) .unlockedBy("has_item", has(ItemTags.PLANKS))::save)
.setAdvancement(location("recipes/ironchest/upgrades/copper_to_iron_chest_upgrade"), ConditionalAdvancement.builder() .setAdvancement(location("recipes/ironchest/upgrades/copper_to_iron_chest_upgrade"), ConditionalAdvancement.builder()
.addCondition(not(new TagEmptyCondition("forge:ingots/copper"))) .addCondition(not(new TagEmptyCondition("forge:ingots/copper")))
.addAdvancement(Advancement.Builder.builder() .addAdvancement(Advancement.Builder.advancement()
.withParentId(new ResourceLocation("recipes/root")) .parent(new ResourceLocation("recipes/root"))
.withRewards(AdvancementRewards.Builder.recipe(copperToIronChestUpgrade)) .rewards(AdvancementRewards.Builder.recipe(copperToIronChestUpgrade))
.withCriterion("has_item", hasItem(Tags.Items.GLASS)) .addCriterion("has_item", has(Tags.Items.GLASS))
.withCriterion("has_the_recipe", RecipeUnlockedTrigger.create(copperToIronChestUpgrade)) .addCriterion("has_the_recipe", RecipeUnlockedTrigger.unlocked(copperToIronChestUpgrade))
.withRequirementsStrategy(IRequirementsStrategy.OR)) .requirements(RequirementsStrategy.OR))
).build(consumer, copperToIronChestUpgrade); ).build(consumer, copperToIronChestUpgrade);
ResourceLocation copperToSilverChestUpgrade = prefix(IronChestsItems.UPGRADES.get(IronChestsUpgradeType.COPPER_TO_SILVER).get(), folder); ResourceLocation copperToSilverChestUpgrade = prefix(IronChestsItems.UPGRADES.get(IronChestsUpgradeType.COPPER_TO_SILVER).get(), folder);
ConditionalRecipe.builder() ConditionalRecipe.builder()
.addCondition(and(not(new TagEmptyCondition("forge:ingots/copper")), not(new TagEmptyCondition("forge:ingots/silver")))) .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()) .addRecipe(ShapedRecipeBuilder.shaped(IronChestsItems.UPGRADES.get(IronChestsUpgradeType.COPPER_TO_SILVER).get())
.key('M', INGOTS_SILVER) .define('M', INGOTS_SILVER)
.key('S', INGOTS_COPPER) .define('S', INGOTS_COPPER)
.patternLine("MMM") .pattern("MMM")
.patternLine("MSM") .pattern("MSM")
.patternLine("MMM") .pattern("MMM")
.addCriterion("has_item", hasItem(INGOTS_COPPER))::build) .unlockedBy("has_item", has(INGOTS_COPPER))::save)
.setAdvancement(location("recipes/ironchest/upgrades/copper_to_silver_chest_upgrade"), ConditionalAdvancement.builder() .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")))) .addCondition(and(not(new TagEmptyCondition("forge:ingots/copper")), not(new TagEmptyCondition("forge:ingots/silver"))))
.addAdvancement(Advancement.Builder.builder() .addAdvancement(Advancement.Builder.advancement()
.withParentId(new ResourceLocation("recipes/root")) .parent(new ResourceLocation("recipes/root"))
.withRewards(AdvancementRewards.Builder.recipe(copperToSilverChestUpgrade)) .rewards(AdvancementRewards.Builder.recipe(copperToSilverChestUpgrade))
.withCriterion("has_item", hasItem(INGOTS_COPPER)) .addCriterion("has_item", has(INGOTS_COPPER))
.withCriterion("has_the_recipe", RecipeUnlockedTrigger.create(copperToSilverChestUpgrade)) .addCriterion("has_the_recipe", RecipeUnlockedTrigger.unlocked(copperToSilverChestUpgrade))
.withRequirementsStrategy(IRequirementsStrategy.OR)) .requirements(RequirementsStrategy.OR))
).build(consumer, copperToSilverChestUpgrade); ).build(consumer, copperToSilverChestUpgrade);
ResourceLocation silverToGoldChestUpgrade = prefix(IronChestsItems.UPGRADES.get(IronChestsUpgradeType.SILVER_TO_GOLD).get(), folder); ResourceLocation silverToGoldChestUpgrade = prefix(IronChestsItems.UPGRADES.get(IronChestsUpgradeType.SILVER_TO_GOLD).get(), folder);
ConditionalRecipe.builder() ConditionalRecipe.builder()
.addCondition(not(new TagEmptyCondition("forge:ingots/silver"))) .addCondition(not(new TagEmptyCondition("forge:ingots/silver")))
.addRecipe(ShapedRecipeBuilder.shapedRecipe(IronChestsItems.UPGRADES.get(IronChestsUpgradeType.SILVER_TO_GOLD).get()) .addRecipe(ShapedRecipeBuilder.shaped(IronChestsItems.UPGRADES.get(IronChestsUpgradeType.SILVER_TO_GOLD).get())
.key('M', Tags.Items.INGOTS_GOLD) .define('M', Tags.Items.INGOTS_GOLD)
.key('S', INGOTS_SILVER) .define('S', INGOTS_SILVER)
.key('G', Tags.Items.GLASS) .define('G', Tags.Items.GLASS)
.patternLine("MGM") .pattern("MGM")
.patternLine("GSG") .pattern("GSG")
.patternLine("MGM") .pattern("MGM")
.addCriterion("has_item", hasItem(Tags.Items.GLASS))::build) .unlockedBy("has_item", has(Tags.Items.GLASS))::save)
.setAdvancement(location("recipes/ironchest/upgrades/silver_to_gold_chest_upgrade"), ConditionalAdvancement.builder() .setAdvancement(location("recipes/ironchest/upgrades/silver_to_gold_chest_upgrade"), ConditionalAdvancement.builder()
.addCondition(not(new TagEmptyCondition("forge:ingots/silver"))) .addCondition(not(new TagEmptyCondition("forge:ingots/silver")))
.addAdvancement(Advancement.Builder.builder() .addAdvancement(Advancement.Builder.advancement()
.withParentId(new ResourceLocation("recipes/root")) .parent(new ResourceLocation("recipes/root"))
.withRewards(AdvancementRewards.Builder.recipe(silverToGoldChestUpgrade)) .rewards(AdvancementRewards.Builder.recipe(silverToGoldChestUpgrade))
.withCriterion("has_item", hasItem(Tags.Items.GLASS)) .addCriterion("has_item", has(Tags.Items.GLASS))
.withCriterion("has_the_recipe", RecipeUnlockedTrigger.create(silverToGoldChestUpgrade)) .addCriterion("has_the_recipe", RecipeUnlockedTrigger.unlocked(silverToGoldChestUpgrade))
.withRequirementsStrategy(IRequirementsStrategy.OR)) .requirements(RequirementsStrategy.OR))
).build(consumer, silverToGoldChestUpgrade); ).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()); ResourceLocation loc = Objects.requireNonNull(item.asItem().getRegistryName());
return location(prefix + loc.getPath()); return location(prefix + loc.getPath());
} }

View File

@ -1,19 +1,19 @@
package com.progwml6.ironchest.common.inventory; package com.progwml6.ironchest.common.inventory;
import net.minecraft.block.Blocks; import net.minecraft.world.level.block.Blocks;
import net.minecraft.inventory.IInventory; import net.minecraft.world.Container;
import net.minecraft.inventory.container.Slot; import net.minecraft.world.inventory.Slot;
import net.minecraft.item.Item; import net.minecraft.world.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.world.item.ItemStack;
public class DirtChestSlot extends Slot { 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); super(inventoryIn, slotIndex, xPosition, yPosition);
} }
@Override @Override
public boolean isItemValid(ItemStack stack) { public boolean mayPlace(ItemStack stack) {
return stack.isEmpty() || stack.getItem() == Item.getItemFromBlock(Blocks.DIRT); return stack.isEmpty() || stack.getItem() == Item.byBlock(Blocks.DIRT);
} }
} }

View File

@ -1,99 +1,99 @@
package com.progwml6.ironchest.common.inventory; package com.progwml6.ironchest.common.inventory;
import com.progwml6.ironchest.common.block.IronChestsTypes; import com.progwml6.ironchest.common.block.IronChestsTypes;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.world.entity.player.Player;
import net.minecraft.entity.player.PlayerInventory; import net.minecraft.world.entity.player.Inventory;
import net.minecraft.inventory.IInventory; import net.minecraft.world.Container;
import net.minecraft.inventory.Inventory; import net.minecraft.world.SimpleContainer;
import net.minecraft.inventory.container.Container; import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.inventory.container.ContainerType; import net.minecraft.world.inventory.MenuType;
import net.minecraft.inventory.container.Slot; import net.minecraft.world.inventory.Slot;
import net.minecraft.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraftforge.api.distmarker.Dist; import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn; 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 final IronChestsTypes chestType;
private IronChestContainer(ContainerType<?> containerType, int windowId, PlayerInventory playerInventory) { private IronChestContainer(MenuType<?> containerType, int windowId, Inventory playerInventory) {
this(containerType, windowId, playerInventory, new Inventory(IronChestsTypes.WOOD.size), IronChestsTypes.WOOD); this(containerType, windowId, playerInventory, new SimpleContainer(IronChestsTypes.WOOD.size), IronChestsTypes.WOOD);
} }
public static IronChestContainer createIronContainer(int windowId, PlayerInventory playerInventory) { public static IronChestContainer createIronContainer(int windowId, Inventory playerInventory) {
return new IronChestContainer(IronChestsContainerTypes.IRON_CHEST.get(), windowId, playerInventory, new Inventory(IronChestsTypes.IRON.size), IronChestsTypes.IRON); 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); return new IronChestContainer(IronChestsContainerTypes.IRON_CHEST.get(), windowId, playerInventory, inventory, IronChestsTypes.IRON);
} }
public static IronChestContainer createGoldContainer(int windowId, PlayerInventory playerInventory) { public static IronChestContainer createGoldContainer(int windowId, Inventory playerInventory) {
return new IronChestContainer(IronChestsContainerTypes.GOLD_CHEST.get(), windowId, playerInventory, new Inventory(IronChestsTypes.GOLD.size), IronChestsTypes.GOLD); 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); return new IronChestContainer(IronChestsContainerTypes.GOLD_CHEST.get(), windowId, playerInventory, inventory, IronChestsTypes.GOLD);
} }
public static IronChestContainer createDiamondContainer(int windowId, PlayerInventory playerInventory) { public static IronChestContainer createDiamondContainer(int windowId, Inventory playerInventory) {
return new IronChestContainer(IronChestsContainerTypes.DIAMOND_CHEST.get(), windowId, playerInventory, new Inventory(IronChestsTypes.DIAMOND.size), IronChestsTypes.DIAMOND); 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); return new IronChestContainer(IronChestsContainerTypes.DIAMOND_CHEST.get(), windowId, playerInventory, inventory, IronChestsTypes.DIAMOND);
} }
public static IronChestContainer createCrystalContainer(int windowId, PlayerInventory playerInventory) { public static IronChestContainer createCrystalContainer(int windowId, Inventory playerInventory) {
return new IronChestContainer(IronChestsContainerTypes.CRYSTAL_CHEST.get(), windowId, playerInventory, new Inventory(IronChestsTypes.CRYSTAL.size), IronChestsTypes.CRYSTAL); 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); return new IronChestContainer(IronChestsContainerTypes.CRYSTAL_CHEST.get(), windowId, playerInventory, inventory, IronChestsTypes.CRYSTAL);
} }
public static IronChestContainer createCopperContainer(int windowId, PlayerInventory playerInventory) { public static IronChestContainer createCopperContainer(int windowId, Inventory playerInventory) {
return new IronChestContainer(IronChestsContainerTypes.COPPER_CHEST.get(), windowId, playerInventory, new Inventory(IronChestsTypes.COPPER.size), IronChestsTypes.COPPER); 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); return new IronChestContainer(IronChestsContainerTypes.COPPER_CHEST.get(), windowId, playerInventory, inventory, IronChestsTypes.COPPER);
} }
public static IronChestContainer createSilverContainer(int windowId, PlayerInventory playerInventory) { public static IronChestContainer createSilverContainer(int windowId, Inventory playerInventory) {
return new IronChestContainer(IronChestsContainerTypes.SILVER_CHEST.get(), windowId, playerInventory, new Inventory(IronChestsTypes.CRYSTAL.size), IronChestsTypes.SILVER); 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); return new IronChestContainer(IronChestsContainerTypes.SILVER_CHEST.get(), windowId, playerInventory, inventory, IronChestsTypes.SILVER);
} }
public static IronChestContainer createObsidianContainer(int windowId, PlayerInventory playerInventory) { public static IronChestContainer createObsidianContainer(int windowId, Inventory playerInventory) {
return new IronChestContainer(IronChestsContainerTypes.OBSIDIAN_CHEST.get(), windowId, playerInventory, new Inventory(IronChestsTypes.OBSIDIAN.size), IronChestsTypes.OBSIDIAN); 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); return new IronChestContainer(IronChestsContainerTypes.OBSIDIAN_CHEST.get(), windowId, playerInventory, inventory, IronChestsTypes.OBSIDIAN);
} }
public static IronChestContainer createDirtContainer(int windowId, PlayerInventory playerInventory) { public static IronChestContainer createDirtContainer(int windowId, Inventory playerInventory) {
return new IronChestContainer(IronChestsContainerTypes.DIRT_CHEST.get(), windowId, playerInventory, new Inventory(IronChestsTypes.DIRT.size), IronChestsTypes.DIRT); 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); 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); super(containerType, windowId);
assertInventorySize(inventory, chestType.size); checkContainerSize(inventory, chestType.size);
this.inventory = inventory; this.inventory = inventory;
this.chestType = chestType; this.chestType = chestType;
inventory.openInventory(playerInventory.player); inventory.startOpen(playerInventory.player);
if (chestType == IronChestsTypes.DIRT) { if (chestType == IronChestsTypes.DIRT) {
this.addSlot(new DirtChestSlot(inventory, 0, 12 + 4 * 18, 8 + 2 * 18)); this.addSlot(new DirtChestSlot(inventory, 0, 12 + 4 * 18, 8 + 2 * 18));
@ -121,33 +121,33 @@ public class IronChestContainer extends Container {
} }
@Override @Override
public boolean canInteractWith(PlayerEntity playerIn) { public boolean stillValid(Player playerIn) {
return this.inventory.isUsableByPlayer(playerIn); return this.inventory.stillValid(playerIn);
} }
@Override @Override
public ItemStack transferStackInSlot(PlayerEntity playerIn, int index) { public ItemStack quickMoveStack(Player playerIn, int index) {
ItemStack itemstack = ItemStack.EMPTY; ItemStack itemstack = ItemStack.EMPTY;
Slot slot = this.inventorySlots.get(index); Slot slot = this.slots.get(index);
if (slot != null && slot.getHasStack()) { if (slot != null && slot.hasItem()) {
ItemStack itemstack1 = slot.getStack(); ItemStack itemstack1 = slot.getItem();
itemstack = itemstack1.copy(); itemstack = itemstack1.copy();
if (index < this.chestType.size) { 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; 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; return ItemStack.EMPTY;
} }
if (itemstack1.isEmpty()) { if (itemstack1.isEmpty()) {
slot.putStack(ItemStack.EMPTY); slot.set(ItemStack.EMPTY);
} }
else { else {
slot.onSlotChanged(); slot.setChanged();
} }
} }
@ -155,9 +155,9 @@ public class IronChestContainer extends Container {
} }
@Override @Override
public void onContainerClosed(PlayerEntity playerIn) { public void removed(Player playerIn) {
super.onContainerClosed(playerIn); super.removed(playerIn);
this.inventory.closeInventory(playerIn); this.inventory.stopOpen(playerIn);
} }
@OnlyIn(Dist.CLIENT) @OnlyIn(Dist.CLIENT)

View File

@ -1,28 +1,28 @@
package com.progwml6.ironchest.common.inventory; package com.progwml6.ironchest.common.inventory;
import com.progwml6.ironchest.IronChests; 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.fml.RegistryObject;
import net.minecraftforge.registries.DeferredRegister; import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries; import net.minecraftforge.registries.ForgeRegistries;
public class IronChestsContainerTypes { public class IronChestsContainerTypes {
public static final DeferredRegister<ContainerType<?>> CONTAINERS = DeferredRegister.create(ForgeRegistries.CONTAINERS, IronChests.MODID); public static final DeferredRegister<MenuType<?>> CONTAINERS = DeferredRegister.create(ForgeRegistries.CONTAINERS, IronChests.MODID);
public static final RegistryObject<ContainerType<IronChestContainer>> IRON_CHEST = CONTAINERS.register("iron_chest", () -> new ContainerType<>(IronChestContainer::createIronContainer)); public static final RegistryObject<MenuType<IronChestContainer>> IRON_CHEST = CONTAINERS.register("iron_chest", () -> new MenuType<>(IronChestContainer::createIronContainer));
public static final RegistryObject<ContainerType<IronChestContainer>> GOLD_CHEST = CONTAINERS.register("gold_chest", () -> new ContainerType<>(IronChestContainer::createGoldContainer)); public static final RegistryObject<MenuType<IronChestContainer>> GOLD_CHEST = CONTAINERS.register("gold_chest", () -> new MenuType<>(IronChestContainer::createGoldContainer));
public static final RegistryObject<ContainerType<IronChestContainer>> DIAMOND_CHEST = CONTAINERS.register("diamond_chest", () -> new ContainerType<>(IronChestContainer::createDiamondContainer)); public static final RegistryObject<MenuType<IronChestContainer>> DIAMOND_CHEST = CONTAINERS.register("diamond_chest", () -> new MenuType<>(IronChestContainer::createDiamondContainer));
public static final RegistryObject<ContainerType<IronChestContainer>> CRYSTAL_CHEST = CONTAINERS.register("crystal_chest", () -> new ContainerType<>(IronChestContainer::createCrystalContainer)); public static final RegistryObject<MenuType<IronChestContainer>> CRYSTAL_CHEST = CONTAINERS.register("crystal_chest", () -> new MenuType<>(IronChestContainer::createCrystalContainer));
public static final RegistryObject<ContainerType<IronChestContainer>> COPPER_CHEST = CONTAINERS.register("copper_chest", () -> new ContainerType<>(IronChestContainer::createCopperContainer)); public static final RegistryObject<MenuType<IronChestContainer>> COPPER_CHEST = CONTAINERS.register("copper_chest", () -> new MenuType<>(IronChestContainer::createCopperContainer));
public static final RegistryObject<ContainerType<IronChestContainer>> SILVER_CHEST = CONTAINERS.register("silver_chest", () -> new ContainerType<>(IronChestContainer::createSilverContainer)); public static final RegistryObject<MenuType<IronChestContainer>> SILVER_CHEST = CONTAINERS.register("silver_chest", () -> new MenuType<>(IronChestContainer::createSilverContainer));
public static final RegistryObject<ContainerType<IronChestContainer>> OBSIDIAN_CHEST = CONTAINERS.register("obsidian_chest", () -> new ContainerType<>(IronChestContainer::createObsidianContainer)); public static final RegistryObject<MenuType<IronChestContainer>> OBSIDIAN_CHEST = CONTAINERS.register("obsidian_chest", () -> new MenuType<>(IronChestContainer::createObsidianContainer));
public static final RegistryObject<ContainerType<IronChestContainer>> DIRT_CHEST = CONTAINERS.register("dirt_chest", () -> new ContainerType<>(IronChestContainer::createDirtContainer)); public static final RegistryObject<MenuType<IronChestContainer>> DIRT_CHEST = CONTAINERS.register("dirt_chest", () -> new MenuType<>(IronChestContainer::createDirtContainer));
} }

View File

@ -3,26 +3,28 @@ package com.progwml6.ironchest.common.item;
import com.progwml6.ironchest.common.block.GenericIronChestBlock; import com.progwml6.ironchest.common.block.GenericIronChestBlock;
import com.progwml6.ironchest.common.block.IronChestsTypes; import com.progwml6.ironchest.common.block.IronChestsTypes;
import com.progwml6.ironchest.common.block.tileentity.GenericIronChestTileEntity; import com.progwml6.ironchest.common.block.tileentity.GenericIronChestTileEntity;
import net.minecraft.block.BlockState; import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.block.ChestBlock; import net.minecraft.world.level.block.ChestBlock;
import net.minecraft.client.util.ITooltipFlag; import net.minecraft.world.item.TooltipFlag;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.world.entity.player.Player;
import net.minecraft.item.Item; import net.minecraft.world.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.item.ItemUseContext; import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.tileentity.ChestTileEntity; import net.minecraft.world.level.block.entity.ChestBlockEntity;
import net.minecraft.tileentity.TileEntity; import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.util.ActionResultType; import net.minecraft.world.InteractionResult;
import net.minecraft.util.Direction; import net.minecraft.core.Direction;
import net.minecraft.util.NonNullList; import net.minecraft.core.NonNullList;
import net.minecraft.util.math.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.util.text.ITextComponent; import net.minecraft.network.chat.Component;
import net.minecraft.util.text.TextFormatting; import net.minecraft.util.text.TextFormatting;
import net.minecraft.util.text.TranslationTextComponent; import net.minecraft.util.text.TranslationTextComponent;
import net.minecraft.world.World; import net.minecraft.world.level.Level;
import java.util.List; import java.util.List;
import net.minecraft.world.item.Item.Properties;
public class ChestUpgradeItem extends Item { public class ChestUpgradeItem extends Item {
private final IronChestsUpgradeType type; private final IronChestsUpgradeType type;
@ -33,47 +35,47 @@ public class ChestUpgradeItem extends Item {
} }
@Override @Override
public void addInformation(ItemStack stack, World worldIn, List<ITextComponent> tooltip, ITooltipFlag flagIn) { public void appendHoverText(ItemStack stack, Level worldIn, List<Component> tooltip, TooltipFlag flagIn) {
super.addInformation(stack, worldIn, tooltip, flagIn); super.appendHoverText(stack, worldIn, tooltip, flagIn);
//tooltip.add(new TranslationTextComponent(this.getTranslationKey() + ".desc").applyTextStyle(TextFormatting.GRAY)); //tooltip.add(new TranslationTextComponent(this.getTranslationKey() + ".desc").applyTextStyle(TextFormatting.GRAY));
} }
@Override @Override
public ActionResultType onItemUseFirst(ItemStack stack, ItemUseContext context) { public InteractionResult onItemUseFirst(ItemStack stack, UseOnContext context) {
PlayerEntity entityPlayer = context.getPlayer(); Player entityPlayer = context.getPlayer();
BlockPos blockPos = context.getPos(); BlockPos blockPos = context.getClickedPos();
World world = context.getWorld(); Level world = context.getLevel();
ItemStack itemStack = context.getItem(); ItemStack itemStack = context.getItemInHand();
if (world.isRemote) { if (world.isClientSide) {
return ActionResultType.PASS; return InteractionResult.PASS;
} }
if (entityPlayer == null) { if (entityPlayer == null) {
return ActionResultType.PASS; return InteractionResult.PASS;
} }
if (this.type.canUpgrade(IronChestsTypes.WOOD)) { if (this.type.canUpgrade(IronChestsTypes.WOOD)) {
if (!(world.getBlockState(blockPos).getBlock() instanceof ChestBlock)) { if (!(world.getBlockState(blockPos).getBlock() instanceof ChestBlock)) {
return ActionResultType.PASS; return InteractionResult.PASS;
} }
} }
else { else {
if (world.getBlockState(blockPos).getBlock().getDefaultState() != IronChestsTypes.get(this.type.source).getDefaultState()) { if (world.getBlockState(blockPos).getBlock().defaultBlockState() != IronChestsTypes.get(this.type.source).defaultBlockState()) {
return ActionResultType.PASS; return InteractionResult.PASS;
} }
} }
TileEntity tileEntity = world.getTileEntity(blockPos); BlockEntity tileEntity = world.getBlockEntity(blockPos);
if (this.type.canUpgrade(IronChestsTypes.WOOD)) { if (this.type.canUpgrade(IronChestsTypes.WOOD)) {
if (!(tileEntity instanceof ChestTileEntity)) { if (!(tileEntity instanceof ChestBlockEntity)) {
return ActionResultType.PASS; return InteractionResult.PASS;
} }
} }
GenericIronChestTileEntity newChest = null; GenericIronChestTileEntity newChest = null;
ITextComponent customName = null; Component customName = null;
NonNullList<ItemStack> chestContents = NonNullList.withSize(27, ItemStack.EMPTY); NonNullList<ItemStack> chestContents = NonNullList.withSize(27, ItemStack.EMPTY);
Direction chestFacing = Direction.NORTH; Direction chestFacing = Direction.NORTH;
@ -83,43 +85,43 @@ public class ChestUpgradeItem extends Item {
BlockState chestState = world.getBlockState(blockPos); BlockState chestState = world.getBlockState(blockPos);
if (GenericIronChestTileEntity.getPlayersUsing(world, blockPos) > 0) { if (GenericIronChestTileEntity.getPlayersUsing(world, blockPos) > 0) {
return ActionResultType.PASS; return InteractionResult.PASS;
} }
if (!chest.canOpen(entityPlayer)) { if (!chest.canOpen(entityPlayer)) {
return ActionResultType.PASS; return InteractionResult.PASS;
} }
chestContents = chest.getItems(); chestContents = chest.getItems();
chestFacing = chestState.get(GenericIronChestBlock.FACING); chestFacing = chestState.getValue(GenericIronChestBlock.FACING);
customName = chest.getCustomName(); customName = chest.getCustomName();
newChest = this.type.target.makeEntity(); newChest = this.type.target.makeEntity();
if (newChest == null) { if (newChest == null) {
return ActionResultType.PASS; return InteractionResult.PASS;
} }
} }
else if (tileEntity instanceof ChestTileEntity) { else if (tileEntity instanceof ChestBlockEntity) {
BlockState chestState = world.getBlockState(blockPos); BlockState chestState = world.getBlockState(blockPos);
chestFacing = chestState.get(ChestBlock.FACING); chestFacing = chestState.getValue(ChestBlock.FACING);
ChestTileEntity chest = (ChestTileEntity) tileEntity; ChestBlockEntity chest = (ChestBlockEntity) tileEntity;
if (ChestTileEntity.getPlayersUsing(world, blockPos) > 0) { if (ChestBlockEntity.getOpenCount(world, blockPos) > 0) {
return ActionResultType.PASS; return InteractionResult.PASS;
} }
if (!chest.canOpen(entityPlayer)) { if (!chest.canOpen(entityPlayer)) {
return ActionResultType.PASS; return InteractionResult.PASS;
} }
if (!this.type.canUpgrade(IronChestsTypes.WOOD)) { 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++) { for (int slot = 0; slot < chestContents.size(); slot++) {
chestContents.set(slot, chest.getStackInSlot(slot)); chestContents.set(slot, chest.getItem(slot));
} }
customName = chest.getCustomName(); 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); 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.setBlock(blockPos, iBlockState, 3);
world.setTileEntity(blockPos, newChest); 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 (tileEntity2 instanceof GenericIronChestTileEntity) {
if (customName != null) { if (customName != null) {
@ -150,11 +152,11 @@ public class ChestUpgradeItem extends Item {
((GenericIronChestTileEntity) tileEntity2).setItems(chestContents); ((GenericIronChestTileEntity) tileEntity2).setItems(chestContents);
} }
if (!entityPlayer.abilities.isCreativeMode) { if (!entityPlayer.abilities.instabuild) {
itemStack.shrink(1); itemStack.shrink(1);
} }
return ActionResultType.SUCCESS; return InteractionResult.SUCCESS;
} }
} }

View File

@ -2,7 +2,7 @@ package com.progwml6.ironchest.common.item;
import com.google.common.collect.ImmutableMap; import com.google.common.collect.ImmutableMap;
import com.progwml6.ironchest.IronChests; import com.progwml6.ironchest.IronChests;
import net.minecraft.item.Item; import net.minecraft.world.item.Item;
import net.minecraftforge.fml.RegistryObject; import net.minecraftforge.fml.RegistryObject;
import net.minecraftforge.registries.DeferredRegister; import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries; import net.minecraftforge.registries.ForgeRegistries;
@ -19,7 +19,7 @@ public class IronChestsItems {
public static final ImmutableMap<IronChestsUpgradeType, RegistryObject<ChestUpgradeItem>> UPGRADES = ImmutableMap.copyOf(Arrays.stream(IronChestsUpgradeType.values()) public static final ImmutableMap<IronChestsUpgradeType, RegistryObject<ChestUpgradeItem>> UPGRADES = ImmutableMap.copyOf(Arrays.stream(IronChestsUpgradeType.values())
.collect(Collectors.toMap(Function.identity(), type -> register(type.name().toLowerCase(Locale.ROOT) + "_chest_upgrade", .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 <T extends Item> RegistryObject<T> register(final String name, final Supplier<T> sup) { private static <T extends Item> RegistryObject<T> register(final String name, final Supplier<T> sup) {
return ITEMS.register(name, sup); return ITEMS.register(name, sup);

View File

@ -3,12 +3,12 @@ package com.progwml6.ironchest.common.network;
import com.progwml6.ironchest.common.block.tileentity.CrystalChestTileEntity; import com.progwml6.ironchest.common.block.tileentity.CrystalChestTileEntity;
import com.progwml6.ironchest.common.network.helper.IThreadsafePacket; import com.progwml6.ironchest.common.network.helper.IThreadsafePacket;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.item.ItemStack; import net.minecraft.world.item.ItemStack;
import net.minecraft.network.PacketBuffer; import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.tileentity.TileEntity; import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.util.NonNullList; import net.minecraft.core.NonNullList;
import net.minecraft.util.math.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.world.World; import net.minecraft.world.level.Level;
import net.minecraftforge.fml.network.NetworkEvent.Context; import net.minecraftforge.fml.network.NetworkEvent.Context;
public class InventoryTopStacksSyncPacket implements IThreadsafePacket { public class InventoryTopStacksSyncPacket implements IThreadsafePacket {
@ -21,12 +21,12 @@ public class InventoryTopStacksSyncPacket implements IThreadsafePacket {
this.pos = pos; this.pos = pos;
} }
public InventoryTopStacksSyncPacket(PacketBuffer buffer) { public InventoryTopStacksSyncPacket(FriendlyByteBuf buffer) {
int size = buffer.readInt(); int size = buffer.readInt();
NonNullList<ItemStack> topStacks = NonNullList.<ItemStack>withSize(size, ItemStack.EMPTY); NonNullList<ItemStack> topStacks = NonNullList.<ItemStack>withSize(size, ItemStack.EMPTY);
for (int item = 0; item < size; item++) { for (int item = 0; item < size; item++) {
ItemStack itemStack = buffer.readItemStack(); ItemStack itemStack = buffer.readItem();
topStacks.set(item, itemStack); topStacks.set(item, itemStack);
} }
@ -37,11 +37,11 @@ public class InventoryTopStacksSyncPacket implements IThreadsafePacket {
} }
@Override @Override
public void encode(PacketBuffer packetBuffer) { public void encode(FriendlyByteBuf packetBuffer) {
packetBuffer.writeInt(this.topStacks.size()); packetBuffer.writeInt(this.topStacks.size());
for (ItemStack stack : this.topStacks) { for (ItemStack stack : this.topStacks) {
packetBuffer.writeItemStack(stack); packetBuffer.writeItem(stack);
} }
packetBuffer.writeBlockPos(this.pos); packetBuffer.writeBlockPos(this.pos);
@ -58,15 +58,15 @@ public class InventoryTopStacksSyncPacket implements IThreadsafePacket {
private static class HandleClient { private static class HandleClient {
private static void handle(InventoryTopStacksSyncPacket packet) { private static void handle(InventoryTopStacksSyncPacket packet) {
World world = Minecraft.getInstance().world; Level world = Minecraft.getInstance().level;
if (world != null) { if (world != null) {
TileEntity te = world.getTileEntity(packet.pos); BlockEntity te = world.getBlockEntity(packet.pos);
if (te != null) { if (te != null) {
if (te instanceof CrystalChestTileEntity) { if (te instanceof CrystalChestTileEntity) {
((CrystalChestTileEntity) te).receiveMessageFromServer(packet.topStacks); ((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);
} }
} }
} }

View File

@ -2,16 +2,16 @@ package com.progwml6.ironchest.common.network;
import com.progwml6.ironchest.IronChests; import com.progwml6.ironchest.IronChests;
import com.progwml6.ironchest.common.network.helper.ISimplePacket; import com.progwml6.ironchest.common.network.helper.ISimplePacket;
import net.minecraft.entity.Entity; import net.minecraft.world.entity.Entity;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.world.entity.player.Player;
import net.minecraft.entity.player.ServerPlayerEntity; import net.minecraft.server.level.ServerPlayer;
import net.minecraft.network.IPacket; import net.minecraft.network.protocol.Packet;
import net.minecraft.network.PacketBuffer; import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.util.ResourceLocation; import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.math.BlockPos; import net.minecraft.core.BlockPos;
import net.minecraft.world.IWorld; import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.chunk.Chunk; import net.minecraft.world.level.chunk.LevelChunk;
import net.minecraft.world.server.ServerWorld; import net.minecraft.server.level.ServerLevel;
import net.minecraftforge.common.util.FakePlayer; import net.minecraftforge.common.util.FakePlayer;
import net.minecraftforge.fml.network.NetworkDirection; import net.minecraftforge.fml.network.NetworkDirection;
import net.minecraftforge.fml.network.NetworkEvent; import net.minecraftforge.fml.network.NetworkEvent;
@ -71,7 +71,7 @@ public class IronChestNetwork {
* @param decoder Packet decoder, typically the constructor * @param decoder Packet decoder, typically the constructor
* @param <MSG> Packet class type * @param <MSG> Packet class type
*/ */
public <MSG extends ISimplePacket> void registerPacket(Class<MSG> clazz, Function<PacketBuffer, MSG> decoder, @Nullable NetworkDirection direction) { public <MSG extends ISimplePacket> void registerPacket(Class<MSG> clazz, Function<FriendlyByteBuf, MSG> decoder, @Nullable NetworkDirection direction) {
registerPacket(clazz, ISimplePacket::encode, decoder, ISimplePacket::handle, 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 direction Network direction for validation. Pass null for no direction
* @param <MSG> Packet class type * @param <MSG> Packet class type
*/ */
public <MSG> void registerPacket(Class<MSG> clazz, BiConsumer<MSG, PacketBuffer> encoder, Function<PacketBuffer, MSG> decoder, BiConsumer<MSG, Supplier<NetworkEvent.Context>> consumer, @Nullable NetworkDirection direction) { public <MSG> void registerPacket(Class<MSG> clazz, BiConsumer<MSG, FriendlyByteBuf> encoder, Function<FriendlyByteBuf, MSG> decoder, BiConsumer<MSG, Supplier<NetworkEvent.Context>> consumer, @Nullable NetworkDirection direction) {
this.network.registerMessage(this.id++, clazz, encoder, decoder, consumer, Optional.ofNullable(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 player Player receiving the packet
* @param packet Packet * @param packet Packet
*/ */
public void sendVanillaPacket(IPacket<?> packet, Entity player) { public void sendVanillaPacket(Packet<?> packet, Entity player) {
if (player instanceof ServerPlayerEntity && ((ServerPlayerEntity) player).connection != null) { if (player instanceof ServerPlayer && ((ServerPlayer) player).connection != null) {
((ServerPlayerEntity) player).connection.sendPacket(packet); ((ServerPlayer) player).connection.send(packet);
} }
} }
@ -128,9 +128,9 @@ public class IronChestNetwork {
* @param msg Packet * @param msg Packet
* @param player Player to send * @param player Player to send
*/ */
public void sendTo(Object msg, PlayerEntity player) { public void sendTo(Object msg, Player player) {
if (player instanceof ServerPlayerEntity) { if (player instanceof ServerPlayer) {
sendTo(msg, (ServerPlayerEntity) player); sendTo(msg, (ServerPlayer) player);
} }
} }
@ -140,9 +140,9 @@ public class IronChestNetwork {
* @param msg Packet * @param msg Packet
* @param player Player to send * @param player Player to send
*/ */
public void sendTo(Object msg, ServerPlayerEntity player) { public void sendTo(Object msg, ServerPlayer player) {
if (!(player instanceof FakePlayer)) { 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 serverWorld World instance
* @param position Position within range * @param position Position within range
*/ */
public void sendToClientsAround(Object msg, ServerWorld serverWorld, BlockPos position) { public void sendToClientsAround(Object msg, ServerLevel serverWorld, BlockPos position) {
Chunk chunk = serverWorld.getChunkAt(position); LevelChunk chunk = serverWorld.getChunkAt(position);
network.send(PacketDistributor.TRACKING_CHUNK.with(() -> chunk), msg); network.send(PacketDistributor.TRACKING_CHUNK.with(() -> chunk), msg);
} }
@ -185,9 +185,9 @@ public class IronChestNetwork {
* @param world World instance * @param world World instance
* @param position Target position * @param position Target position
*/ */
public void sendToClientsAround(Object msg, @Nullable IWorld world, BlockPos position) { public void sendToClientsAround(Object msg, @Nullable LevelAccessor world, BlockPos position) {
if (world instanceof ServerWorld) { if (world instanceof ServerLevel) {
sendToClientsAround(msg, (ServerWorld) world, position); sendToClientsAround(msg, (ServerLevel) world, position);
} }
} }
} }

View File

@ -1,6 +1,6 @@
package com.progwml6.ironchest.common.network.helper; package com.progwml6.ironchest.common.network.helper;
import net.minecraft.network.PacketBuffer; import net.minecraft.network.FriendlyByteBuf;
import net.minecraftforge.fml.network.NetworkEvent; import net.minecraftforge.fml.network.NetworkEvent;
import java.util.function.Supplier; import java.util.function.Supplier;
@ -13,7 +13,7 @@ public interface ISimplePacket {
* Encodes a packet for the buffer * Encodes a packet for the buffer
* @param buf Buffer instance * @param buf Buffer instance
*/ */
void encode(PacketBuffer buf); void encode(FriendlyByteBuf buf);
/** /**
* Handles receiving the packet * Handles receiving the packet

View File

@ -1 +1 @@
public net.minecraft.entity.ai.goal.GoalSelector field_220892_d # goals public net.minecraft.world.entity.ai.goal.GoalSelector f_25345_ # goals