Update Iron Chests to 1.17!

This commit is contained in:
Alexander Behrhof 2021-07-28 13:38:12 -04:00
parent 3c4cefdad3
commit db2540c968
67 changed files with 1541 additions and 1447 deletions

View File

@ -141,9 +141,9 @@ dependencies {
minecraft 'net.minecraftforge:forge:' + minecraft_version + '-' + forge_version
// compile against the JEI API but do not include it at runtime
compileOnly fg.deobf("mezz.jei:jei-${jei_version}:api")
//compileOnly fg.deobf("mezz.jei:jei-${jei_version}:api")
// at runtime, use the full JEI jar
runtimeOnly fg.deobf("mezz.jei:jei-${jei_version}")
//runtimeOnly fg.deobf("mezz.jei:jei-${jei_version}")
}
def modsTomlSpec = copySpec{

View File

@ -12,7 +12,7 @@ minecraft_range=[1.17.1,1.18)
# Forge Version Information
loader_range=[33.0,)
forge_version=37.0.1
forge_version=37.0.12
forge_range=[37.0.1,)
# Mappings Information

View File

@ -1,14 +1,15 @@
package com.progwml6.ironchest;
import com.progwml6.ironchest.client.screen.IronChestScreen;
import com.progwml6.ironchest.client.render.IronChestTileEntityRenderer;
import com.progwml6.ironchest.client.render.IronChestRenderer;
import com.progwml6.ironchest.common.block.entity.IronChestsBlockEntityTypes;
import com.progwml6.ironchest.common.block.IronChestsBlocks;
import com.progwml6.ironchest.common.block.tileentity.IronChestsTileEntityTypes;
import com.progwml6.ironchest.common.data.IronChestsRecipeProvider;
import com.progwml6.ironchest.common.inventory.IronChestsContainerTypes;
import com.progwml6.ironchest.common.item.IronChestsItems;
import com.progwml6.ironchest.common.network.IronChestNetwork;
import net.minecraft.client.gui.screens.MenuScreens;
import net.minecraft.client.renderer.blockentity.BlockEntityRenderers;
import net.minecraft.data.DataGenerator;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.ItemStack;
@ -16,17 +17,16 @@ import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.fml.DistExecutor;
import net.minecraftforge.fml.client.registry.ClientRegistry;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.event.lifecycle.GatherDataEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.forge.event.lifecycle.GatherDataEvent;
@Mod(IronChests.MODID)
@Mod(IronChests.MOD_ID)
public class IronChests {
public static final String MODID = "ironchest";
public static final String MOD_ID = "ironchest";
public static final CreativeModeTab IRONCHESTS_ITEM_GROUP = (new CreativeModeTab("ironchest") {
@Override
@ -53,7 +53,7 @@ public class IronChests {
// Registry objects
IronChestsBlocks.BLOCKS.register(modBus);
IronChestsItems.ITEMS.register(modBus);
IronChestsTileEntityTypes.TILE_ENTITIES.register(modBus);
IronChestsBlockEntityTypes.BLOCK_ENTITIES.register(modBus);
IronChestsContainerTypes.CONTAINERS.register(modBus);
}
@ -68,14 +68,14 @@ public class IronChests {
MenuScreens.register(IronChestsContainerTypes.OBSIDIAN_CHEST.get(), IronChestScreen::new);
MenuScreens.register(IronChestsContainerTypes.DIRT_CHEST.get(), IronChestScreen::new);
ClientRegistry.bindTileEntityRenderer(IronChestsTileEntityTypes.IRON_CHEST.get(), IronChestTileEntityRenderer::new);
ClientRegistry.bindTileEntityRenderer(IronChestsTileEntityTypes.GOLD_CHEST.get(), IronChestTileEntityRenderer::new);
ClientRegistry.bindTileEntityRenderer(IronChestsTileEntityTypes.DIAMOND_CHEST.get(), IronChestTileEntityRenderer::new);
ClientRegistry.bindTileEntityRenderer(IronChestsTileEntityTypes.COPPER_CHEST.get(), IronChestTileEntityRenderer::new);
ClientRegistry.bindTileEntityRenderer(IronChestsTileEntityTypes.SILVER_CHEST.get(), IronChestTileEntityRenderer::new);
ClientRegistry.bindTileEntityRenderer(IronChestsTileEntityTypes.CRYSTAL_CHEST.get(), IronChestTileEntityRenderer::new);
ClientRegistry.bindTileEntityRenderer(IronChestsTileEntityTypes.OBSIDIAN_CHEST.get(), IronChestTileEntityRenderer::new);
ClientRegistry.bindTileEntityRenderer(IronChestsTileEntityTypes.DIRT_CHEST.get(), IronChestTileEntityRenderer::new);
BlockEntityRenderers.register(IronChestsBlockEntityTypes.IRON_CHEST.get(), IronChestRenderer::new);
BlockEntityRenderers.register(IronChestsBlockEntityTypes.GOLD_CHEST.get(), IronChestRenderer::new);
BlockEntityRenderers.register(IronChestsBlockEntityTypes.DIAMOND_CHEST.get(), IronChestRenderer::new);
BlockEntityRenderers.register(IronChestsBlockEntityTypes.COPPER_CHEST.get(), IronChestRenderer::new);
BlockEntityRenderers.register(IronChestsBlockEntityTypes.SILVER_CHEST.get(), IronChestRenderer::new);
BlockEntityRenderers.register(IronChestsBlockEntityTypes.CRYSTAL_CHEST.get(), IronChestRenderer::new);
BlockEntityRenderers.register(IronChestsBlockEntityTypes.OBSIDIAN_CHEST.get(), IronChestRenderer::new);
BlockEntityRenderers.register(IronChestsBlockEntityTypes.DIRT_CHEST.get(), IronChestRenderer::new);
}
private void setup(final FMLCommonSetupEvent event) {

View File

@ -0,0 +1,20 @@
package com.progwml6.ironchest;
import com.progwml6.ironchest.client.render.IronChestRenderer;
import net.minecraft.client.model.geom.ModelLayerLocation;
import net.minecraft.resources.ResourceLocation;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.client.event.EntityRenderersEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
@Mod.EventBusSubscriber(modid = IronChests.MOD_ID, value = Dist.CLIENT, bus = Mod.EventBusSubscriber.Bus.MOD)
public class IronChestsClientEvents {
public static final ModelLayerLocation IRON_CHEST = new ModelLayerLocation(new ResourceLocation(IronChests.MOD_ID, "iron_chest"), "main");
@SubscribeEvent
public static void layerDefinitions(EntityRenderersEvent.RegisterLayerDefinitions event) {
event.registerLayerDefinition(IRON_CHEST, IronChestRenderer::createBodyLayer);
}
}

View File

@ -9,43 +9,31 @@ import net.minecraftforge.client.event.TextureStitchEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import java.util.function.Consumer;
@Mod.EventBusSubscriber(modid = IronChests.MODID, value = Dist.CLIENT, bus = Mod.EventBusSubscriber.Bus.MOD)
@Mod.EventBusSubscriber(modid = IronChests.MOD_ID, value = Dist.CLIENT, bus = Mod.EventBusSubscriber.Bus.MOD)
public class IronChestsModels {
public static final ResourceLocation IRON_CHEST_LOCATION = new ResourceLocation(IronChests.MODID, "model/iron_chest");
public static final ResourceLocation GOLD_CHEST_LOCATION = new ResourceLocation(IronChests.MODID, "model/gold_chest");
public static final ResourceLocation DIAMOND_CHEST_LOCATION = new ResourceLocation(IronChests.MODID, "model/diamond_chest");
public static final ResourceLocation COPPER_CHEST_LOCATION = new ResourceLocation(IronChests.MODID, "model/copper_chest");
public static final ResourceLocation SILVER_CHEST_LOCATION = new ResourceLocation(IronChests.MODID, "model/silver_chest");
public static final ResourceLocation CRYSTAL_CHEST_LOCATION = new ResourceLocation(IronChests.MODID, "model/crystal_chest");
public static final ResourceLocation OBSIDIAN_CHEST_LOCATION = new ResourceLocation(IronChests.MODID, "model/obsidian_chest");
public static final ResourceLocation DIRT_CHEST_LOCATION = new ResourceLocation(IronChests.MODID, "model/dirt_chest");
public static final ResourceLocation VANLLA_CHEST_LOCATION = new ResourceLocation("entity/chest/normal");
public static final ResourceLocation IRON_CHEST_LOCATION = new ResourceLocation(IronChests.MOD_ID, "model/iron_chest");
public static final ResourceLocation GOLD_CHEST_LOCATION = new ResourceLocation(IronChests.MOD_ID, "model/gold_chest");
public static final ResourceLocation DIAMOND_CHEST_LOCATION = new ResourceLocation(IronChests.MOD_ID, "model/diamond_chest");
public static final ResourceLocation COPPER_CHEST_LOCATION = new ResourceLocation(IronChests.MOD_ID, "model/copper_chest");
public static final ResourceLocation SILVER_CHEST_LOCATION = new ResourceLocation(IronChests.MOD_ID, "model/silver_chest");
public static final ResourceLocation CRYSTAL_CHEST_LOCATION = new ResourceLocation(IronChests.MOD_ID, "model/crystal_chest");
public static final ResourceLocation OBSIDIAN_CHEST_LOCATION = new ResourceLocation(IronChests.MOD_ID, "model/obsidian_chest");
public static final ResourceLocation DIRT_CHEST_LOCATION = new ResourceLocation(IronChests.MOD_ID, "model/dirt_chest");
public static final ResourceLocation VANILLA_CHEST_LOCATION = new ResourceLocation("entity/chest/normal");
public static ResourceLocation chooseChestTexture(IronChestsTypes type) {
switch (type) {
case IRON:
return IRON_CHEST_LOCATION;
case GOLD:
return GOLD_CHEST_LOCATION;
case DIAMOND:
return DIAMOND_CHEST_LOCATION;
case COPPER:
return COPPER_CHEST_LOCATION;
case SILVER:
return SILVER_CHEST_LOCATION;
case CRYSTAL:
return CRYSTAL_CHEST_LOCATION;
case OBSIDIAN:
return OBSIDIAN_CHEST_LOCATION;
case DIRT:
return DIRT_CHEST_LOCATION;
case WOOD:
default:
return VANLLA_CHEST_LOCATION;
}
return switch (type) {
case IRON -> IRON_CHEST_LOCATION;
case GOLD -> GOLD_CHEST_LOCATION;
case DIAMOND -> DIAMOND_CHEST_LOCATION;
case COPPER -> COPPER_CHEST_LOCATION;
case SILVER -> SILVER_CHEST_LOCATION;
case CRYSTAL -> CRYSTAL_CHEST_LOCATION;
case OBSIDIAN -> OBSIDIAN_CHEST_LOCATION;
case DIRT -> DIRT_CHEST_LOCATION;
default -> VANILLA_CHEST_LOCATION;
};
}
@SubscribeEvent

View File

@ -1,6 +1,7 @@
package com.progwml6.ironchest.client.model.inventory;
import com.mojang.blaze3d.vertex.PoseStack;
import net.minecraft.client.model.geom.EntityModelSet;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.block.model.ItemTransforms;
import net.minecraft.client.renderer.BlockEntityWithoutLevelRenderer;
@ -16,13 +17,17 @@ import java.util.function.Supplier;
public class IronChestItemStackRenderer<T extends BlockEntity> extends BlockEntityWithoutLevelRenderer {
private final Supplier<T> te;
private final BlockEntityRenderDispatcher blockEntityRenderDispatcher;
public IronChestItemStackRenderer(BlockEntityRenderDispatcher renderDispatcher, EntityModelSet modelSet, Supplier<T> te) {
super(renderDispatcher, modelSet);
public IronChestItemStackRenderer(Supplier<T> te) {
this.te = te;
this.blockEntityRenderDispatcher = renderDispatcher;
}
@Override
public void renderByItem(ItemStack itemStackIn, ItemTransforms.TransformType transformType, PoseStack matrixStackIn, MultiBufferSource bufferIn, int combinedLightIn, int combinedOverlayIn) {
BlockEntityRenderDispatcher.instance.renderItem(this.te.get(), matrixStackIn, bufferIn, combinedLightIn, combinedOverlayIn);
this.blockEntityRenderDispatcher.renderItem(this.te.get(), matrixStackIn, bufferIn, combinedLightIn, combinedOverlayIn);
}
}

View File

@ -2,6 +2,6 @@
@MethodsReturnNonnullByDefault
package com.progwml6.ironchest.client.model.inventory;
import mcp.MethodsReturnNonnullByDefault;
import net.minecraft.MethodsReturnNonnullByDefault;
import javax.annotation.ParametersAreNonnullByDefault;

View File

@ -2,6 +2,6 @@
@MethodsReturnNonnullByDefault
package com.progwml6.ironchest.client.model;
import mcp.MethodsReturnNonnullByDefault;
import net.minecraft.MethodsReturnNonnullByDefault;
import javax.annotation.ParametersAreNonnullByDefault;

View File

@ -2,6 +2,6 @@
@MethodsReturnNonnullByDefault
package com.progwml6.ironchest.client;
import mcp.MethodsReturnNonnullByDefault;
import net.minecraft.MethodsReturnNonnullByDefault;
import javax.annotation.ParametersAreNonnullByDefault;

View File

@ -0,0 +1,213 @@
package com.progwml6.ironchest.client.render;
import com.google.common.primitives.SignedBytes;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
import com.progwml6.ironchest.IronChestsClientEvents;
import com.progwml6.ironchest.client.model.IronChestsModels;
import com.progwml6.ironchest.client.model.inventory.ModelItem;
import com.progwml6.ironchest.common.block.AbstractIronChestBlock;
import com.progwml6.ironchest.common.block.entity.CrystalChestBlockEntity;
import com.progwml6.ironchest.common.block.IronChestsTypes;
import com.progwml6.ironchest.common.block.entity.AbstractIronChestBlockEntity;
import it.unimi.dsi.fastutil.floats.Float2FloatFunction;
import it.unimi.dsi.fastutil.ints.Int2IntFunction;
import net.minecraft.client.model.geom.PartPose;
import net.minecraft.client.model.geom.builders.CubeListBuilder;
import net.minecraft.client.model.geom.builders.LayerDefinition;
import net.minecraft.client.model.geom.builders.MeshDefinition;
import net.minecraft.client.model.geom.builders.PartDefinition;
import net.minecraft.client.renderer.blockentity.BlockEntityRenderDispatcher;
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
import net.minecraft.client.renderer.entity.EntityRendererProvider;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.Sheets;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.entity.ItemEntityRenderer;
import net.minecraft.client.model.geom.ModelPart;
import net.minecraft.client.resources.model.Material;
import net.minecraft.client.renderer.blockentity.BrightnessCombiner;
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.entity.LidBlockEntity;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.DoubleBlockCombiner;
import net.minecraft.core.Direction;
import net.minecraft.world.phys.Vec3;
import com.mojang.math.Vector3f;
import net.minecraft.world.level.Level;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import java.util.Arrays;
import java.util.List;
@OnlyIn(Dist.CLIENT)
public class IronChestRenderer<T extends BlockEntity & LidBlockEntity> implements BlockEntityRenderer<T> {
private final ModelPart lid;
private final ModelPart bottom;
private final ModelPart lock;
private static ItemEntity customItem;
private static ItemEntityRenderer itemRenderer;
private final BlockEntityRenderDispatcher renderer;
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.7F, 0.45F, 0.3F), 3.0F),
new ModelItem(new Vector3f(0.3F, 0.45F, 0.7F), 3.0F),
new ModelItem(new Vector3f(0.7F, 0.45F, 0.7F), 3.0F),
new ModelItem(new Vector3f(0.3F, 0.1F, 0.3F), 3.0F),
new ModelItem(new Vector3f(0.7F, 0.1F, 0.3F), 3.0F),
new ModelItem(new Vector3f(0.3F, 0.1F, 0.7F), 3.0F),
new ModelItem(new Vector3f(0.7F, 0.1F, 0.7F), 3.0F),
new ModelItem(new Vector3f(0.5F, 0.32F, 0.5F), 3.0F)
);
public IronChestRenderer(BlockEntityRendererProvider.Context context) {
ModelPart modelPart = context.bakeLayer(IronChestsClientEvents.IRON_CHEST);
this.renderer = context.getBlockEntityRenderDispatcher();
this.bottom = modelPart.getChild("iron_bottom");
this.lid = modelPart.getChild("iron_lid");
this.lock = modelPart.getChild("iron_lock");
}
public static LayerDefinition createBodyLayer() {
MeshDefinition meshDefinition = new MeshDefinition();
PartDefinition partDefinition = meshDefinition.getRoot();
partDefinition.addOrReplaceChild("iron_bottom", CubeListBuilder.create().texOffs(0, 19).addBox(1.0F, 0.0F, 1.0F, 14.0F, 10.0F, 14.0F), PartPose.ZERO);
partDefinition.addOrReplaceChild("iron_lid", CubeListBuilder.create().texOffs(0, 0).addBox(1.0F, 0.0F, 0.0F, 14.0F, 5.0F, 14.0F), PartPose.offset(0.0F, 9.0F, 1.0F));
partDefinition.addOrReplaceChild("iron_lock", CubeListBuilder.create().texOffs(0, 0).addBox(7.0F, -1.0F, 15.0F, 2.0F, 4.0F, 1.0F), PartPose.offset(0.0F, 8.0F, 0.0F));
return LayerDefinition.create(meshDefinition, 64, 64);
}
@Override
public void render(T tileEntityIn, float partialTicks, PoseStack poseStack, MultiBufferSource bufferSource, int combinedLightIn, int combinedOverlayIn) {
AbstractIronChestBlockEntity tileEntity = (AbstractIronChestBlockEntity) tileEntityIn;
Level level = tileEntity.getLevel();
boolean useTileEntityBlockState = level != null;
BlockState blockState = useTileEntityBlockState ? tileEntity.getBlockState() : (BlockState) tileEntity.getBlockToUse().defaultBlockState().setValue(AbstractIronChestBlock.FACING, Direction.SOUTH);
Block block = blockState.getBlock();
IronChestsTypes chestType = IronChestsTypes.IRON;
IronChestsTypes actualType = AbstractIronChestBlock.getTypeFromBlock(block);
if (actualType != null) {
chestType = actualType;
}
if (block instanceof AbstractIronChestBlock abstractChestBlock) {
poseStack.pushPose();
float f = blockState.getValue(AbstractIronChestBlock.FACING).toYRot();
poseStack.translate(0.5D, 0.5D, 0.5D);
poseStack.mulPose(Vector3f.YP.rotationDegrees(-f));
poseStack.translate(-0.5D, -0.5D, -0.5D);
DoubleBlockCombiner.NeighborCombineResult<? extends AbstractIronChestBlockEntity> neighborCombineResult;
if (useTileEntityBlockState) {
neighborCombineResult = abstractChestBlock.combine(blockState, level, tileEntityIn.getBlockPos(), true);
} else {
neighborCombineResult = DoubleBlockCombiner.Combiner::acceptNone;
}
float openness = neighborCombineResult.<Float2FloatFunction>apply(AbstractIronChestBlock.opennessCombiner(tileEntity)).get(partialTicks);
openness = 1.0F - openness;
openness = 1.0F - openness * openness * openness;
int brightness = neighborCombineResult.<Int2IntFunction>apply(new BrightnessCombiner<>()).applyAsInt(combinedLightIn);
Material material = new Material(Sheets.CHEST_SHEET, IronChestsModels.chooseChestTexture(chestType));
VertexConsumer vertexConsumer = material.buffer(bufferSource, RenderType::entityCutout);
this.render(poseStack, vertexConsumer, this.lid, this.lock, this.bottom, openness, brightness, combinedOverlayIn);
poseStack.popPose();
if (chestType.isTransparent() && tileEntity instanceof CrystalChestBlockEntity crystalChestTileEntity && Vec3.atCenterOf(tileEntityIn.getBlockPos()).closerThan(this.renderer.camera.getPosition(), 128d)) {
float rotation = (float) (360D * (System.currentTimeMillis() & 0x3FFFL) / 0x3FFFL) - partialTicks;
if (customItem == null) {
assert level != null;
customItem = new ItemEntity(EntityType.ITEM, level);
}
for (int j = 0; j < MODEL_ITEMS.size() - 1; j++) {
renderItem(poseStack, bufferSource, crystalChestTileEntity.getTopItems().get(j), MODEL_ITEMS.get(j), rotation, combinedLightIn, partialTicks);
}
}
}
}
private void render(PoseStack poseStack, VertexConsumer vertexConsumer, ModelPart lid, ModelPart lock, ModelPart bottom, float openness, int brightness, int combinedOverlayIn) {
lid.xRot = -(openness * ((float) Math.PI / 2F));
lock.xRot = lid.xRot;
lid.render(poseStack, vertexConsumer, brightness, combinedOverlayIn);
lock.render(poseStack, vertexConsumer, brightness, combinedOverlayIn);
bottom.render(poseStack, vertexConsumer, brightness, combinedOverlayIn);
}
/**
* Renders a single item in a TESR
*
* @param matrices Matrix stack instance
* @param buffer Buffer instance
* @param item Item to render
* @param modelItem Model items for render information
* @param light Model light
*/
public static void renderItem(PoseStack matrices, MultiBufferSource buffer, ItemStack item, ModelItem modelItem, float rotation, int light, float partialTicks) {
// if no stack, skip
if (item.isEmpty()) return;
customItem.setItem(item);
// start rendering
matrices.pushPose();
Vector3f center = modelItem.getCenter();
matrices.translate(center.x(), center.y(), center.z());
matrices.mulPose(Vector3f.YP.rotation(rotation));
// scale
float scale = modelItem.getSizeScaled();
matrices.scale(scale, scale, scale);
// render the actual item
if (itemRenderer == null) {
itemRenderer = new ItemEntityRenderer(new EntityRendererProvider.Context(Minecraft.getInstance().getEntityRenderDispatcher(), Minecraft.getInstance().getItemRenderer(), Minecraft.getInstance().getResourceManager(), Minecraft.getInstance().getEntityModels(), Minecraft.getInstance().font)) {
@Override
public int getRenderAmount(ItemStack stack) {
return SignedBytes.saturatedCast(Math.min(stack.getCount() / 32, 15) + 1);
}
@Override
public boolean shouldBob() {
return false;
}
@Override
public boolean shouldSpreadItems() {
return true;
}
};
}
itemRenderer.render(customItem, 0F, partialTicks, matrices, buffer, light);
matrices.popPose();
}
}

View File

@ -1,192 +0,0 @@
package com.progwml6.ironchest.client.render;
import com.google.common.primitives.SignedBytes;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.vertex.VertexConsumer;
import com.progwml6.ironchest.client.model.IronChestsModels;
import com.progwml6.ironchest.client.model.inventory.ModelItem;
import com.progwml6.ironchest.common.block.GenericIronChestBlock;
import com.progwml6.ironchest.common.block.IronChestsTypes;
import com.progwml6.ironchest.common.block.tileentity.CrystalChestTileEntity;
import com.progwml6.ironchest.common.block.tileentity.GenericIronChestTileEntity;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.Sheets;
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.entity.ItemEntityRenderer;
import net.minecraft.client.renderer.model.ItemCameraTransforms;
import net.minecraft.client.model.geom.ModelPart;
import net.minecraft.client.resources.model.Material;
import net.minecraft.client.renderer.texture.OverlayTexture;
import net.minecraft.client.renderer.blockentity.BrightnessCombiner;
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
import net.minecraft.client.renderer.blockentity.BlockEntityRenderDispatcher;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.entity.LidBlockEntity;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.DoubleBlockCombiner;
import net.minecraft.core.Direction;
import net.minecraft.world.phys.Vec3;
import com.mojang.math.Vector3f;
import net.minecraft.world.level.Level;
import java.util.Arrays;
import java.util.List;
public class IronChestTileEntityRenderer<T extends BlockEntity & LidBlockEntity> extends BlockEntityRenderer<T> {
private final ModelPart chestLid;
private final ModelPart chestBottom;
private final ModelPart chestLock;
private static ItemEntity customItem;
private static ItemEntityRenderer itemRenderer;
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.7F, 0.45F, 0.3F), 3.0F),
new ModelItem(new Vector3f(0.3F, 0.45F, 0.7F), 3.0F),
new ModelItem(new Vector3f(0.7F, 0.45F, 0.7F), 3.0F),
new ModelItem(new Vector3f(0.3F, 0.1F, 0.3F), 3.0F),
new ModelItem(new Vector3f(0.7F, 0.1F, 0.3F), 3.0F),
new ModelItem(new Vector3f(0.3F, 0.1F, 0.7F), 3.0F),
new ModelItem(new Vector3f(0.7F, 0.1F, 0.7F), 3.0F),
new ModelItem(new Vector3f(0.5F, 0.32F, 0.5F), 3.0F)
);
public IronChestTileEntityRenderer(BlockEntityRenderDispatcher tileEntityRendererDispatcher) {
super(tileEntityRendererDispatcher);
this.chestBottom = new ModelPart(64, 64, 0, 19);
this.chestBottom.addBox(1.0F, 0.0F, 1.0F, 14.0F, 10.0F, 14.0F, 0.0F);
this.chestLid = new ModelPart(64, 64, 0, 0);
this.chestLid.addBox(1.0F, 0.0F, 0.0F, 14.0F, 5.0F, 14.0F, 0.0F);
this.chestLid.y = 9.0F;
this.chestLid.z = 1.0F;
this.chestLock = new ModelPart(64, 64, 0, 0);
this.chestLock.addBox(7.0F, -1.0F, 15.0F, 2.0F, 4.0F, 1.0F, 0.0F);
this.chestLock.y = 8.0F;
}
@Override
public void render(T tileEntityIn, float partialTicks, PoseStack matrixStackIn, MultiBufferSource bufferIn, int combinedLightIn, int combinedOverlayIn) {
GenericIronChestTileEntity tileEntity = (GenericIronChestTileEntity) tileEntityIn;
Level world = tileEntity.getLevel();
boolean flag = world != null;
BlockState blockstate = flag ? tileEntity.getBlockState() : (BlockState) tileEntity.getBlockToUse().defaultBlockState().setValue(GenericIronChestBlock.FACING, Direction.SOUTH);
Block block = blockstate.getBlock();
IronChestsTypes chestType = IronChestsTypes.IRON;
IronChestsTypes actualType = GenericIronChestBlock.getTypeFromBlock(block);
if (actualType != null) {
chestType = actualType;
}
if (block instanceof GenericIronChestBlock) {
GenericIronChestBlock ironChestBlock = (GenericIronChestBlock) block;
matrixStackIn.pushPose();
float f = blockstate.getValue(GenericIronChestBlock.FACING).toYRot();
matrixStackIn.translate(0.5D, 0.5D, 0.5D);
matrixStackIn.mulPose(Vector3f.YP.rotationDegrees(-f));
matrixStackIn.translate(-0.5D, -0.5D, -0.5D);
DoubleBlockCombiner.NeighborCombineResult<? extends GenericIronChestTileEntity> iCallbackWrapper;
if (flag) {
iCallbackWrapper = ironChestBlock.getWrapper(blockstate, world, tileEntity.getBlockPos(), true);
} else {
iCallbackWrapper = DoubleBlockCombiner.Combiner::acceptNone;
}
float f1 = iCallbackWrapper.apply(GenericIronChestBlock.getLid((LidBlockEntity) tileEntity)).get(partialTicks);
f1 = 1.0F - f1;
f1 = 1.0F - f1 * f1 * f1;
int i = iCallbackWrapper.apply(new BrightnessCombiner<>()).applyAsInt(combinedLightIn);
Material material = new Material(Sheets.CHEST_SHEET, IronChestsModels.chooseChestTexture(chestType));
VertexConsumer ivertexbuilder = material.buffer(bufferIn, RenderType::entityCutout);
this.handleModelRender(matrixStackIn, ivertexbuilder, this.chestLid, this.chestLock, this.chestBottom, f1, i, combinedOverlayIn);
matrixStackIn.popPose();
if (chestType.isTransparent() && tileEntity instanceof CrystalChestTileEntity && Vec3.atCenterOf(tileEntityIn.getBlockPos()).closerThan(this.renderer.camera.getPosition(), 128d)) {
float rotation = (float) (360D * (System.currentTimeMillis() & 0x3FFFL) / 0x3FFFL) - partialTicks;
CrystalChestTileEntity crystalChestTileEntity = (CrystalChestTileEntity) tileEntity;
if (customItem == null) {
assert world != null;
customItem = new ItemEntity(EntityType.ITEM, world);
}
for (int j = 0; j < MODEL_ITEMS.size() - 1; j++) {
renderItem(matrixStackIn, bufferIn, crystalChestTileEntity.getTopItems().get(j), MODEL_ITEMS.get(j), rotation, combinedLightIn, partialTicks);
}
}
}
}
private void handleModelRender(PoseStack matrixStackIn, VertexConsumer iVertexBuilder, ModelPart firstModel, ModelPart secondModel, ModelPart thirdModel, float f1, int p_228871_7_, int p_228871_8_) {
firstModel.xRot = -(f1 * ((float) Math.PI / 2F));
secondModel.xRot = firstModel.xRot;
firstModel.render(matrixStackIn, iVertexBuilder, p_228871_7_, p_228871_8_);
secondModel.render(matrixStackIn, iVertexBuilder, p_228871_7_, p_228871_8_);
thirdModel.render(matrixStackIn, iVertexBuilder, p_228871_7_, p_228871_8_);
}
/**
* Renders a single item in a TESR
*
* @param matrices Matrix stack instance
* @param buffer Buffer instance
* @param item Item to render
* @param modelItem Model items for render information
* @param light Model light
*/
public static void renderItem(PoseStack matrices, MultiBufferSource buffer, ItemStack item, ModelItem modelItem, float rotation, int light, float partialTicks) {
// if no stack, skip
if (item.isEmpty()) return;
customItem.setItem(item);
// start rendering
matrices.pushPose();
Vector3f center = modelItem.getCenter();
matrices.translate(center.x(), center.y(), center.z());
matrices.mulPose(Vector3f.YP.rotation(rotation));
// scale
float scale = modelItem.getSizeScaled();
matrices.scale(scale, scale, scale);
// render the actual item
if (itemRenderer == null) {
itemRenderer = new ItemEntityRenderer(Minecraft.getInstance().getEntityRenderDispatcher(), Minecraft.getInstance().getItemRenderer()) {
@Override
public int getRenderAmount(ItemStack stack) {
return SignedBytes.saturatedCast(Math.min(stack.getCount() / 32, 15) + 1);
}
@Override
public boolean shouldBob() {
return false;
}
@Override
public boolean shouldSpreadItems() {
return true;
}
};
}
itemRenderer.render(customItem, 0F, partialTicks, matrices, buffer, light);
matrices.popPose();
}
}

View File

@ -2,6 +2,6 @@
@MethodsReturnNonnullByDefault
package com.progwml6.ironchest.client.render;
import mcp.MethodsReturnNonnullByDefault;
import net.minecraft.MethodsReturnNonnullByDefault;
import javax.annotation.ParametersAreNonnullByDefault;

View File

@ -3,16 +3,17 @@ package com.progwml6.ironchest.client.screen;
import com.mojang.blaze3d.vertex.PoseStack;
import com.mojang.blaze3d.systems.RenderSystem;
import com.progwml6.ironchest.common.block.IronChestsTypes;
import com.progwml6.ironchest.common.inventory.IronChestContainer;
import com.progwml6.ironchest.common.inventory.IronChestMenu;
import net.minecraft.client.gui.screens.inventory.MenuAccess;
import net.minecraft.client.gui.screens.inventory.AbstractContainerScreen;
import net.minecraft.client.renderer.GameRenderer;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.network.chat.Component;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
@OnlyIn(Dist.CLIENT)
public class IronChestScreen extends AbstractContainerScreen<IronChestContainer> implements MenuAccess<IronChestContainer> {
public class IronChestScreen extends AbstractContainerScreen<IronChestMenu> implements MenuAccess<IronChestMenu> {
private final IronChestsTypes chestType;
@ -20,7 +21,7 @@ public class IronChestScreen extends AbstractContainerScreen<IronChestContainer>
private final int textureYSize;
public IronChestScreen(IronChestContainer container, Inventory playerInventory, Component title) {
public IronChestScreen(IronChestMenu container, Inventory playerInventory, Component title) {
super(container, playerInventory, title);
this.chestType = container.getChestType();
@ -43,19 +44,19 @@ public class IronChestScreen extends AbstractContainerScreen<IronChestContainer>
protected void renderLabels(PoseStack matrixStack, int mouseX, int mouseY) {
this.font.draw(matrixStack, this.title, 8.0F, 6.0F, 4210752);
this.font.draw(matrixStack, this.inventory.getDisplayName(), 8.0F, (float) (this.imageHeight - 96 + 2), 4210752);
this.font.draw(matrixStack, this.playerInventoryTitle, 8.0F, (float) (this.imageHeight - 96 + 2), 4210752);
}
@Override
protected void renderBg(PoseStack matrixStack, float partialTicks, int mouseX, int mouseY) {
RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F);
this.minecraft.getTextureManager().bind(this.chestType.guiTexture);
protected void renderBg(PoseStack poseStack, float partialTicks, int mouseX, int mouseY) {
RenderSystem.setShader(GameRenderer::getPositionTexShader);
RenderSystem.setShaderColor(1.0F, 1.0F, 1.0F, 1.0F);
RenderSystem.setShaderTexture(0, this.chestType.guiTexture);
int x = (this.width - this.imageWidth) / 2;
int y = (this.height - this.imageHeight) / 2;
blit(matrixStack, x, y, 0, 0, this.imageWidth, this.imageHeight, this.textureXSize, this.textureYSize);
blit(poseStack, x, y, 0, 0, this.imageWidth, this.imageHeight, this.textureXSize, this.textureYSize);
}
}

View File

@ -2,6 +2,6 @@
@MethodsReturnNonnullByDefault
package com.progwml6.ironchest.client.screen;
import mcp.MethodsReturnNonnullByDefault;
import net.minecraft.MethodsReturnNonnullByDefault;
import javax.annotation.ParametersAreNonnullByDefault;

View File

@ -1,31 +1,33 @@
package com.progwml6.ironchest.common.ai;
import com.progwml6.ironchest.IronChests;
import net.minecraft.world.entity.ai.goal.CatSitOnBlockGoal;
import net.minecraft.world.entity.ai.goal.WrappedGoal;
import net.minecraft.world.entity.animal.Cat;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.event.entity.living.LivingEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import java.util.HashSet;
@Mod.EventBusSubscriber(modid = IronChests.MOD_ID, bus = Mod.EventBusSubscriber.Bus.FORGE)
public class CatsSitOnChestsHandler {
@SubscribeEvent
public void changeSittingTaskForOcelots(final LivingEvent.LivingUpdateEvent evt) {
if (evt.getEntityLiving().tickCount < 5 && evt.getEntityLiving() instanceof Cat) {
static void changeSittingTaskForOcelots(final LivingEvent.LivingUpdateEvent evt) {
if (evt.getEntityLiving().tickCount < 5 && evt.getEntityLiving() instanceof Cat cat) {
HashSet<WrappedGoal> goals = new HashSet<>();
Cat catEntity = (Cat) evt.getEntityLiving();
for (WrappedGoal goal : catEntity.goalSelector.availableGoals) {
for (WrappedGoal goal : cat.goalSelector.availableGoals) {
if (goal.getGoal().getClass() == CatSitOnBlockGoal.class) {
goals.add(goal);
}
}
for (WrappedGoal goal : goals) {
catEntity.goalSelector.removeGoal(goal.getGoal());
catEntity.goalSelector.addGoal(goal.getPriority(), new IronChestCatSitOnBlockGoal(catEntity, 0.4F));
cat.goalSelector.removeGoal(goal.getGoal());
cat.goalSelector.addGoal(goal.getPriority(), new IronChestCatSitOnBlockGoal(cat, 0.4F));
}
}
}

View File

@ -1,7 +1,7 @@
package com.progwml6.ironchest.common.ai;
import com.progwml6.ironchest.common.block.GenericIronChestBlock;
import com.progwml6.ironchest.common.block.tileentity.GenericIronChestTileEntity;
import com.progwml6.ironchest.common.block.AbstractIronChestBlock;
import com.progwml6.ironchest.common.block.entity.AbstractIronChestBlockEntity;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.entity.ai.goal.CatSitOnBlockGoal;
@ -11,21 +11,20 @@ import net.minecraft.world.level.LevelReader;
public class IronChestCatSitOnBlockGoal extends CatSitOnBlockGoal {
public IronChestCatSitOnBlockGoal(Cat catEntity, double p_i50330_2_) {
super(catEntity, p_i50330_2_);
public IronChestCatSitOnBlockGoal(Cat cat, double p_i50330_2_) {
super(cat, p_i50330_2_);
}
@Override
protected boolean isValidTarget(LevelReader worldIn, BlockPos pos) {
if (!worldIn.isEmptyBlock(pos.above())) {
return false;
}
else {
} else {
BlockState blockstate = worldIn.getBlockState(pos);
Block block = blockstate.getBlock();
if (block instanceof GenericIronChestBlock) {
return GenericIronChestTileEntity.getPlayersUsing(worldIn, pos) < 1;
if (block instanceof AbstractIronChestBlock) {
return AbstractIronChestBlockEntity.getOpenCount(worldIn, pos) < 1;
}
return super.isValidTarget(worldIn, pos);

View File

@ -2,6 +2,6 @@
@MethodsReturnNonnullByDefault
package com.progwml6.ironchest.common.ai;
import mcp.MethodsReturnNonnullByDefault;
import net.minecraft.MethodsReturnNonnullByDefault;
import javax.annotation.ParametersAreNonnullByDefault;

View File

@ -0,0 +1,332 @@
package com.progwml6.ironchest.common.block;
import com.progwml6.ironchest.common.block.entity.AbstractIronChestBlockEntity;
import it.unimi.dsi.fastutil.floats.Float2FloatFunction;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.stats.Stat;
import net.minecraft.stats.Stats;
import net.minecraft.world.CompoundContainer;
import net.minecraft.world.Container;
import net.minecraft.world.Containers;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.InteractionResult;
import net.minecraft.world.MenuProvider;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.animal.Cat;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.block.BaseEntityBlock;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.DoubleBlockCombiner;
import net.minecraft.world.level.block.HorizontalDirectionalBlock;
import net.minecraft.world.level.block.Mirror;
import net.minecraft.world.level.block.RenderShape;
import net.minecraft.world.level.block.Rotation;
import net.minecraft.world.level.block.SimpleWaterloggedBlock;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityTicker;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.entity.LidBlockEntity;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.level.block.state.properties.BooleanProperty;
import net.minecraft.world.level.block.state.properties.DirectionProperty;
import net.minecraft.world.level.material.FluidState;
import net.minecraft.world.level.material.Fluids;
import net.minecraft.world.level.pathfinder.PathComputationType;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;
import javax.annotation.Nullable;
import java.util.List;
import java.util.Optional;
import java.util.Random;
import java.util.function.BiPredicate;
import java.util.function.Supplier;
public abstract class AbstractIronChestBlock extends BaseEntityBlock implements SimpleWaterloggedBlock {
public static final DirectionProperty FACING = HorizontalDirectionalBlock.FACING;
public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED;
protected static final VoxelShape AABB = Block.box(1.0D, 0.0D, 1.0D, 15.0D, 14.0D, 15.0D);
private static final DoubleBlockCombiner.Combiner<AbstractIronChestBlockEntity, Optional<Container>> CHEST_COMBINER = new DoubleBlockCombiner.Combiner<>() {
@Override
public Optional<Container> acceptDouble(AbstractIronChestBlockEntity blockEntityOne, AbstractIronChestBlockEntity blockEntityTwo) {
return Optional.of(new CompoundContainer(blockEntityOne, blockEntityTwo));
}
@Override
public Optional<Container> acceptSingle(AbstractIronChestBlockEntity blockEntity) {
return Optional.of(blockEntity);
}
@Override
public Optional<Container> acceptNone() {
return Optional.empty();
}
};
private static final DoubleBlockCombiner.Combiner<AbstractIronChestBlockEntity, Optional<MenuProvider>> MENU_PROVIDER_COMBINER = new DoubleBlockCombiner.Combiner<>() {
@Override
public Optional<MenuProvider> acceptDouble(AbstractIronChestBlockEntity blockEntityOne, AbstractIronChestBlockEntity blockEntityTwo) {
return Optional.empty();
}
@Override
public Optional<MenuProvider> acceptSingle(AbstractIronChestBlockEntity blockEntity) {
return Optional.of(blockEntity);
}
@Override
public Optional<MenuProvider> acceptNone() {
return Optional.empty();
}
};
private final IronChestsTypes type;
protected final Supplier<BlockEntityType<? extends AbstractIronChestBlockEntity>> blockEntityType;
public AbstractIronChestBlock(BlockBehaviour.Properties properties, Supplier<BlockEntityType<? extends AbstractIronChestBlockEntity>> blockEntityType, IronChestsTypes type) {
super(properties);
this.type = type;
this.blockEntityType = blockEntityType;
this.registerDefaultState(this.stateDefinition.any().setValue(FACING, Direction.NORTH).setValue(WATERLOGGED, Boolean.FALSE));
}
public static DoubleBlockCombiner.BlockType getBlockType(BlockState blockState) {
return DoubleBlockCombiner.BlockType.SINGLE;
}
@Override
public RenderShape getRenderShape(BlockState state) {
return RenderShape.ENTITYBLOCK_ANIMATED;
}
@Override
@Deprecated
public BlockState updateShape(BlockState blockState, Direction direction, BlockState facingState, LevelAccessor levelAccessor, BlockPos currentPos, BlockPos facingPos) {
if (blockState.getValue(WATERLOGGED)) {
levelAccessor.getLiquidTicks().scheduleTick(currentPos, Fluids.WATER, Fluids.WATER.getTickDelay(levelAccessor));
}
return super.updateShape(blockState, direction, facingState, levelAccessor, currentPos, facingPos);
}
@Override
@Deprecated
public VoxelShape getShape(BlockState blockState, BlockGetter blockGetter, BlockPos blockPos, CollisionContext context) {
return AABB;
}
public static Direction getConnectedDirection(BlockState blockState) {
return blockState.getValue(FACING).getCounterClockWise();
}
@Override
public BlockState getStateForPlacement(BlockPlaceContext context) {
Direction direction = context.getHorizontalDirection().getOpposite();
FluidState fluidState = context.getLevel().getFluidState(context.getClickedPos());
return this.defaultBlockState().setValue(FACING, direction).setValue(WATERLOGGED, fluidState.getType() == Fluids.WATER);
}
@Override
@Deprecated
public FluidState getFluidState(BlockState blockState) {
return blockState.getValue(WATERLOGGED) ? Fluids.WATER.getSource(false) : super.getFluidState(blockState);
}
@Override
public void setPlacedBy(Level level, BlockPos blockPos, BlockState blockState, @Nullable LivingEntity livingEntity, ItemStack itemStack) {
BlockEntity blockEntity = level.getBlockEntity(blockPos);
if (blockEntity instanceof AbstractIronChestBlockEntity) {
((AbstractIronChestBlockEntity) blockEntity).wasPlaced(livingEntity, itemStack);
if (itemStack.hasCustomHoverName()) {
((AbstractIronChestBlockEntity) blockEntity).setCustomName(itemStack.getHoverName());
}
}
}
@Override
@Deprecated
public void onRemove(BlockState blockState, Level level, BlockPos blockPos, BlockState newState, boolean isMoving) {
if (!blockState.is(newState.getBlock())) {
BlockEntity blockentity = level.getBlockEntity(blockPos);
if (blockentity instanceof Container) {
Containers.dropContents(level, blockPos, (Container) blockentity);
level.updateNeighbourForOutputSignal(blockPos, this);
}
super.onRemove(blockState, level, blockPos, newState, isMoving);
}
}
@Override
@Deprecated
public InteractionResult use(BlockState blockState, Level level, BlockPos blockPos, Player player, InteractionHand interactionHand, BlockHitResult blockHitResult) {
if (level.isClientSide) {
return InteractionResult.SUCCESS;
} else {
MenuProvider menuProvider = this.getMenuProvider(blockState, level, blockPos);
if (menuProvider != null) {
player.openMenu(menuProvider);
player.awardStat(this.getOpenChestStat());
}
return InteractionResult.CONSUME;
}
}
protected Stat<ResourceLocation> getOpenChestStat() {
return Stats.CUSTOM.get(Stats.OPEN_CHEST);
}
public BlockEntityType<? extends AbstractIronChestBlockEntity> blockEntityType() {
return this.blockEntityType.get();
}
@Nullable
public static Container getContainer(AbstractIronChestBlock chestBlock, BlockState blockState, Level level, BlockPos blockPos, boolean ignoreBlockedChest) {
return chestBlock.combine(blockState, level, blockPos, ignoreBlockedChest).<Optional<Container>>apply(CHEST_COMBINER).orElse((Container) null);
}
public DoubleBlockCombiner.NeighborCombineResult<? extends AbstractIronChestBlockEntity> combine(BlockState blockState, Level level, BlockPos blockPos, boolean ignoreBlockedChest) {
BiPredicate<LevelAccessor, BlockPos> biPredicate;
if (ignoreBlockedChest) {
biPredicate = (levelAccessor, blockPos1) -> {
return false;
};
} else {
biPredicate = AbstractIronChestBlock::isChestBlockedAt;
}
return DoubleBlockCombiner.combineWithNeigbour(this.blockEntityType.get(), AbstractIronChestBlock::getBlockType, AbstractIronChestBlock::getConnectedDirection, FACING, blockState, level, blockPos, biPredicate);
}
@Nullable
public MenuProvider getMenuProvider(BlockState blockState, Level level, BlockPos blockPos) {
return this.combine(blockState, level, blockPos, false).<Optional<MenuProvider>>apply(MENU_PROVIDER_COMBINER).orElse((MenuProvider) null);
}
public static DoubleBlockCombiner.Combiner<AbstractIronChestBlockEntity, Float2FloatFunction> opennessCombiner(final LidBlockEntity lidBlockEntity) {
return new DoubleBlockCombiner.Combiner<>() {
public Float2FloatFunction acceptDouble(AbstractIronChestBlockEntity blockEntityOne, AbstractIronChestBlockEntity blockEntityTwo) {
return (lidBlockEntity) -> Math.max(blockEntityOne.getOpenNess(lidBlockEntity), blockEntityTwo.getOpenNess(lidBlockEntity));
}
public Float2FloatFunction acceptSingle(AbstractIronChestBlockEntity blockEntity) {
return blockEntity::getOpenNess;
}
public Float2FloatFunction acceptNone() {
return lidBlockEntity::getOpenNess;
}
};
}
@Override
@Nullable
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level level, BlockState blockState, BlockEntityType<T> blockEntityType) {
return level.isClientSide ? createTickerHelper(blockEntityType, this.blockEntityType(), AbstractIronChestBlockEntity::lidAnimateTick) : null;
}
public static boolean isChestBlockedAt(LevelAccessor levelAccessor, BlockPos blockPos) {
return isBlockedChestByBlock(levelAccessor, blockPos) || isCatSittingOnChest(levelAccessor, blockPos);
}
private static boolean isBlockedChestByBlock(BlockGetter blockGetter, BlockPos blockPos) {
BlockPos above = blockPos.above();
return blockGetter.getBlockState(above).isRedstoneConductor(blockGetter, above);
}
private static boolean isCatSittingOnChest(LevelAccessor levelAccessor, BlockPos blockPos) {
List<Cat> list = levelAccessor.getEntitiesOfClass(Cat.class, new AABB((double) blockPos.getX(), (double) (blockPos.getY() + 1), (double) blockPos.getZ(), (double) (blockPos.getX() + 1), (double) (blockPos.getY() + 2), (double) (blockPos.getZ() + 1)));
if (!list.isEmpty()) {
for (Cat cat : list) {
if (cat.isInSittingPose()) {
return true;
}
}
}
return false;
}
@Override
public boolean hasAnalogOutputSignal(BlockState blockState) {
return true;
}
@Override
public int getAnalogOutputSignal(BlockState blockState, Level level, BlockPos blockPos) {
return AbstractContainerMenu.getRedstoneSignalFromContainer(getContainer(this, blockState, level, blockPos, false));
}
@Override
public BlockState rotate(BlockState blockState, Rotation rotation) {
return blockState.setValue(FACING, rotation.rotate(blockState.getValue(FACING)));
}
@Override
public BlockState mirror(BlockState blockState, Mirror mirror) {
return blockState.rotate(mirror.getRotation(blockState.getValue(FACING)));
}
@Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> blockBlockStateBuilder) {
blockBlockStateBuilder.add(FACING, WATERLOGGED);
}
@Override
public boolean isPathfindable(BlockState blockState, BlockGetter blockGetter, BlockPos blockPos, PathComputationType pathComputationType) {
return false;
}
@Override
public void tick(BlockState blockState, ServerLevel serverLevel, BlockPos blockPos, Random random) {
BlockEntity blockEntity = serverLevel.getBlockEntity(blockPos);
if (blockEntity instanceof AbstractIronChestBlockEntity) {
((AbstractIronChestBlockEntity) blockEntity).recheckOpen();
}
}
@Nullable
public static IronChestsTypes getTypeFromItem(Item itemIn) {
return getTypeFromBlock(Block.byItem(itemIn));
}
@Nullable
public static IronChestsTypes getTypeFromBlock(Block block) {
return block instanceof AbstractIronChestBlock ? ((AbstractIronChestBlock) block).getType() : null;
}
public IronChestsTypes getType() {
return this.type;
}
}

View File

@ -1,21 +1,22 @@
package com.progwml6.ironchest.common.block;
import com.progwml6.ironchest.common.block.tileentity.CopperChestTileEntity;
import com.progwml6.ironchest.common.block.tileentity.IronChestsTileEntityTypes;
import net.minecraft.world.level.block.state.BlockState;
import com.progwml6.ironchest.common.block.entity.CopperChestBlockEntity;
import com.progwml6.ironchest.common.block.entity.IronChestsBlockEntityTypes;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.BlockBehaviour.Properties;
import javax.annotation.Nullable;
public class CopperChestBlock extends GenericIronChestBlock {
public class CopperChestBlock extends AbstractIronChestBlock {
public CopperChestBlock(Properties properties) {
super(IronChestsTypes.COPPER, IronChestsTileEntityTypes.COPPER_CHEST::get, properties);
super(properties, IronChestsBlockEntityTypes.COPPER_CHEST::get, IronChestsTypes.COPPER);
}
@Nullable
@Override
public BlockEntity createTileEntity(BlockState state, BlockGetter world) {
return new CopperChestTileEntity();
public BlockEntity newBlockEntity(BlockPos blockPos, BlockState blockState) {
return new CopperChestBlockEntity(blockPos, blockState);
}
}

View File

@ -1,22 +1,33 @@
package com.progwml6.ironchest.common.block;
import com.progwml6.ironchest.common.block.tileentity.CrystalChestTileEntity;
import com.progwml6.ironchest.common.block.tileentity.IronChestsTileEntityTypes;
import net.minecraft.world.level.block.state.BlockState;
import com.progwml6.ironchest.common.block.entity.AbstractIronChestBlockEntity;
import com.progwml6.ironchest.common.block.entity.CrystalChestBlockEntity;
import com.progwml6.ironchest.common.block.entity.IronChestsBlockEntityTypes;
import com.progwml6.ironchest.common.block.entity.SilverChestBlockEntity;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.block.entity.BlockEntityTicker;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.BlockBehaviour.Properties;
import javax.annotation.Nullable;
public class CrystalChestBlock extends GenericIronChestBlock {
public class CrystalChestBlock extends AbstractIronChestBlock {
public CrystalChestBlock(Properties properties) {
super(IronChestsTypes.CRYSTAL, IronChestsTileEntityTypes.CRYSTAL_CHEST::get, properties);
super(properties, IronChestsBlockEntityTypes.CRYSTAL_CHEST::get, IronChestsTypes.CRYSTAL);
}
@Nullable
@Override
public BlockEntity newBlockEntity(BlockPos blockPos, BlockState blockState) {
return new CrystalChestBlockEntity(blockPos, blockState);
}
@Override
public BlockEntity createTileEntity(BlockState state, BlockGetter world) {
return new CrystalChestTileEntity();
@Nullable
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(Level level, BlockState blockState, BlockEntityType<T> blockEntityType) {
return level.isClientSide ? createTickerHelper(blockEntityType, this.blockEntityType(), AbstractIronChestBlockEntity::lidAnimateTick) : createTickerHelper(blockEntityType, this.blockEntityType(), CrystalChestBlockEntity::tick);
}
}

View File

@ -1,21 +1,22 @@
package com.progwml6.ironchest.common.block;
import com.progwml6.ironchest.common.block.tileentity.DiamondChestTileEntity;
import com.progwml6.ironchest.common.block.tileentity.IronChestsTileEntityTypes;
import net.minecraft.world.level.block.state.BlockState;
import com.progwml6.ironchest.common.block.entity.DiamondChestBlockEntity;
import com.progwml6.ironchest.common.block.entity.IronChestsBlockEntityTypes;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.BlockBehaviour.Properties;
import javax.annotation.Nullable;
public class DiamondChestBlock extends GenericIronChestBlock {
public class DiamondChestBlock extends AbstractIronChestBlock {
public DiamondChestBlock(Properties properties) {
super(IronChestsTypes.DIAMOND, IronChestsTileEntityTypes.DIAMOND_CHEST::get, properties);
super(properties, IronChestsBlockEntityTypes.DIAMOND_CHEST::get, IronChestsTypes.DIAMOND);
}
@Nullable
@Override
public BlockEntity createTileEntity(BlockState state, BlockGetter world) {
return new DiamondChestTileEntity();
public BlockEntity newBlockEntity(BlockPos blockPos, BlockState blockState) {
return new DiamondChestBlockEntity(blockPos, blockState);
}
}
}

View File

@ -1,22 +1,22 @@
package com.progwml6.ironchest.common.block;
import com.progwml6.ironchest.common.block.tileentity.DirtChestTileEntity;
import com.progwml6.ironchest.common.block.tileentity.IronChestsTileEntityTypes;
import com.progwml6.ironchest.common.block.tileentity.ObsidianChestTileEntity;
import net.minecraft.world.level.block.state.BlockState;
import com.progwml6.ironchest.common.block.entity.DirtChestBlockEntity;
import com.progwml6.ironchest.common.block.entity.IronChestsBlockEntityTypes;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.BlockBehaviour.Properties;
import javax.annotation.Nullable;
public class DirtChestBlock extends GenericIronChestBlock {
public class DirtChestBlock extends AbstractIronChestBlock {
public DirtChestBlock(Properties properties) {
super(IronChestsTypes.DIRT, IronChestsTileEntityTypes.DIRT_CHEST::get, properties);
super(properties, IronChestsBlockEntityTypes.DIRT_CHEST::get, IronChestsTypes.DIRT);
}
@Nullable
@Override
public BlockEntity createTileEntity(BlockState state, BlockGetter world) {
return new DirtChestTileEntity();
public BlockEntity newBlockEntity(BlockPos blockPos, BlockState blockState) {
return new DirtChestBlockEntity(blockPos, blockState);
}
}

View File

@ -1,279 +0,0 @@
package com.progwml6.ironchest.common.block;
import com.progwml6.ironchest.common.block.tileentity.GenericIronChestTileEntity;
import it.unimi.dsi.fastutil.floats.Float2FloatFunction;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.RenderShape;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.HorizontalDirectionalBlock;
import net.minecraft.world.level.block.SimpleWaterloggedBlock;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.animal.Cat;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.material.Fluids;
import net.minecraft.world.level.material.FluidState;
import net.minecraft.world.Container;
import net.minecraft.world.Containers;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.MenuProvider;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.pathfinder.PathComputationType;
import net.minecraft.world.level.block.state.properties.BooleanProperty;
import net.minecraft.world.level.block.state.properties.DirectionProperty;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.stats.Stat;
import net.minecraft.stats.Stats;
import net.minecraft.world.level.block.entity.LidBlockEntity;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.DoubleBlockCombiner;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.InteractionResult;
import net.minecraft.core.Direction;
import net.minecraft.world.InteractionHand;
import net.minecraft.world.level.block.Mirror;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.Rotation;
import net.minecraft.world.phys.AABB;
import net.minecraft.core.BlockPos;
import net.minecraft.world.phys.BlockHitResult;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.Level;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import javax.annotation.Nullable;
import java.util.List;
import java.util.function.BiPredicate;
import java.util.function.Supplier;
import net.minecraft.world.level.block.state.BlockBehaviour.Properties;
public class GenericIronChestBlock extends Block implements SimpleWaterloggedBlock {
public static final DirectionProperty FACING = HorizontalDirectionalBlock.FACING;
public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED;
protected static final VoxelShape IRON_CHEST_SHAPE = Block.box(1.0D, 0.0D, 1.0D, 15.0D, 14.0D, 15.0D);
private final IronChestsTypes type;
private final Supplier<BlockEntityType<? extends GenericIronChestTileEntity>> tileEntityTypeSupplier;
public GenericIronChestBlock(IronChestsTypes typeIn, Supplier<BlockEntityType<? extends GenericIronChestTileEntity>> tileEntityTypeSupplierIn, Properties propertiesIn) {
super(propertiesIn);
this.type = typeIn;
this.tileEntityTypeSupplier = tileEntityTypeSupplierIn;
this.registerDefaultState(this.stateDefinition.any().setValue(FACING, Direction.NORTH).setValue(WATERLOGGED, Boolean.valueOf(false)));
}
@Override
public RenderShape getRenderShape(BlockState state) {
return RenderShape.ENTITYBLOCK_ANIMATED;
}
@Override
public BlockState updateShape(BlockState stateIn, Direction facing, BlockState facingState, LevelAccessor worldIn, BlockPos currentPos, BlockPos facingPos) {
if (stateIn.getValue(WATERLOGGED)) {
worldIn.getLiquidTicks().scheduleTick(currentPos, Fluids.WATER, Fluids.WATER.getTickDelay(worldIn));
}
return super.updateShape(stateIn, facing, facingState, worldIn, currentPos, facingPos);
}
@Override
public VoxelShape getShape(BlockState state, BlockGetter worldIn, BlockPos pos, CollisionContext context) {
return IRON_CHEST_SHAPE;
}
@Override
public BlockState getStateForPlacement(BlockPlaceContext context) {
Direction direction = context.getHorizontalDirection().getOpposite();
FluidState ifluidstate = context.getLevel().getFluidState(context.getClickedPos());
return this.defaultBlockState().setValue(FACING, direction).setValue(WATERLOGGED, ifluidstate.getType() == Fluids.WATER);
}
@Override
public FluidState getFluidState(BlockState state) {
return state.getValue(WATERLOGGED) ? Fluids.WATER.getSource(false) : super.getFluidState(state);
}
@Override
public void setPlacedBy(Level worldIn, BlockPos pos, BlockState state, LivingEntity placer, ItemStack stack) {
BlockEntity tileentity = worldIn.getBlockEntity(pos);
if (tileentity instanceof GenericIronChestTileEntity) {
((GenericIronChestTileEntity) tileentity).wasPlaced(placer, stack);
if (stack.hasCustomHoverName()) {
((GenericIronChestTileEntity) tileentity).setCustomName(stack.getHoverName());
}
}
}
@Override
public void onRemove(BlockState state, Level worldIn, BlockPos pos, BlockState newState, boolean isMoving) {
if (state.getBlock() != newState.getBlock()) {
BlockEntity tileentity = worldIn.getBlockEntity(pos);
if (tileentity instanceof GenericIronChestTileEntity) {
((GenericIronChestTileEntity) tileentity).removeAdornments();
Containers.dropContents(worldIn, pos, (GenericIronChestTileEntity) tileentity);
worldIn.updateNeighbourForOutputSignal(pos, this);
}
super.onRemove(state, worldIn, pos, newState, isMoving);
}
}
@Override
public InteractionResult use(BlockState state, Level worldIn, BlockPos pos, Player player, InteractionHand handIn, BlockHitResult hit) {
if (!worldIn.isClientSide) {
MenuProvider inamedcontainerprovider = this.getMenuProvider(state, worldIn, pos);
if (inamedcontainerprovider != null) {
player.openMenu(inamedcontainerprovider);
player.awardStat(this.getOpenStat());
}
}
return InteractionResult.SUCCESS;
}
protected Stat<ResourceLocation> getOpenStat() {
return Stats.CUSTOM.get(Stats.OPEN_CHEST);
}
@Override
@Nullable
public MenuProvider getMenuProvider(BlockState state, Level world, BlockPos pos) {
BlockEntity tileentity = world.getBlockEntity(pos);
return tileentity instanceof MenuProvider ? (MenuProvider) tileentity : null;
}
@Override
public boolean hasTileEntity(BlockState state) {
return true;
}
@Override
public boolean triggerEvent(BlockState state, Level worldIn, BlockPos pos, int id, int param) {
super.triggerEvent(state, worldIn, pos, id, param);
BlockEntity tileentity = worldIn.getBlockEntity(pos);
return tileentity == null ? false : tileentity.triggerEvent(id, param);
}
private static boolean isBlocked(LevelAccessor iWorld, BlockPos blockPos) {
return isBelowSolidBlock(iWorld, blockPos) || isCatSittingOn(iWorld, blockPos);
}
private static boolean isBelowSolidBlock(BlockGetter iBlockReader, BlockPos worldIn) {
BlockPos blockpos = worldIn.above();
return iBlockReader.getBlockState(blockpos).isRedstoneConductor(iBlockReader, blockpos);
}
private static boolean isCatSittingOn(LevelAccessor iWorld, BlockPos blockPos) {
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()) {
for (Cat catentity : list) {
if (catentity.isSleeping()) {
return true;
}
}
}
return false;
}
@Override
public boolean hasAnalogOutputSignal(BlockState state) {
return true;
}
@Override
public int getAnalogOutputSignal(BlockState blockState, Level worldIn, BlockPos pos) {
return AbstractContainerMenu.getRedstoneSignalFromContainer((Container) worldIn.getBlockEntity(pos));
}
@Override
public BlockState rotate(BlockState state, Rotation rot) {
return state.setValue(FACING, rot.rotate(state.getValue(FACING)));
}
@Override
public BlockState mirror(BlockState state, Mirror mirrorIn) {
return state.rotate(mirrorIn.getRotation(state.getValue(FACING)));
}
@Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
builder.add(FACING, WATERLOGGED);
}
@Override
public boolean isPathfindable(BlockState state, BlockGetter worldIn, BlockPos pos, PathComputationType type) {
return false;
}
public static IronChestsTypes getTypeFromItem(Item itemIn) {
return getTypeFromBlock(Block.byItem(itemIn));
}
public static IronChestsTypes getTypeFromBlock(Block blockIn) {
return blockIn instanceof GenericIronChestBlock ? ((GenericIronChestBlock) blockIn).getType() : null;
}
public IronChestsTypes getType() {
return this.type;
}
@OnlyIn(Dist.CLIENT)
public static DoubleBlockCombiner.Combiner<GenericIronChestTileEntity, Float2FloatFunction> getLid(final LidBlockEntity p_226917_0_) {
return new DoubleBlockCombiner.Combiner<GenericIronChestTileEntity, Float2FloatFunction>() {
@Override
public Float2FloatFunction acceptDouble(GenericIronChestTileEntity p_225539_1_, GenericIronChestTileEntity p_225539_2_) {
return (p_226921_2_) -> {
return Math.max(p_225539_1_.getOpenNess(p_226921_2_), p_225539_2_.getOpenNess(p_226921_2_));
};
}
@Override
public Float2FloatFunction acceptSingle(GenericIronChestTileEntity p_225538_1_) {
return p_225538_1_::getOpenNess;
}
@Override
public Float2FloatFunction acceptNone() {
return p_226917_0_::getOpenNess;
}
};
}
public DoubleBlockCombiner.NeighborCombineResult<? extends GenericIronChestTileEntity> getWrapper(BlockState blockState, Level world, BlockPos blockPos, boolean p_225536_4_) {
BiPredicate<LevelAccessor, BlockPos> biPredicate;
if (p_225536_4_) {
biPredicate = (p_226918_0_, p_226918_1_) -> false;
}
else {
biPredicate = GenericIronChestBlock::isBlocked;
}
return DoubleBlockCombiner.combineWithNeigbour(this.tileEntityTypeSupplier.get(), GenericIronChestBlock::getMergerType, GenericIronChestBlock::getDirectionToAttached, FACING, blockState, world, blockPos, biPredicate);
}
public static DoubleBlockCombiner.BlockType getMergerType(BlockState blockState) {
return DoubleBlockCombiner.BlockType.SINGLE;
}
public static Direction getDirectionToAttached(BlockState state) {
Direction direction = state.getValue(FACING);
return direction.getCounterClockWise();
}
}

View File

@ -1,21 +1,22 @@
package com.progwml6.ironchest.common.block;
import com.progwml6.ironchest.common.block.tileentity.GoldChestTileEntity;
import com.progwml6.ironchest.common.block.tileentity.IronChestsTileEntityTypes;
import net.minecraft.world.level.block.state.BlockState;
import com.progwml6.ironchest.common.block.entity.GoldChestBlockEntity;
import com.progwml6.ironchest.common.block.entity.IronChestsBlockEntityTypes;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.BlockBehaviour.Properties;
import javax.annotation.Nullable;
public class GoldChestBlock extends GenericIronChestBlock {
public class GoldChestBlock extends AbstractIronChestBlock {
public GoldChestBlock(Properties properties) {
super(IronChestsTypes.GOLD, IronChestsTileEntityTypes.GOLD_CHEST::get, properties);
super(properties, IronChestsBlockEntityTypes.GOLD_CHEST::get, IronChestsTypes.GOLD);
}
@Nullable
@Override
public BlockEntity createTileEntity(BlockState state, BlockGetter world) {
return new GoldChestTileEntity();
public BlockEntity newBlockEntity(BlockPos blockPos, BlockState blockState) {
return new GoldChestBlockEntity(blockPos, blockState);
}
}

View File

@ -1,20 +1,23 @@
package com.progwml6.ironchest.common.block;
import com.progwml6.ironchest.common.block.tileentity.IronChestTileEntity;
import com.progwml6.ironchest.common.block.tileentity.IronChestsTileEntityTypes;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import com.progwml6.ironchest.common.block.entity.IronChestBlockEntity;
import com.progwml6.ironchest.common.block.entity.IronChestsBlockEntityTypes;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.block.state.BlockState;
public class IronChestBlock extends GenericIronChestBlock {
import javax.annotation.Nullable;
import java.util.function.Supplier;
public IronChestBlock(Block.Properties properties) {
super(IronChestsTypes.IRON, IronChestsTileEntityTypes.IRON_CHEST::get, properties);
public class IronChestBlock extends AbstractIronChestBlock {
public IronChestBlock(Properties properties) {
super(properties, IronChestsBlockEntityTypes.IRON_CHEST::get, IronChestsTypes.IRON);
}
@Nullable
@Override
public BlockEntity createTileEntity(BlockState state, BlockGetter world) {
return new IronChestTileEntity();
public BlockEntity newBlockEntity(BlockPos blockPos, BlockState blockState) {
return new IronChestBlockEntity(blockPos, blockState);
}
}

View File

@ -2,23 +2,26 @@ package com.progwml6.ironchest.common.block;
import com.progwml6.ironchest.IronChests;
import com.progwml6.ironchest.client.model.inventory.IronChestItemStackRenderer;
import com.progwml6.ironchest.common.block.tileentity.CopperChestTileEntity;
import com.progwml6.ironchest.common.block.tileentity.CrystalChestTileEntity;
import com.progwml6.ironchest.common.block.tileentity.DiamondChestTileEntity;
import com.progwml6.ironchest.common.block.tileentity.DirtChestTileEntity;
import com.progwml6.ironchest.common.block.tileentity.GoldChestTileEntity;
import com.progwml6.ironchest.common.block.tileentity.IronChestTileEntity;
import com.progwml6.ironchest.common.block.tileentity.ObsidianChestTileEntity;
import com.progwml6.ironchest.common.block.tileentity.SilverChestTileEntity;
import com.progwml6.ironchest.common.block.entity.CopperChestBlockEntity;
import com.progwml6.ironchest.common.block.entity.CrystalChestBlockEntity;
import com.progwml6.ironchest.common.block.entity.DiamondChestBlockEntity;
import com.progwml6.ironchest.common.block.entity.DirtChestBlockEntity;
import com.progwml6.ironchest.common.block.entity.GoldChestBlockEntity;
import com.progwml6.ironchest.common.block.entity.IronChestBlockEntity;
import com.progwml6.ironchest.common.block.entity.ObsidianChestBlockEntity;
import com.progwml6.ironchest.common.block.entity.SilverChestBlockEntity;
import com.progwml6.ironchest.common.item.IronChestBlockItem;
import com.progwml6.ironchest.common.item.IronChestsItems;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.material.Material;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.BlockEntityWithoutLevelRenderer;
import net.minecraft.core.BlockPos;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.material.Material;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.fml.RegistryObject;
import net.minecraftforge.fmllegacy.RegistryObject;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
@ -28,40 +31,42 @@ import java.util.function.Supplier;
public class IronChestsBlocks {
public static final DeferredRegister<Block> BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, IronChests.MODID);
public static final DeferredRegister<Block> BLOCKS = DeferredRegister.create(ForgeRegistries.BLOCKS, IronChests.MOD_ID);
public static final DeferredRegister<Item> ITEMS = IronChestsItems.ITEMS;
public static final RegistryObject<IronChestBlock> IRON_CHEST = register(
"iron_chest", () -> new IronChestBlock(Block.Properties.of(Material.METAL).strength(3.0F)),
() -> ironChestRenderer());
"iron_chest", () -> new IronChestBlock(Block.Properties.of(Material.METAL).strength(3.0F)),
() -> getIronChestItemStackRenderer());
public static final RegistryObject<GoldChestBlock> GOLD_CHEST = register(
"gold_chest", () -> new GoldChestBlock(Block.Properties.of(Material.METAL).strength(3.0F)),
() -> goldChestRenderer());
"gold_chest", () -> new GoldChestBlock(Block.Properties.of(Material.METAL).strength(3.0F)),
() -> getGoldChestItemStackRenderer());
public static final RegistryObject<DiamondChestBlock> DIAMOND_CHEST = register(
"diamond_chest", () -> new DiamondChestBlock(Block.Properties.of(Material.METAL).strength(3.0F)),
() -> diamondChestRenderer());
"diamond_chest", () -> new DiamondChestBlock(Block.Properties.of(Material.METAL).strength(3.0F)),
() -> getDiamondChestItemStackRenderer());
public static final RegistryObject<CopperChestBlock> COPPER_CHEST = register(
"copper_chest", () -> new CopperChestBlock(Block.Properties.of(Material.METAL).strength(3.0F)),
() -> copperChestRenderer());
"copper_chest", () -> new CopperChestBlock(Block.Properties.of(Material.METAL).strength(3.0F)),
() -> getCopperChestItemStackRenderer());
public static final RegistryObject<SilverChestBlock> SILVER_CHEST = register(
"silver_chest", () -> new SilverChestBlock(Block.Properties.of(Material.METAL).strength(3.0F)),
() -> silverChestRenderer());
"silver_chest", () -> new SilverChestBlock(Block.Properties.of(Material.METAL).strength(3.0F)),
() -> getSilverChestItemStackRenderer());
public static final RegistryObject<CrystalChestBlock> CRYSTAL_CHEST = register(
"crystal_chest", () -> new CrystalChestBlock(Block.Properties.of(Material.METAL).strength(3.0F)),
() -> crystalChestRenderer());
"crystal_chest", () -> new CrystalChestBlock(Block.Properties.of(Material.METAL).strength(3.0F)),
() -> getCrystalChestItemStackRenderer());
public static final RegistryObject<ObsidianChestBlock> OBSIDIAN_CHEST = register(
"obsidian_chest", () -> new ObsidianChestBlock(Block.Properties.of(Material.METAL).strength(3.0F, 10000.0F)),
() -> obsidianChestRenderer());
"obsidian_chest", () -> new ObsidianChestBlock(Block.Properties.of(Material.METAL).strength(3.0F)),
() -> getObsidianChestItemStackRenderer());
public static final RegistryObject<DirtChestBlock> DIRT_CHEST = register(
"dirt_chest", () -> new DirtChestBlock(Block.Properties.of(Material.METAL).strength(3.0F)),
() -> dirtChestRenderer());
"dirt_chest", () -> new DirtChestBlock(Block.Properties.of(Material.METAL).strength(3.0F)),
() -> getDirtChestItemStackRenderer());
//HELPERS
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));
@ -78,46 +83,46 @@ public class IronChestsBlocks {
}
private static Supplier<BlockItem> item(final RegistryObject<? extends Block> block, final Supplier<Callable<BlockEntityWithoutLevelRenderer>> renderMethod) {
return () -> new BlockItem(block.get(), new Item.Properties().tab(IronChests.IRONCHESTS_ITEM_GROUP).setISTER(renderMethod));
return () -> new IronChestBlockItem(block.get(), new Item.Properties().tab(IronChests.IRONCHESTS_ITEM_GROUP), renderMethod);
}
@OnlyIn(Dist.CLIENT)
private static Callable<BlockEntityWithoutLevelRenderer> ironChestRenderer() {
return () -> new IronChestItemStackRenderer(IronChestTileEntity::new);
public static Callable<BlockEntityWithoutLevelRenderer> getIronChestItemStackRenderer() {
return () -> new IronChestItemStackRenderer(Minecraft.getInstance().getBlockEntityRenderDispatcher(), Minecraft.getInstance().getEntityModels(), () -> new IronChestBlockEntity(BlockPos.ZERO, IronChestsBlocks.IRON_CHEST.get().defaultBlockState()));
}
@OnlyIn(Dist.CLIENT)
private static Callable<BlockEntityWithoutLevelRenderer> goldChestRenderer() {
return () -> new IronChestItemStackRenderer(GoldChestTileEntity::new);
public static Callable<BlockEntityWithoutLevelRenderer> getGoldChestItemStackRenderer() {
return () -> new IronChestItemStackRenderer(Minecraft.getInstance().getBlockEntityRenderDispatcher(), Minecraft.getInstance().getEntityModels(), () -> new GoldChestBlockEntity(BlockPos.ZERO, IronChestsBlocks.GOLD_CHEST.get().defaultBlockState()));
}
@OnlyIn(Dist.CLIENT)
private static Callable<BlockEntityWithoutLevelRenderer> diamondChestRenderer() {
return () -> new IronChestItemStackRenderer(DiamondChestTileEntity::new);
public static Callable<BlockEntityWithoutLevelRenderer> getDiamondChestItemStackRenderer() {
return () -> new IronChestItemStackRenderer(Minecraft.getInstance().getBlockEntityRenderDispatcher(), Minecraft.getInstance().getEntityModels(), () -> new DiamondChestBlockEntity(BlockPos.ZERO, IronChestsBlocks.DIAMOND_CHEST.get().defaultBlockState()));
}
@OnlyIn(Dist.CLIENT)
private static Callable<BlockEntityWithoutLevelRenderer> copperChestRenderer() {
return () -> new IronChestItemStackRenderer(CopperChestTileEntity::new);
public static Callable<BlockEntityWithoutLevelRenderer> getCopperChestItemStackRenderer() {
return () -> new IronChestItemStackRenderer(Minecraft.getInstance().getBlockEntityRenderDispatcher(), Minecraft.getInstance().getEntityModels(), () -> new CopperChestBlockEntity(BlockPos.ZERO, IronChestsBlocks.COPPER_CHEST.get().defaultBlockState()));
}
@OnlyIn(Dist.CLIENT)
private static Callable<BlockEntityWithoutLevelRenderer> silverChestRenderer() {
return () -> new IronChestItemStackRenderer(SilverChestTileEntity::new);
public static Callable<BlockEntityWithoutLevelRenderer> getSilverChestItemStackRenderer() {
return () -> new IronChestItemStackRenderer(Minecraft.getInstance().getBlockEntityRenderDispatcher(), Minecraft.getInstance().getEntityModels(), () -> new SilverChestBlockEntity(BlockPos.ZERO, IronChestsBlocks.SILVER_CHEST.get().defaultBlockState()));
}
@OnlyIn(Dist.CLIENT)
private static Callable<BlockEntityWithoutLevelRenderer> crystalChestRenderer() {
return () -> new IronChestItemStackRenderer(CrystalChestTileEntity::new);
public static Callable<BlockEntityWithoutLevelRenderer> getCrystalChestItemStackRenderer() {
return () -> new IronChestItemStackRenderer(Minecraft.getInstance().getBlockEntityRenderDispatcher(), Minecraft.getInstance().getEntityModels(), () -> new CrystalChestBlockEntity(BlockPos.ZERO, IronChestsBlocks.CRYSTAL_CHEST.get().defaultBlockState()));
}
@OnlyIn(Dist.CLIENT)
private static Callable<BlockEntityWithoutLevelRenderer> obsidianChestRenderer() {
return () -> new IronChestItemStackRenderer(ObsidianChestTileEntity::new);
public static Callable<BlockEntityWithoutLevelRenderer> getObsidianChestItemStackRenderer() {
return () -> new IronChestItemStackRenderer(Minecraft.getInstance().getBlockEntityRenderDispatcher(), Minecraft.getInstance().getEntityModels(), () -> new ObsidianChestBlockEntity(BlockPos.ZERO, IronChestsBlocks.OBSIDIAN_CHEST.get().defaultBlockState()));
}
@OnlyIn(Dist.CLIENT)
private static Callable<BlockEntityWithoutLevelRenderer> dirtChestRenderer() {
return () -> new IronChestItemStackRenderer(DirtChestTileEntity::new);
public static Callable<BlockEntityWithoutLevelRenderer> getDirtChestItemStackRenderer() {
return () -> new IronChestItemStackRenderer(Minecraft.getInstance().getBlockEntityRenderDispatcher(), Minecraft.getInstance().getEntityModels(), () -> new DirtChestBlockEntity(BlockPos.ZERO, IronChestsBlocks.DIRT_CHEST.get().defaultBlockState()));
}
}

View File

@ -1,19 +1,21 @@
package com.progwml6.ironchest.common.block;
import com.progwml6.ironchest.common.Util;
import com.progwml6.ironchest.common.block.tileentity.CopperChestTileEntity;
import com.progwml6.ironchest.common.block.tileentity.CrystalChestTileEntity;
import com.progwml6.ironchest.common.block.tileentity.DiamondChestTileEntity;
import com.progwml6.ironchest.common.block.tileentity.DirtChestTileEntity;
import com.progwml6.ironchest.common.block.tileentity.GenericIronChestTileEntity;
import com.progwml6.ironchest.common.block.tileentity.GoldChestTileEntity;
import com.progwml6.ironchest.common.block.tileentity.IronChestTileEntity;
import com.progwml6.ironchest.common.block.tileentity.ObsidianChestTileEntity;
import com.progwml6.ironchest.common.block.tileentity.SilverChestTileEntity;
import com.progwml6.ironchest.common.block.entity.AbstractIronChestBlockEntity;
import com.progwml6.ironchest.common.block.entity.CopperChestBlockEntity;
import com.progwml6.ironchest.common.block.entity.CrystalChestBlockEntity;
import com.progwml6.ironchest.common.block.entity.DiamondChestBlockEntity;
import com.progwml6.ironchest.common.block.entity.DirtChestBlockEntity;
import com.progwml6.ironchest.common.block.entity.GoldChestBlockEntity;
import com.progwml6.ironchest.common.block.entity.IronChestBlockEntity;
import com.progwml6.ironchest.common.block.entity.ObsidianChestBlockEntity;
import com.progwml6.ironchest.common.block.entity.SilverChestBlockEntity;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.minecraft.util.StringRepresentable;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.state.BlockState;
import javax.annotation.Nullable;
import java.util.Locale;
@ -76,48 +78,31 @@ public enum IronChestsTypes implements StringRepresentable {
}
public static Block get(IronChestsTypes type) {
switch (type) {
case IRON:
return IronChestsBlocks.IRON_CHEST.get();
case GOLD:
return IronChestsBlocks.GOLD_CHEST.get();
case DIAMOND:
return IronChestsBlocks.DIAMOND_CHEST.get();
case COPPER:
return IronChestsBlocks.COPPER_CHEST.get();
case SILVER:
return IronChestsBlocks.SILVER_CHEST.get();
case CRYSTAL:
return IronChestsBlocks.CRYSTAL_CHEST.get();
case OBSIDIAN:
return IronChestsBlocks.OBSIDIAN_CHEST.get();
case DIRT:
return IronChestsBlocks.DIRT_CHEST.get();
default:
return Blocks.CHEST;
}
return switch (type) {
case IRON -> IronChestsBlocks.IRON_CHEST.get();
case GOLD -> IronChestsBlocks.GOLD_CHEST.get();
case DIAMOND -> IronChestsBlocks.DIAMOND_CHEST.get();
case COPPER -> IronChestsBlocks.COPPER_CHEST.get();
case SILVER -> IronChestsBlocks.SILVER_CHEST.get();
case CRYSTAL -> IronChestsBlocks.CRYSTAL_CHEST.get();
case OBSIDIAN -> IronChestsBlocks.OBSIDIAN_CHEST.get();
case DIRT -> IronChestsBlocks.DIRT_CHEST.get();
default -> Blocks.CHEST;
};
}
public GenericIronChestTileEntity makeEntity() {
switch (this) {
case IRON:
return new IronChestTileEntity();
case GOLD:
return new GoldChestTileEntity();
case DIAMOND:
return new DiamondChestTileEntity();
case COPPER:
return new CopperChestTileEntity();
case SILVER:
return new SilverChestTileEntity();
case CRYSTAL:
return new CrystalChestTileEntity();
case OBSIDIAN:
return new ObsidianChestTileEntity();
case DIRT:
return new DirtChestTileEntity();
default:
return null;
}
@Nullable
public AbstractIronChestBlockEntity makeEntity(BlockPos blockPos, BlockState blockState) {
return switch (this) {
case IRON -> new IronChestBlockEntity(blockPos, blockState);
case GOLD -> new GoldChestBlockEntity(blockPos, blockState);
case DIAMOND -> new DiamondChestBlockEntity(blockPos, blockState);
case COPPER -> new CopperChestBlockEntity(blockPos, blockState);
case SILVER -> new SilverChestBlockEntity(blockPos, blockState);
case CRYSTAL -> new CrystalChestBlockEntity(blockPos, blockState);
case OBSIDIAN -> new ObsidianChestBlockEntity(blockPos, blockState);
case DIRT -> new DirtChestBlockEntity(blockPos, blockState);
default -> null;
};
}
}

View File

@ -1,22 +1,23 @@
package com.progwml6.ironchest.common.block;
import com.progwml6.ironchest.common.block.tileentity.IronChestsTileEntityTypes;
import com.progwml6.ironchest.common.block.tileentity.ObsidianChestTileEntity;
import com.progwml6.ironchest.common.block.tileentity.SilverChestTileEntity;
import net.minecraft.world.level.block.state.BlockState;
import com.progwml6.ironchest.common.block.entity.IronChestsBlockEntityTypes;
import com.progwml6.ironchest.common.block.entity.ObsidianChestBlockEntity;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.BlockBehaviour.Properties;
import javax.annotation.Nullable;
public class ObsidianChestBlock extends GenericIronChestBlock {
public class ObsidianChestBlock extends AbstractIronChestBlock {
public ObsidianChestBlock(Properties properties) {
super(IronChestsTypes.OBSIDIAN, IronChestsTileEntityTypes.OBSIDIAN_CHEST::get, properties);
public ObsidianChestBlock(BlockBehaviour.Properties properties) {
super(properties, IronChestsBlockEntityTypes.GOLD_CHEST::get, IronChestsTypes.GOLD);
}
@Nullable
@Override
public BlockEntity createTileEntity(BlockState state, BlockGetter world) {
return new ObsidianChestTileEntity();
public BlockEntity newBlockEntity(BlockPos blockPos, BlockState blockState) {
return new ObsidianChestBlockEntity(blockPos, blockState);
}
}

View File

@ -1,22 +1,22 @@
package com.progwml6.ironchest.common.block;
import com.progwml6.ironchest.common.block.tileentity.CopperChestTileEntity;
import com.progwml6.ironchest.common.block.tileentity.IronChestsTileEntityTypes;
import com.progwml6.ironchest.common.block.tileentity.SilverChestTileEntity;
import net.minecraft.world.level.block.state.BlockState;
import com.progwml6.ironchest.common.block.entity.IronChestsBlockEntityTypes;
import com.progwml6.ironchest.common.block.entity.SilverChestBlockEntity;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.BlockBehaviour.Properties;
import javax.annotation.Nullable;
public class SilverChestBlock extends GenericIronChestBlock {
public class SilverChestBlock extends AbstractIronChestBlock {
public SilverChestBlock(Properties properties) {
super(IronChestsTypes.SILVER, IronChestsTileEntityTypes.SILVER_CHEST::get, properties);
super(properties, IronChestsBlockEntityTypes.SILVER_CHEST::get, IronChestsTypes.SILVER);
}
@Nullable
@Override
public BlockEntity createTileEntity(BlockState state, BlockGetter world) {
return new SilverChestTileEntity();
public BlockEntity newBlockEntity(BlockPos blockPos, BlockState blockState) {
return new SilverChestBlockEntity(blockPos, blockState);
}
}

View File

@ -0,0 +1,216 @@
package com.progwml6.ironchest.common.block.entity;
import com.progwml6.ironchest.IronChests;
import com.progwml6.ironchest.common.block.AbstractIronChestBlock;
import com.progwml6.ironchest.common.block.IronChestsTypes;
import com.progwml6.ironchest.common.inventory.IronChestMenu;
import net.minecraft.core.BlockPos;
import net.minecraft.core.NonNullList;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.sounds.SoundSource;
import net.minecraft.world.CompoundContainer;
import net.minecraft.world.Container;
import net.minecraft.world.ContainerHelper;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.inventory.ChestMenu;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.world.level.block.entity.ChestLidController;
import net.minecraft.world.level.block.entity.ContainerOpenersCounter;
import net.minecraft.world.level.block.entity.LidBlockEntity;
import net.minecraft.world.level.block.entity.RandomizableContainerBlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import javax.annotation.Nullable;
import java.util.function.Supplier;
public abstract class AbstractIronChestBlockEntity extends RandomizableContainerBlockEntity implements LidBlockEntity {
private static final int EVENT_SET_OPEN_COUNT = 1;
private NonNullList<ItemStack> items;
private final ContainerOpenersCounter openersCounter = new ContainerOpenersCounter() {
protected void onOpen(Level level, BlockPos pos, BlockState blockState) {
AbstractIronChestBlockEntity.playSound(level, pos, blockState, SoundEvents.CHEST_OPEN);
}
protected void onClose(Level level, BlockPos pos, BlockState blockState) {
AbstractIronChestBlockEntity.playSound(level, pos, blockState, SoundEvents.CHEST_CLOSE);
}
protected void openerCountChanged(Level level, BlockPos pos, BlockState blockState, int previousCount, int newCount) {
AbstractIronChestBlockEntity.this.signalOpenCount(level, pos, blockState, previousCount, newCount);
}
protected boolean isOwnContainer(Player player) {
if (!(player.containerMenu instanceof IronChestMenu)) {
return false;
} else {
Container container = ((IronChestMenu) player.containerMenu).getContainer();
return container instanceof AbstractIronChestBlockEntity || container instanceof CompoundContainer && ((CompoundContainer) container).contains(AbstractIronChestBlockEntity.this);
}
}
};
private final ChestLidController chestLidController = new ChestLidController();
private final IronChestsTypes chestType;
private final Supplier<Block> blockToUse;
protected AbstractIronChestBlockEntity(BlockEntityType<?> blockEntityType, BlockPos blockPos, BlockState blockState, IronChestsTypes chestTypeIn, Supplier<Block> blockToUseIn) {
super(blockEntityType, blockPos, blockState);
this.items = NonNullList.<ItemStack>withSize(chestTypeIn.size, ItemStack.EMPTY);
this.chestType = chestTypeIn;
this.blockToUse = blockToUseIn;
}
@Override
public int getContainerSize() {
return this.getItems().size();
}
@Override
protected Component getDefaultName() {
return new TranslatableComponent(IronChests.MOD_ID + ".container." + this.chestType.getId() + "_chest");
}
@Override
public void load(CompoundTag compoundTag) {
super.load(compoundTag);
this.items = NonNullList.withSize(this.getContainerSize(), ItemStack.EMPTY);
if (!this.tryLoadLootTable(compoundTag)) {
ContainerHelper.loadAllItems(compoundTag, this.items);
}
}
@Override
public CompoundTag save(CompoundTag compoundTag) {
super.save(compoundTag);
if (!this.trySaveLootTable(compoundTag)) {
ContainerHelper.saveAllItems(compoundTag, this.items);
}
return compoundTag;
}
public static void lidAnimateTick(Level level, BlockPos blockPos, BlockState blockState, AbstractIronChestBlockEntity chestBlockEntity) {
chestBlockEntity.chestLidController.tickLid();
}
static void playSound(Level level, BlockPos blockPos, BlockState blockState, SoundEvent soundEvent) {
double d0 = (double) blockPos.getX() + 0.5D;
double d1 = (double) blockPos.getY() + 0.5D;
double d2 = (double) blockPos.getZ() + 0.5D;
level.playSound((Player) null, d0, d1, d2, soundEvent, SoundSource.BLOCKS, 0.5F, level.random.nextFloat() * 0.1F + 0.9F);
}
@Override
public boolean triggerEvent(int id, int type) {
if (id == 1) {
this.chestLidController.shouldBeOpen(type > 0);
return true;
} else {
return super.triggerEvent(id, type);
}
}
@Override
public void startOpen(Player player) {
if (!this.remove && !player.isSpectator()) {
this.openersCounter.incrementOpeners(player, this.getLevel(), this.getBlockPos(), this.getBlockState());
}
}
@Override
public void stopOpen(Player player) {
if (!this.remove && !player.isSpectator()) {
this.openersCounter.decrementOpeners(player, this.getLevel(), this.getBlockPos(), this.getBlockState());
}
}
@Override
public NonNullList<ItemStack> getItems() {
return this.items;
}
@Override
public void setItems(NonNullList<ItemStack> itemsIn) {
this.items = NonNullList.<ItemStack>withSize(this.getChestType().size, ItemStack.EMPTY);
for (int i = 0; i < itemsIn.size(); i++) {
if (i < this.items.size()) {
this.getItems().set(i, itemsIn.get(i));
}
}
}
@Override
public float getOpenNess(float partialTicks) {
return this.chestLidController.getOpenness(partialTicks);
}
public static int getOpenCount(BlockGetter blockGetter, BlockPos blockPos) {
BlockState blockstate = blockGetter.getBlockState(blockPos);
if (blockstate.hasBlockEntity()) {
BlockEntity blockentity = blockGetter.getBlockEntity(blockPos);
if (blockentity instanceof AbstractIronChestBlockEntity) {
return ((AbstractIronChestBlockEntity) blockentity).openersCounter.getOpenerCount();
}
}
return 0;
}
public void recheckOpen() {
if (!this.remove) {
this.openersCounter.recheckOpeners(this.getLevel(), this.getBlockPos(), this.getBlockState());
}
}
protected void signalOpenCount(Level level, BlockPos blockPos, BlockState blockState, int previousCount, int newCount) {
Block block = blockState.getBlock();
level.blockEvent(blockPos, block, 1, newCount);
}
public void wasPlaced(@Nullable LivingEntity livingEntity, ItemStack stack) {
}
public void removeAdornments() {
}
public IronChestsTypes getChestType() {
IronChestsTypes type = IronChestsTypes.IRON;
if (this.hasLevel()) {
IronChestsTypes typeFromBlock = AbstractIronChestBlock.getTypeFromBlock(this.getBlockState().getBlock());
if (typeFromBlock != null) {
type = typeFromBlock;
}
}
return type;
}
public Block getBlockToUse() {
return this.blockToUse.get();
}
}

View File

@ -0,0 +1,21 @@
package com.progwml6.ironchest.common.block.entity;
import com.progwml6.ironchest.common.block.IronChestsBlocks;
import com.progwml6.ironchest.common.block.IronChestsTypes;
import com.progwml6.ironchest.common.inventory.IronChestMenu;
import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.level.block.state.BlockState;
public class CopperChestBlockEntity extends AbstractIronChestBlockEntity {
public CopperChestBlockEntity(BlockPos blockPos, BlockState blockState) {
super(IronChestsBlockEntityTypes.COPPER_CHEST.get(), blockPos, blockState, IronChestsTypes.COPPER, IronChestsBlocks.COPPER_CHEST::get);
}
@Override
protected AbstractContainerMenu createMenu(int containerId, Inventory playerInventory) {
return IronChestMenu.createCopperContainer(containerId, playerInventory, this);
}
}

View File

@ -1,46 +1,43 @@
package com.progwml6.ironchest.common.block.tileentity;
package com.progwml6.ironchest.common.block.entity;
import com.progwml6.ironchest.common.block.IronChestsBlocks;
import com.progwml6.ironchest.common.block.IronChestsTypes;
import com.progwml6.ironchest.common.inventory.IronChestContainer;
import com.progwml6.ironchest.common.inventory.IronChestMenu;
import com.progwml6.ironchest.common.network.InventoryTopStacksSyncPacket;
import com.progwml6.ironchest.common.network.IronChestNetwork;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.core.BlockPos;
import net.minecraft.core.NonNullList;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.item.ItemStack;
import net.minecraft.core.NonNullList;
import net.minecraft.server.level.ServerLevel;
import net.minecraftforge.fml.network.PacketDistributor;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.BlockState;
import java.util.Collections;
public class CrystalChestTileEntity extends GenericIronChestTileEntity {
public class CrystalChestBlockEntity extends AbstractIronChestBlockEntity {
private NonNullList<ItemStack> topStacks;
private boolean inventoryTouched;
private boolean hadStuff;
public CrystalChestTileEntity() {
super(IronChestsTileEntityTypes.CRYSTAL_CHEST.get(), IronChestsTypes.CRYSTAL, IronChestsBlocks.CRYSTAL_CHEST::get);
this.topStacks = NonNullList.<ItemStack>withSize(8, ItemStack.EMPTY);
public CrystalChestBlockEntity(BlockPos blockPos, BlockState blockState) {
super(IronChestsBlockEntityTypes.CRYSTAL_CHEST.get(), blockPos, blockState, IronChestsTypes.CRYSTAL, IronChestsBlocks.CRYSTAL_CHEST::get);
this.topStacks = NonNullList.withSize(8, ItemStack.EMPTY);
}
@Override
protected AbstractContainerMenu createMenu(int id, Inventory playerInventory) {
return IronChestContainer.createCrystalContainer(id, playerInventory, this);
protected AbstractContainerMenu createMenu(int containerId, Inventory playerInventory) {
return IronChestMenu.createCrystalContainer(containerId, playerInventory, this);
}
@Override
public void tick() {
super.tick();
public static void tick(Level level, BlockPos blockPos, BlockState blockState, AbstractIronChestBlockEntity chestBlockEntity) {
if (chestBlockEntity instanceof CrystalChestBlockEntity crystalChestBlockEntity) {
if (!level.isClientSide && crystalChestBlockEntity.inventoryTouched) {
crystalChestBlockEntity.inventoryTouched = false;
if (!this.level.isClientSide && this.inventoryTouched) {
this.inventoryTouched = false;
this.sortTopStacks();
crystalChestBlockEntity.sortTopStacks();
}
}
}
@ -106,9 +103,9 @@ public class CrystalChestTileEntity extends GenericIronChestTileEntity {
}
if (this.level != null) {
BlockState iblockstate = this.level.getBlockState(this.worldPosition);
BlockState blockState = this.level.getBlockState(this.worldPosition);
this.level.sendBlockUpdated(this.worldPosition, iblockstate, iblockstate, 3);
this.level.sendBlockUpdated(this.worldPosition, blockState, blockState, 3);
}
return;
@ -116,43 +113,41 @@ public class CrystalChestTileEntity extends GenericIronChestTileEntity {
this.hadStuff = true;
Collections.sort(tempCopy, (stack1, stack2) -> {
tempCopy.sort((stack1, stack2) -> {
if (stack1.isEmpty()) {
return 1;
}
else if (stack2.isEmpty()) {
} else if (stack2.isEmpty()) {
return -1;
}
else {
} else {
return stack2.getCount() - stack1.getCount();
}
});
int p = 0;
int slot = 0;
for (ItemStack element : tempCopy) {
if (!element.isEmpty() && element.getCount() > 0) {
if (p == this.getTopItems().size()) {
for (ItemStack itemStack : tempCopy) {
if (!itemStack.isEmpty() && itemStack.getCount() > 0) {
if (slot == this.getTopItems().size()) {
break;
}
this.getTopItems().set(p, element);
this.getTopItems().set(slot, itemStack);
p++;
slot++;
}
}
for (int i = p; i < this.getTopItems().size(); i++) {
for (int i = slot; i < this.getTopItems().size(); i++) {
this.getTopItems().set(i, ItemStack.EMPTY);
}
if (this.level != null) {
BlockState iblockstate = this.level.getBlockState(this.worldPosition);
BlockState blockState = this.level.getBlockState(this.worldPosition);
this.level.sendBlockUpdated(this.worldPosition, iblockstate, iblockstate, 3);
this.level.sendBlockUpdated(this.worldPosition, blockState, blockState, 3);
}
sendTopStacksPacket();
this.sendTopStacksPacket();
}
public NonNullList<ItemStack> buildItemStackDataList() {
@ -164,8 +159,7 @@ public class CrystalChestTileEntity extends GenericIronChestTileEntity {
for (ItemStack is : this.topStacks) {
if (!is.isEmpty()) {
sortList.set(pos, is);
}
else {
} else {
sortList.set(pos, ItemStack.EMPTY);
}

View File

@ -0,0 +1,21 @@
package com.progwml6.ironchest.common.block.entity;
import com.progwml6.ironchest.common.block.IronChestsBlocks;
import com.progwml6.ironchest.common.block.IronChestsTypes;
import com.progwml6.ironchest.common.inventory.IronChestMenu;
import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.level.block.state.BlockState;
public class DiamondChestBlockEntity extends AbstractIronChestBlockEntity {
public DiamondChestBlockEntity(BlockPos blockPos, BlockState blockState) {
super(IronChestsBlockEntityTypes.DIAMOND_CHEST.get(), blockPos, blockState, IronChestsTypes.DIAMOND, IronChestsBlocks.DIAMOND_CHEST::get);
}
@Override
protected AbstractContainerMenu createMenu(int containerId, Inventory playerInventory) {
return IronChestMenu.createDiamondContainer(containerId, playerInventory, this);
}
}

View File

@ -1,43 +1,44 @@
package com.progwml6.ironchest.common.block.tileentity;
package com.progwml6.ironchest.common.block.entity;
import com.progwml6.ironchest.common.block.IronChestsBlocks;
import com.progwml6.ironchest.common.block.IronChestsTypes;
import com.progwml6.ironchest.common.inventory.IronChestContainer;
import com.progwml6.ironchest.common.inventory.IronChestMenu;
import net.minecraft.client.resources.language.I18n;
import net.minecraft.core.BlockPos;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.StringTag;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.nbt.ListTag;
import net.minecraft.nbt.StringTag;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.world.level.block.state.BlockState;
public class DirtChestTileEntity extends GenericIronChestTileEntity {
import javax.annotation.Nullable;
import java.util.Objects;
private static ItemStack dirtChest9000GuideBook = new ItemStack(Items.WRITTEN_BOOK);
public class DirtChestBlockEntity extends AbstractIronChestBlockEntity {
private static ItemStack DIRT_CHEST_BOOK = new ItemStack(Items.WRITTEN_BOOK);
private static boolean bookDataCreated = false;
public DirtChestTileEntity() {
super(IronChestsTileEntityTypes.DIRT_CHEST.get(), IronChestsTypes.DIRT, IronChestsBlocks.DIRT_CHEST::get);
if (!bookDataCreated) {
//createBookData();
}
public DirtChestBlockEntity(BlockPos blockPos, BlockState blockState) {
super(IronChestsBlockEntityTypes.DIRT_CHEST.get(), blockPos, blockState, IronChestsTypes.DIRT, IronChestsBlocks.DIRT_CHEST::get);
}
@Override
protected AbstractContainerMenu createMenu(int id, Inventory playerInventory) {
return IronChestContainer.createDirtContainer(id, playerInventory, this);
protected AbstractContainerMenu createMenu(int containerId, Inventory playerInventory) {
return IronChestMenu.createDirtContainer(containerId, playerInventory, this);
}
@Override
public void wasPlaced(LivingEntity entityLivingBase, ItemStack itemStack) {
if (!(itemStack.hasTag() && itemStack.getTag().getBoolean("been_placed"))) {
public void wasPlaced(@Nullable LivingEntity livingEntity, ItemStack itemStack) {
if (!(itemStack.hasTag() && Objects.requireNonNull(itemStack.getTag()).getBoolean("been_placed"))) {
//TODO FIX BOOK
//this.setInventorySlotContents(0, dirtChest9000GuideBook.copy());
//this.setInventorySlotContents(0, DIRT_CHEST_BOOK.copy());
}
if (!bookDataCreated) {
@ -47,15 +48,15 @@ public class DirtChestTileEntity extends GenericIronChestTileEntity {
@Override
public void removeAdornments() {
if (!this.getItems().get(0).isEmpty() && this.getItems().get(0).sameItem(dirtChest9000GuideBook)) {
if (!this.getItems().get(0).isEmpty() && this.getItems().get(0).sameItem(DIRT_CHEST_BOOK)) {
this.getItems().set(0, ItemStack.EMPTY);
}
}
private static void createBookData() {
dirtChest9000GuideBook.addTagElement("author", StringTag.valueOf("cpw"));
DIRT_CHEST_BOOK.addTagElement("author", StringTag.valueOf("cpw"));
dirtChest9000GuideBook.addTagElement("title", StringTag.valueOf(I18n.get("book.ironchest.dirtchest9000.title")));
DIRT_CHEST_BOOK.addTagElement("title", StringTag.valueOf(I18n.get("book.ironchest.dirtchest9000.title")));
ListTag pages = new ListTag();
pages.add(StringTag.valueOf(Component.Serializer.toJson(new TranslatableComponent("book.ironchest.dirtchest9000.page1"))));
@ -64,7 +65,7 @@ public class DirtChestTileEntity extends GenericIronChestTileEntity {
pages.add(StringTag.valueOf(Component.Serializer.toJson(new TranslatableComponent("book.ironchest.dirtchest9000.page4"))));
pages.add(StringTag.valueOf(Component.Serializer.toJson(new TranslatableComponent("book.ironchest.dirtchest9000.page5"))));
dirtChest9000GuideBook.addTagElement("pages", pages);
DIRT_CHEST_BOOK.addTagElement("pages", pages);
bookDataCreated = true;
}

View File

@ -0,0 +1,21 @@
package com.progwml6.ironchest.common.block.entity;
import com.progwml6.ironchest.common.block.IronChestsBlocks;
import com.progwml6.ironchest.common.block.IronChestsTypes;
import com.progwml6.ironchest.common.inventory.IronChestMenu;
import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.level.block.state.BlockState;
public class GoldChestBlockEntity extends AbstractIronChestBlockEntity {
public GoldChestBlockEntity(BlockPos blockPos, BlockState blockState) {
super(IronChestsBlockEntityTypes.GOLD_CHEST.get(), blockPos, blockState, IronChestsTypes.GOLD, IronChestsBlocks.GOLD_CHEST::get);
}
@Override
protected AbstractContainerMenu createMenu(int containerId, Inventory playerInventory) {
return IronChestMenu.createGoldContainer(containerId, playerInventory, this);
}
}

View File

@ -0,0 +1,21 @@
package com.progwml6.ironchest.common.block.entity;
import com.progwml6.ironchest.common.block.IronChestsBlocks;
import com.progwml6.ironchest.common.block.IronChestsTypes;
import com.progwml6.ironchest.common.inventory.IronChestMenu;
import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.level.block.state.BlockState;
public class IronChestBlockEntity extends AbstractIronChestBlockEntity {
public IronChestBlockEntity(BlockPos blockPos, BlockState blockState) {
super(IronChestsBlockEntityTypes.IRON_CHEST.get(), blockPos, blockState, IronChestsTypes.IRON, IronChestsBlocks.IRON_CHEST::get);
}
@Override
protected AbstractContainerMenu createMenu(int containerId, Inventory playerInventory) {
return IronChestMenu.createIronContainer(containerId, playerInventory, this);
}
}

View File

@ -0,0 +1,36 @@
package com.progwml6.ironchest.common.block.entity;
import com.progwml6.ironchest.IronChests;
import com.progwml6.ironchest.common.block.IronChestsBlocks;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraftforge.fmllegacy.RegistryObject;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
public class IronChestsBlockEntityTypes {
public static final DeferredRegister<BlockEntityType<?>> BLOCK_ENTITIES = DeferredRegister.create(ForgeRegistries.BLOCK_ENTITIES, IronChests.MOD_ID);
public static final RegistryObject<BlockEntityType<IronChestBlockEntity>> IRON_CHEST = BLOCK_ENTITIES.register(
"iron_chest", () -> BlockEntityType.Builder.of(IronChestBlockEntity::new, IronChestsBlocks.IRON_CHEST.get()).build(null));
public static final RegistryObject<BlockEntityType<GoldChestBlockEntity>> GOLD_CHEST = BLOCK_ENTITIES.register(
"gold_chest", () -> BlockEntityType.Builder.of(GoldChestBlockEntity::new, IronChestsBlocks.GOLD_CHEST.get()).build(null));
public static final RegistryObject<BlockEntityType<DiamondChestBlockEntity>> DIAMOND_CHEST = BLOCK_ENTITIES.register(
"diamond_chest", () -> BlockEntityType.Builder.of(DiamondChestBlockEntity::new, IronChestsBlocks.DIAMOND_CHEST.get()).build(null));
public static final RegistryObject<BlockEntityType<CopperChestBlockEntity>> COPPER_CHEST = BLOCK_ENTITIES.register(
"copper_chest", () -> BlockEntityType.Builder.of(CopperChestBlockEntity::new, IronChestsBlocks.COPPER_CHEST.get()).build(null));
public static final RegistryObject<BlockEntityType<SilverChestBlockEntity>> SILVER_CHEST = BLOCK_ENTITIES.register(
"silver_chest", () -> BlockEntityType.Builder.of(SilverChestBlockEntity::new, IronChestsBlocks.SILVER_CHEST.get()).build(null));
public static final RegistryObject<BlockEntityType<CrystalChestBlockEntity>> CRYSTAL_CHEST = BLOCK_ENTITIES.register(
"crystal_chest", () -> BlockEntityType.Builder.of(CrystalChestBlockEntity::new, IronChestsBlocks.CRYSTAL_CHEST.get()).build(null));
public static final RegistryObject<BlockEntityType<ObsidianChestBlockEntity>> OBSIDIAN_CHEST = BLOCK_ENTITIES.register(
"obsidian_chest", () -> BlockEntityType.Builder.of(ObsidianChestBlockEntity::new, IronChestsBlocks.OBSIDIAN_CHEST.get()).build(null));
public static final RegistryObject<BlockEntityType<DirtChestBlockEntity>> DIRT_CHEST = BLOCK_ENTITIES.register(
"dirt_chest", () -> BlockEntityType.Builder.of(DirtChestBlockEntity::new, IronChestsBlocks.DIRT_CHEST.get()).build(null));
}

View File

@ -0,0 +1,21 @@
package com.progwml6.ironchest.common.block.entity;
import com.progwml6.ironchest.common.block.IronChestsBlocks;
import com.progwml6.ironchest.common.block.IronChestsTypes;
import com.progwml6.ironchest.common.inventory.IronChestMenu;
import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.level.block.state.BlockState;
public class ObsidianChestBlockEntity extends AbstractIronChestBlockEntity {
public ObsidianChestBlockEntity(BlockPos blockPos, BlockState blockState) {
super(IronChestsBlockEntityTypes.OBSIDIAN_CHEST.get(), blockPos, blockState, IronChestsTypes.OBSIDIAN, IronChestsBlocks.OBSIDIAN_CHEST::get);
}
@Override
protected AbstractContainerMenu createMenu(int containerId, Inventory playerInventory) {
return IronChestMenu.createObsidianContainer(containerId, playerInventory, this);
}
}

View File

@ -0,0 +1,21 @@
package com.progwml6.ironchest.common.block.entity;
import com.progwml6.ironchest.common.block.IronChestsBlocks;
import com.progwml6.ironchest.common.block.IronChestsTypes;
import com.progwml6.ironchest.common.inventory.IronChestMenu;
import net.minecraft.core.BlockPos;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.level.block.state.BlockState;
public class SilverChestBlockEntity extends AbstractIronChestBlockEntity {
public SilverChestBlockEntity(BlockPos blockPos, BlockState blockState) {
super(IronChestsBlockEntityTypes.SILVER_CHEST.get(), blockPos, blockState, IronChestsTypes.SILVER, IronChestsBlocks.SILVER_CHEST::get);
}
@Override
protected AbstractContainerMenu createMenu(int containerId, Inventory playerInventory) {
return IronChestMenu.createSilverContainer(containerId, playerInventory, this);
}
}

View File

@ -1,7 +1,7 @@
@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
package com.progwml6.ironchest.common.block.tileentity;
package com.progwml6.ironchest.common.block.entity;
import mcp.MethodsReturnNonnullByDefault;
import net.minecraft.MethodsReturnNonnullByDefault;
import javax.annotation.ParametersAreNonnullByDefault;

View File

@ -2,6 +2,6 @@
@MethodsReturnNonnullByDefault
package com.progwml6.ironchest.common.block;
import mcp.MethodsReturnNonnullByDefault;
import net.minecraft.MethodsReturnNonnullByDefault;
import javax.annotation.ParametersAreNonnullByDefault;

View File

@ -1,19 +0,0 @@
package com.progwml6.ironchest.common.block.tileentity;
import com.progwml6.ironchest.common.block.IronChestsBlocks;
import com.progwml6.ironchest.common.block.IronChestsTypes;
import com.progwml6.ironchest.common.inventory.IronChestContainer;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.inventory.AbstractContainerMenu;
public class CopperChestTileEntity extends GenericIronChestTileEntity {
public CopperChestTileEntity() {
super(IronChestsTileEntityTypes.COPPER_CHEST.get(), IronChestsTypes.COPPER, IronChestsBlocks.COPPER_CHEST::get);
}
@Override
protected AbstractContainerMenu createMenu(int id, Inventory playerInventory) {
return IronChestContainer.createCopperContainer(id, playerInventory, this);
}
}

View File

@ -1,19 +0,0 @@
package com.progwml6.ironchest.common.block.tileentity;
import com.progwml6.ironchest.common.block.IronChestsBlocks;
import com.progwml6.ironchest.common.block.IronChestsTypes;
import com.progwml6.ironchest.common.inventory.IronChestContainer;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.inventory.AbstractContainerMenu;
public class DiamondChestTileEntity extends GenericIronChestTileEntity {
public DiamondChestTileEntity() {
super(IronChestsTileEntityTypes.DIAMOND_CHEST.get(), IronChestsTypes.DIAMOND, IronChestsBlocks.DIAMOND_CHEST::get);
}
@Override
protected AbstractContainerMenu createMenu(int id, Inventory playerInventory) {
return IronChestContainer.createDiamondContainer(id, playerInventory, this);
}
}

View File

@ -1,267 +0,0 @@
package com.progwml6.ironchest.common.block.tileentity;
import com.progwml6.ironchest.IronChests;
import com.progwml6.ironchest.common.block.GenericIronChestBlock;
import com.progwml6.ironchest.common.block.IronChestsTypes;
import com.progwml6.ironchest.common.inventory.IronChestContainer;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.ContainerHelper;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.item.ItemStack;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.world.level.block.entity.LidBlockEntity;
import net.minecraft.world.level.block.entity.TickableBlockEntity;
import net.minecraft.world.level.block.entity.RandomizableContainerBlockEntity;
import net.minecraft.world.level.block.entity.BaseContainerBlockEntity;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.entity.BlockEntityType;
import net.minecraft.core.NonNullList;
import net.minecraft.sounds.SoundSource;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.sounds.SoundEvents;
import net.minecraft.world.phys.AABB;
import net.minecraft.core.BlockPos;
import net.minecraft.util.Mth;
import net.minecraft.network.chat.Component;
import net.minecraft.network.chat.TranslatableComponent;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import java.util.function.Supplier;
@OnlyIn(value = Dist.CLIENT, _interface = LidBlockEntity.class)
public class GenericIronChestTileEntity extends RandomizableContainerBlockEntity implements LidBlockEntity, TickableBlockEntity {
private NonNullList<ItemStack> chestContents;
protected float lidAngle;
protected float prevLidAngle;
protected int numPlayersUsing;
private int ticksSinceSync;
private IronChestsTypes chestType;
private Supplier<Block> blockToUse;
protected GenericIronChestTileEntity(BlockEntityType<?> typeIn, IronChestsTypes chestTypeIn, Supplier<Block> blockToUseIn) {
super(typeIn);
this.chestContents = NonNullList.<ItemStack>withSize(chestTypeIn.size, ItemStack.EMPTY);
this.chestType = chestTypeIn;
this.blockToUse = blockToUseIn;
}
@Override
public int getContainerSize() {
return this.getItems().size();
}
@Override
public boolean isEmpty() {
for (ItemStack itemstack : this.chestContents) {
if (!itemstack.isEmpty()) {
return false;
}
}
return true;
}
@Override
protected Component getDefaultName() {
return new TranslatableComponent(IronChests.MODID + ".container." + this.chestType.getId() + "_chest");
}
@Override
public void load(BlockState state, CompoundTag compound) {
super.load(state, compound);
this.chestContents = NonNullList.withSize(this.getContainerSize(), ItemStack.EMPTY);
if (!this.tryLoadLootTable(compound)) {
ContainerHelper.loadAllItems(compound, this.chestContents);
}
}
@Override
public CompoundTag save(CompoundTag compound) {
super.save(compound);
if (!this.trySaveLootTable(compound)) {
ContainerHelper.saveAllItems(compound, this.chestContents);
}
return compound;
}
@Override
public void tick() {
int i = this.worldPosition.getX();
int j = this.worldPosition.getY();
int k = this.worldPosition.getZ();
++this.ticksSinceSync;
this.numPlayersUsing = getNumberOfPlayersUsing(this.level, this, this.ticksSinceSync, i, j, k, this.numPlayersUsing);
this.prevLidAngle = this.lidAngle;
float f = 0.1F;
if (this.numPlayersUsing > 0 && this.lidAngle == 0.0F) {
this.playSound(SoundEvents.CHEST_OPEN);
}
if (this.numPlayersUsing == 0 && this.lidAngle > 0.0F || this.numPlayersUsing > 0 && this.lidAngle < 1.0F) {
float f1 = this.lidAngle;
if (this.numPlayersUsing > 0) {
this.lidAngle += 0.1F;
}
else {
this.lidAngle -= 0.1F;
}
if (this.lidAngle > 1.0F) {
this.lidAngle = 1.0F;
}
float f2 = 0.5F;
if (this.lidAngle < 0.5F && f1 >= 0.5F) {
this.playSound(SoundEvents.CHEST_CLOSE);
}
if (this.lidAngle < 0.0F) {
this.lidAngle = 0.0F;
}
}
}
public static int getNumberOfPlayersUsing(Level worldIn, BaseContainerBlockEntity lockableTileEntity, int ticksSinceSync, int x, int y, int z, int numPlayersUsing) {
if (!worldIn.isClientSide && numPlayersUsing != 0 && (ticksSinceSync + x + y + z) % 200 == 0) {
numPlayersUsing = getNumberOfPlayersUsing(worldIn, lockableTileEntity, x, y, z);
}
return numPlayersUsing;
}
public static int getNumberOfPlayersUsing(Level world, BaseContainerBlockEntity lockableTileEntity, int x, int y, int z) {
int i = 0;
for (Player playerentity : world.getEntitiesOfClass(Player.class, new AABB((double) ((float) x - 5.0F), (double) ((float) y - 5.0F), (double) ((float) z - 5.0F), (double) ((float) (x + 1) + 5.0F), (double) ((float) (y + 1) + 5.0F), (double) ((float) (z + 1) + 5.0F)))) {
if (playerentity.containerMenu instanceof IronChestContainer) {
++i;
}
}
return i;
}
private void playSound(SoundEvent soundIn) {
double d0 = (double) this.worldPosition.getX() + 0.5D;
double d1 = (double) this.worldPosition.getY() + 0.5D;
double d2 = (double) this.worldPosition.getZ() + 0.5D;
this.level.playSound((Player) null, d0, d1, d2, soundIn, SoundSource.BLOCKS, 0.5F, this.level.random.nextFloat() * 0.1F + 0.9F);
}
@Override
public boolean triggerEvent(int id, int type) {
if (id == 1) {
this.numPlayersUsing = type;
return true;
}
else {
return super.triggerEvent(id, type);
}
}
@Override
public void startOpen(Player player) {
if (!player.isSpectator()) {
if (this.numPlayersUsing < 0) {
this.numPlayersUsing = 0;
}
++this.numPlayersUsing;
this.onOpenOrClose();
}
}
@Override
public void stopOpen(Player player) {
if (!player.isSpectator()) {
--this.numPlayersUsing;
this.onOpenOrClose();
}
}
protected void onOpenOrClose() {
Block block = this.getBlockState().getBlock();
if (block instanceof GenericIronChestBlock) {
this.level.blockEvent(this.worldPosition, block, 1, this.numPlayersUsing);
this.level.updateNeighborsAt(this.worldPosition, block);
}
}
@Override
public NonNullList<ItemStack> getItems() {
return this.chestContents;
}
@Override
public void setItems(NonNullList<ItemStack> itemsIn) {
this.chestContents = NonNullList.<ItemStack>withSize(this.getChestType().size, ItemStack.EMPTY);
for (int i = 0; i < itemsIn.size(); i++) {
if (i < this.chestContents.size()) {
this.getItems().set(i, itemsIn.get(i));
}
}
}
@Override
@OnlyIn(Dist.CLIENT)
public float getOpenNess(float partialTicks) {
return Mth.lerp(partialTicks, this.prevLidAngle, this.lidAngle);
}
public static int getPlayersUsing(BlockGetter reader, BlockPos posIn) {
BlockState blockstate = reader.getBlockState(posIn);
if (blockstate.hasTileEntity()) {
BlockEntity tileentity = reader.getBlockEntity(posIn);
if (tileentity instanceof GenericIronChestTileEntity) {
return ((GenericIronChestTileEntity) tileentity).numPlayersUsing;
}
}
return 0;
}
@Override
protected AbstractContainerMenu createMenu(int windowId, Inventory playerInventory) {
return IronChestContainer.createIronContainer(windowId, playerInventory, this);
}
public void wasPlaced(LivingEntity livingEntity, ItemStack stack) {
}
public void removeAdornments() {
}
public IronChestsTypes getChestType() {
IronChestsTypes type = IronChestsTypes.IRON;
if (this.hasLevel()) {
IronChestsTypes typeFromBlock = GenericIronChestBlock.getTypeFromBlock(this.getBlockState().getBlock());
if (typeFromBlock != null) {
type = typeFromBlock;
}
}
return type;
}
public Block getBlockToUse() {
return this.blockToUse.get();
}
}

View File

@ -1,19 +0,0 @@
package com.progwml6.ironchest.common.block.tileentity;
import com.progwml6.ironchest.common.block.IronChestsBlocks;
import com.progwml6.ironchest.common.block.IronChestsTypes;
import com.progwml6.ironchest.common.inventory.IronChestContainer;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.inventory.AbstractContainerMenu;
public class GoldChestTileEntity extends GenericIronChestTileEntity {
public GoldChestTileEntity() {
super(IronChestsTileEntityTypes.GOLD_CHEST.get(), IronChestsTypes.GOLD, IronChestsBlocks.GOLD_CHEST::get);
}
@Override
protected AbstractContainerMenu createMenu(int id, Inventory playerInventory) {
return IronChestContainer.createGoldContainer(id, playerInventory, this);
}
}

View File

@ -1,11 +0,0 @@
package com.progwml6.ironchest.common.block.tileentity;
import com.progwml6.ironchest.common.block.IronChestsBlocks;
import com.progwml6.ironchest.common.block.IronChestsTypes;
public class IronChestTileEntity extends GenericIronChestTileEntity {
public IronChestTileEntity() {
super(IronChestsTileEntityTypes.IRON_CHEST.get(), IronChestsTypes.IRON, IronChestsBlocks.IRON_CHEST::get);
}
}

View File

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

View File

@ -1,19 +0,0 @@
package com.progwml6.ironchest.common.block.tileentity;
import com.progwml6.ironchest.common.block.IronChestsBlocks;
import com.progwml6.ironchest.common.block.IronChestsTypes;
import com.progwml6.ironchest.common.inventory.IronChestContainer;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.inventory.AbstractContainerMenu;
public class ObsidianChestTileEntity extends GenericIronChestTileEntity {
public ObsidianChestTileEntity() {
super(IronChestsTileEntityTypes.OBSIDIAN_CHEST.get(), IronChestsTypes.OBSIDIAN, IronChestsBlocks.OBSIDIAN_CHEST::get);
}
@Override
protected AbstractContainerMenu createMenu(int id, Inventory playerInventory) {
return IronChestContainer.createObsidianContainer(id, playerInventory, this);
}
}

View File

@ -1,19 +0,0 @@
package com.progwml6.ironchest.common.block.tileentity;
import com.progwml6.ironchest.common.block.IronChestsBlocks;
import com.progwml6.ironchest.common.block.IronChestsTypes;
import com.progwml6.ironchest.common.inventory.IronChestContainer;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.inventory.AbstractContainerMenu;
public class SilverChestTileEntity extends GenericIronChestTileEntity {
public SilverChestTileEntity() {
super(IronChestsTileEntityTypes.SILVER_CHEST.get(), IronChestsTypes.SILVER, IronChestsBlocks.SILVER_CHEST::get);
}
@Override
protected AbstractContainerMenu createMenu(int id, Inventory playerInventory) {
return IronChestContainer.createSilverContainer(id, playerInventory, this);
}
}

View File

@ -37,7 +37,7 @@ public class IronChestsRecipeProvider extends RecipeProvider implements IConditi
}
@Override
protected void buildShapelessRecipes(Consumer<FinishedRecipe> consumer) {
protected void buildCraftingRecipes(Consumer<FinishedRecipe> consumer) {
this.addChestsRecipes(consumer);
this.addUpgradesRecipes(consumer);
}
@ -363,7 +363,7 @@ public class IronChestsRecipeProvider extends RecipeProvider implements IConditi
}
private static ResourceLocation location(String id) {
return new ResourceLocation(IronChests.MODID, id);
return new ResourceLocation(IronChests.MOD_ID, id);
}
private static Tags.IOptionalNamedTag<Item> tag(String name) {

View File

@ -2,6 +2,6 @@
@MethodsReturnNonnullByDefault
package com.progwml6.ironchest.common.data;
import mcp.MethodsReturnNonnullByDefault;
import net.minecraft.MethodsReturnNonnullByDefault;
import javax.annotation.ParametersAreNonnullByDefault;

View File

@ -1,167 +0,0 @@
package com.progwml6.ironchest.common.inventory;
import com.progwml6.ironchest.common.block.IronChestsTypes;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.Container;
import net.minecraft.world.SimpleContainer;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.inventory.MenuType;
import net.minecraft.world.inventory.Slot;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
public class IronChestContainer extends AbstractContainerMenu {
private final Container inventory;
private final IronChestsTypes chestType;
private IronChestContainer(MenuType<?> containerType, int windowId, Inventory playerInventory) {
this(containerType, windowId, playerInventory, new SimpleContainer(IronChestsTypes.WOOD.size), IronChestsTypes.WOOD);
}
public static IronChestContainer createIronContainer(int windowId, Inventory playerInventory) {
return new IronChestContainer(IronChestsContainerTypes.IRON_CHEST.get(), windowId, playerInventory, new SimpleContainer(IronChestsTypes.IRON.size), IronChestsTypes.IRON);
}
public static IronChestContainer createIronContainer(int windowId, Inventory playerInventory, Container inventory) {
return new IronChestContainer(IronChestsContainerTypes.IRON_CHEST.get(), windowId, playerInventory, inventory, IronChestsTypes.IRON);
}
public static IronChestContainer createGoldContainer(int windowId, Inventory playerInventory) {
return new IronChestContainer(IronChestsContainerTypes.GOLD_CHEST.get(), windowId, playerInventory, new SimpleContainer(IronChestsTypes.GOLD.size), IronChestsTypes.GOLD);
}
public static IronChestContainer createGoldContainer(int windowId, Inventory playerInventory, Container inventory) {
return new IronChestContainer(IronChestsContainerTypes.GOLD_CHEST.get(), windowId, playerInventory, inventory, IronChestsTypes.GOLD);
}
public static IronChestContainer createDiamondContainer(int windowId, Inventory playerInventory) {
return new IronChestContainer(IronChestsContainerTypes.DIAMOND_CHEST.get(), windowId, playerInventory, new SimpleContainer(IronChestsTypes.DIAMOND.size), IronChestsTypes.DIAMOND);
}
public static IronChestContainer createDiamondContainer(int windowId, Inventory playerInventory, Container inventory) {
return new IronChestContainer(IronChestsContainerTypes.DIAMOND_CHEST.get(), windowId, playerInventory, inventory, IronChestsTypes.DIAMOND);
}
public static IronChestContainer createCrystalContainer(int windowId, Inventory playerInventory) {
return new IronChestContainer(IronChestsContainerTypes.CRYSTAL_CHEST.get(), windowId, playerInventory, new SimpleContainer(IronChestsTypes.CRYSTAL.size), IronChestsTypes.CRYSTAL);
}
public static IronChestContainer createCrystalContainer(int windowId, Inventory playerInventory, Container inventory) {
return new IronChestContainer(IronChestsContainerTypes.CRYSTAL_CHEST.get(), windowId, playerInventory, inventory, IronChestsTypes.CRYSTAL);
}
public static IronChestContainer createCopperContainer(int windowId, Inventory playerInventory) {
return new IronChestContainer(IronChestsContainerTypes.COPPER_CHEST.get(), windowId, playerInventory, new SimpleContainer(IronChestsTypes.COPPER.size), IronChestsTypes.COPPER);
}
public static IronChestContainer createCopperContainer(int windowId, Inventory playerInventory, Container inventory) {
return new IronChestContainer(IronChestsContainerTypes.COPPER_CHEST.get(), windowId, playerInventory, inventory, IronChestsTypes.COPPER);
}
public static IronChestContainer createSilverContainer(int windowId, Inventory playerInventory) {
return new IronChestContainer(IronChestsContainerTypes.SILVER_CHEST.get(), windowId, playerInventory, new SimpleContainer(IronChestsTypes.CRYSTAL.size), IronChestsTypes.SILVER);
}
public static IronChestContainer createSilverContainer(int windowId, Inventory playerInventory, Container inventory) {
return new IronChestContainer(IronChestsContainerTypes.SILVER_CHEST.get(), windowId, playerInventory, inventory, IronChestsTypes.SILVER);
}
public static IronChestContainer createObsidianContainer(int windowId, Inventory playerInventory) {
return new IronChestContainer(IronChestsContainerTypes.OBSIDIAN_CHEST.get(), windowId, playerInventory, new SimpleContainer(IronChestsTypes.OBSIDIAN.size), IronChestsTypes.OBSIDIAN);
}
public static IronChestContainer createObsidianContainer(int windowId, Inventory playerInventory, Container inventory) {
return new IronChestContainer(IronChestsContainerTypes.OBSIDIAN_CHEST.get(), windowId, playerInventory, inventory, IronChestsTypes.OBSIDIAN);
}
public static IronChestContainer createDirtContainer(int windowId, Inventory playerInventory) {
return new IronChestContainer(IronChestsContainerTypes.DIRT_CHEST.get(), windowId, playerInventory, new SimpleContainer(IronChestsTypes.DIRT.size), IronChestsTypes.DIRT);
}
public static IronChestContainer createDirtContainer(int windowId, Inventory playerInventory, Container inventory) {
return new IronChestContainer(IronChestsContainerTypes.DIRT_CHEST.get(), windowId, playerInventory, inventory, IronChestsTypes.DIRT);
}
public IronChestContainer(MenuType<?> containerType, int windowId, Inventory playerInventory, Container inventory, IronChestsTypes chestType) {
super(containerType, windowId);
checkContainerSize(inventory, chestType.size);
this.inventory = inventory;
this.chestType = chestType;
inventory.startOpen(playerInventory.player);
if (chestType == IronChestsTypes.DIRT) {
this.addSlot(new DirtChestSlot(inventory, 0, 12 + 4 * 18, 8 + 2 * 18));
}
else {
for (int chestRow = 0; chestRow < chestType.getRowCount(); chestRow++) {
for (int chestCol = 0; chestCol < chestType.rowLength; chestCol++) {
this.addSlot(new Slot(inventory, chestCol + chestRow * chestType.rowLength, 12 + chestCol * 18, 18 + chestRow * 18));
}
}
}
int leftCol = (chestType.xSize - 162) / 2 + 1;
for (int playerInvRow = 0; playerInvRow < 3; playerInvRow++) {
for (int playerInvCol = 0; playerInvCol < 9; playerInvCol++) {
this.addSlot(new Slot(playerInventory, playerInvCol + playerInvRow * 9 + 9, leftCol + playerInvCol * 18, chestType.ySize - (4 - playerInvRow) * 18 - 10));
}
}
for (int hotbarSlot = 0; hotbarSlot < 9; hotbarSlot++) {
this.addSlot(new Slot(playerInventory, hotbarSlot, leftCol + hotbarSlot * 18, chestType.ySize - 24));
}
}
@Override
public boolean stillValid(Player playerIn) {
return this.inventory.stillValid(playerIn);
}
@Override
public ItemStack quickMoveStack(Player playerIn, int index) {
ItemStack itemstack = ItemStack.EMPTY;
Slot slot = this.slots.get(index);
if (slot != null && slot.hasItem()) {
ItemStack itemstack1 = slot.getItem();
itemstack = itemstack1.copy();
if (index < this.chestType.size) {
if (!this.moveItemStackTo(itemstack1, this.chestType.size, this.slots.size(), true)) {
return ItemStack.EMPTY;
}
}
else if (!this.moveItemStackTo(itemstack1, 0, this.chestType.size, false)) {
return ItemStack.EMPTY;
}
if (itemstack1.isEmpty()) {
slot.set(ItemStack.EMPTY);
}
else {
slot.setChanged();
}
}
return itemstack;
}
@Override
public void removed(Player playerIn) {
super.removed(playerIn);
this.inventory.stopOpen(playerIn);
}
@OnlyIn(Dist.CLIENT)
public IronChestsTypes getChestType() {
return this.chestType;
}
}

View File

@ -0,0 +1,171 @@
package com.progwml6.ironchest.common.inventory;
import com.progwml6.ironchest.common.block.IronChestsTypes;
import net.minecraft.world.Container;
import net.minecraft.world.SimpleContainer;
import net.minecraft.world.entity.player.Inventory;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.AbstractContainerMenu;
import net.minecraft.world.inventory.MenuType;
import net.minecraft.world.inventory.Slot;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import javax.annotation.Nullable;
public class IronChestMenu extends AbstractContainerMenu {
private final Container container;
private final IronChestsTypes chestType;
private IronChestMenu(@Nullable MenuType<?> menuType, int containerId, Inventory playerInventory) {
this(menuType, containerId, playerInventory, new SimpleContainer(IronChestsTypes.WOOD.size), IronChestsTypes.WOOD);
}
public static IronChestMenu createIronContainer(int containerId, Inventory playerInventory) {
return new IronChestMenu(IronChestsContainerTypes.IRON_CHEST.get(), containerId, playerInventory, new SimpleContainer(IronChestsTypes.IRON.size), IronChestsTypes.IRON);
}
public static IronChestMenu createIronContainer(int containerId, Inventory playerInventory, Container inventory) {
return new IronChestMenu(IronChestsContainerTypes.IRON_CHEST.get(), containerId, playerInventory, inventory, IronChestsTypes.IRON);
}
public static IronChestMenu createGoldContainer(int containerId, Inventory playerInventory) {
return new IronChestMenu(IronChestsContainerTypes.GOLD_CHEST.get(), containerId, playerInventory, new SimpleContainer(IronChestsTypes.GOLD.size), IronChestsTypes.GOLD);
}
public static IronChestMenu createGoldContainer(int containerId, Inventory playerInventory, Container inventory) {
return new IronChestMenu(IronChestsContainerTypes.GOLD_CHEST.get(), containerId, playerInventory, inventory, IronChestsTypes.GOLD);
}
public static IronChestMenu createDiamondContainer(int containerId, Inventory playerInventory) {
return new IronChestMenu(IronChestsContainerTypes.DIAMOND_CHEST.get(), containerId, playerInventory, new SimpleContainer(IronChestsTypes.DIAMOND.size), IronChestsTypes.DIAMOND);
}
public static IronChestMenu createDiamondContainer(int containerId, Inventory playerInventory, Container inventory) {
return new IronChestMenu(IronChestsContainerTypes.DIAMOND_CHEST.get(), containerId, playerInventory, inventory, IronChestsTypes.DIAMOND);
}
public static IronChestMenu createCrystalContainer(int containerId, Inventory playerInventory) {
return new IronChestMenu(IronChestsContainerTypes.CRYSTAL_CHEST.get(), containerId, playerInventory, new SimpleContainer(IronChestsTypes.CRYSTAL.size), IronChestsTypes.CRYSTAL);
}
public static IronChestMenu createCrystalContainer(int containerId, Inventory playerInventory, Container inventory) {
return new IronChestMenu(IronChestsContainerTypes.CRYSTAL_CHEST.get(), containerId, playerInventory, inventory, IronChestsTypes.CRYSTAL);
}
public static IronChestMenu createCopperContainer(int containerId, Inventory playerInventory) {
return new IronChestMenu(IronChestsContainerTypes.COPPER_CHEST.get(), containerId, playerInventory, new SimpleContainer(IronChestsTypes.COPPER.size), IronChestsTypes.COPPER);
}
public static IronChestMenu createCopperContainer(int containerId, Inventory playerInventory, Container inventory) {
return new IronChestMenu(IronChestsContainerTypes.COPPER_CHEST.get(), containerId, playerInventory, inventory, IronChestsTypes.COPPER);
}
public static IronChestMenu createSilverContainer(int containerId, Inventory playerInventory) {
return new IronChestMenu(IronChestsContainerTypes.SILVER_CHEST.get(), containerId, playerInventory, new SimpleContainer(IronChestsTypes.CRYSTAL.size), IronChestsTypes.SILVER);
}
public static IronChestMenu createSilverContainer(int containerId, Inventory playerInventory, Container inventory) {
return new IronChestMenu(IronChestsContainerTypes.SILVER_CHEST.get(), containerId, playerInventory, inventory, IronChestsTypes.SILVER);
}
public static IronChestMenu createObsidianContainer(int containerId, Inventory playerInventory) {
return new IronChestMenu(IronChestsContainerTypes.OBSIDIAN_CHEST.get(), containerId, playerInventory, new SimpleContainer(IronChestsTypes.OBSIDIAN.size), IronChestsTypes.OBSIDIAN);
}
public static IronChestMenu createObsidianContainer(int containerId, Inventory playerInventory, Container inventory) {
return new IronChestMenu(IronChestsContainerTypes.OBSIDIAN_CHEST.get(), containerId, playerInventory, inventory, IronChestsTypes.OBSIDIAN);
}
public static IronChestMenu createDirtContainer(int containerId, Inventory playerInventory) {
return new IronChestMenu(IronChestsContainerTypes.DIRT_CHEST.get(), containerId, playerInventory, new SimpleContainer(IronChestsTypes.DIRT.size), IronChestsTypes.DIRT);
}
public static IronChestMenu createDirtContainer(int containerId, Inventory playerInventory, Container inventory) {
return new IronChestMenu(IronChestsContainerTypes.DIRT_CHEST.get(), containerId, playerInventory, inventory, IronChestsTypes.DIRT);
}
protected IronChestMenu(@Nullable MenuType<?> menuType, int containerId, Inventory playerInventory, Container inventory, IronChestsTypes chestType) {
super(menuType, containerId);
checkContainerSize(inventory, chestType.size);
this.container = inventory;
this.chestType = chestType;
inventory.startOpen(playerInventory.player);
if (chestType == IronChestsTypes.DIRT) {
this.addSlot(new DirtChestSlot(inventory, 0, 12 + 4 * 18, 8 + 2 * 18));
} else {
for (int chestRow = 0; chestRow < chestType.getRowCount(); chestRow++) {
for (int chestCol = 0; chestCol < chestType.rowLength; chestCol++) {
this.addSlot(new Slot(inventory, chestCol + chestRow * chestType.rowLength, 12 + chestCol * 18, 18 + chestRow * 18));
}
}
}
int leftCol = (chestType.xSize - 162) / 2 + 1;
for (int playerInvRow = 0; playerInvRow < 3; playerInvRow++) {
for (int playerInvCol = 0; playerInvCol < 9; playerInvCol++) {
this.addSlot(new Slot(playerInventory, playerInvCol + playerInvRow * 9 + 9, leftCol + playerInvCol * 18, chestType.ySize - (4 - playerInvRow) * 18 - 10));
}
}
for (int hotbarSlot = 0; hotbarSlot < 9; hotbarSlot++) {
this.addSlot(new Slot(playerInventory, hotbarSlot, leftCol + hotbarSlot * 18, chestType.ySize - 24));
}
}
@Override
public boolean stillValid(Player player) {
return this.container.stillValid(player);
}
@Override
public ItemStack quickMoveStack(Player player, int index) {
ItemStack itemstack = ItemStack.EMPTY;
Slot slot = this.slots.get(index);
if (slot != null && slot.hasItem()) {
ItemStack itemstack1 = slot.getItem();
itemstack = itemstack1.copy();
if (index < this.chestType.size) {
if (!this.moveItemStackTo(itemstack1, this.chestType.size, this.slots.size(), true)) {
return ItemStack.EMPTY;
}
} else if (!this.moveItemStackTo(itemstack1, 0, this.chestType.size, false)) {
return ItemStack.EMPTY;
}
if (itemstack1.isEmpty()) {
slot.set(ItemStack.EMPTY);
} else {
slot.setChanged();
}
}
return itemstack;
}
@Override
public void removed(Player playerIn) {
super.removed(playerIn);
this.container.stopOpen(playerIn);
}
public Container getContainer() {
return this.container;
}
@OnlyIn(Dist.CLIENT)
public IronChestsTypes getChestType() {
return this.chestType;
}
}

View File

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

View File

@ -2,6 +2,6 @@
@MethodsReturnNonnullByDefault
package com.progwml6.ironchest.common.inventory;
import mcp.MethodsReturnNonnullByDefault;
import net.minecraft.MethodsReturnNonnullByDefault;
import javax.annotation.ParametersAreNonnullByDefault;

View File

@ -1,8 +1,8 @@
package com.progwml6.ironchest.common.item;
import com.progwml6.ironchest.common.block.GenericIronChestBlock;
import com.progwml6.ironchest.common.block.AbstractIronChestBlock;
import com.progwml6.ironchest.common.block.IronChestsTypes;
import com.progwml6.ironchest.common.block.tileentity.GenericIronChestTileEntity;
import com.progwml6.ironchest.common.block.entity.AbstractIronChestBlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.ChestBlock;
import net.minecraft.world.item.TooltipFlag;
@ -17,14 +17,10 @@ import net.minecraft.core.Direction;
import net.minecraft.core.NonNullList;
import net.minecraft.core.BlockPos;
import net.minecraft.network.chat.Component;
import net.minecraft.util.text.TextFormatting;
import net.minecraft.util.text.TranslationTextComponent;
import net.minecraft.world.level.Level;
import java.util.List;
import net.minecraft.world.item.Item.Properties;
public class ChestUpgradeItem extends Item {
private final IronChestsUpgradeType type;
@ -34,12 +30,6 @@ public class ChestUpgradeItem extends Item {
this.type = type;
}
@Override
public void appendHoverText(ItemStack stack, Level worldIn, List<Component> tooltip, TooltipFlag flagIn) {
super.appendHoverText(stack, worldIn, tooltip, flagIn);
//tooltip.add(new TranslationTextComponent(this.getTranslationKey() + ".desc").applyTextStyle(TextFormatting.GRAY));
}
@Override
public InteractionResult onItemUseFirst(ItemStack stack, UseOnContext context) {
Player entityPlayer = context.getPlayer();
@ -59,8 +49,7 @@ public class ChestUpgradeItem extends Item {
if (!(world.getBlockState(blockPos).getBlock() instanceof ChestBlock)) {
return InteractionResult.PASS;
}
}
else {
} else {
if (world.getBlockState(blockPos).getBlock().defaultBlockState() != IronChestsTypes.get(this.type.source).defaultBlockState()) {
return InteractionResult.PASS;
}
@ -74,17 +63,17 @@ public class ChestUpgradeItem extends Item {
}
}
GenericIronChestTileEntity newChest = null;
AbstractIronChestBlockEntity newChest = null;
Component customName = null;
NonNullList<ItemStack> chestContents = NonNullList.withSize(27, ItemStack.EMPTY);
Direction chestFacing = Direction.NORTH;
BlockState iBlockState = IronChestsTypes.get(this.type.target).defaultBlockState();
if (tileEntity != null) {
if (tileEntity instanceof GenericIronChestTileEntity) {
GenericIronChestTileEntity chest = (GenericIronChestTileEntity) tileEntity;
if (tileEntity instanceof AbstractIronChestBlockEntity chest) {
BlockState chestState = world.getBlockState(blockPos);
if (GenericIronChestTileEntity.getPlayersUsing(world, blockPos) > 0) {
if (AbstractIronChestBlockEntity.getOpenCount(world, blockPos) > 0) {
return InteractionResult.PASS;
}
@ -93,18 +82,13 @@ public class ChestUpgradeItem extends Item {
}
chestContents = chest.getItems();
chestFacing = chestState.getValue(GenericIronChestBlock.FACING);
chestFacing = chestState.getValue(AbstractIronChestBlock.FACING);
customName = chest.getCustomName();
newChest = this.type.target.makeEntity();
if (newChest == null) {
return InteractionResult.PASS;
}
}
else if (tileEntity instanceof ChestBlockEntity) {
iBlockState = iBlockState.setValue(AbstractIronChestBlock.FACING, chestFacing);
newChest = this.type.target.makeEntity(blockPos, iBlockState);
} else if (tileEntity instanceof ChestBlockEntity chest) {
BlockState chestState = world.getBlockState(blockPos);
chestFacing = chestState.getValue(ChestBlock.FACING);
ChestBlockEntity chest = (ChestBlockEntity) tileEntity;
if (ChestBlockEntity.getOpenCount(world, blockPos) > 0) {
return InteractionResult.PASS;
@ -126,33 +110,35 @@ public class ChestUpgradeItem extends Item {
customName = chest.getCustomName();
newChest = this.type.target.makeEntity();
iBlockState = iBlockState.setValue(AbstractIronChestBlock.FACING, chestFacing);
newChest = this.type.target.makeEntity(blockPos, iBlockState);
}
}
tileEntity.clearCache();
if (newChest == null) {
return InteractionResult.PASS;
}
world.removeBlockEntity(blockPos);
world.removeBlock(blockPos, false);
BlockState iBlockState = IronChestsTypes.get(this.type.target).defaultBlockState().setValue(GenericIronChestBlock.FACING, chestFacing);
world.setBlock(blockPos, iBlockState, 3);
world.setBlockEntity(blockPos, newChest);
world.setBlockEntity(newChest);
world.sendBlockUpdated(blockPos, iBlockState, iBlockState, 3);
BlockEntity tileEntity2 = world.getBlockEntity(blockPos);
if (tileEntity2 instanceof GenericIronChestTileEntity) {
if (tileEntity2 instanceof AbstractIronChestBlockEntity) {
if (customName != null) {
((GenericIronChestTileEntity) tileEntity2).setCustomName(customName);
((AbstractIronChestBlockEntity) tileEntity2).setCustomName(customName);
}
((GenericIronChestTileEntity) tileEntity2).setItems(chestContents);
((AbstractIronChestBlockEntity) tileEntity2).setItems(chestContents);
}
if (!entityPlayer.abilities.instabuild) {
if (!entityPlayer.getAbilities().instabuild) {
itemStack.shrink(1);
}

View File

@ -0,0 +1,36 @@
package com.progwml6.ironchest.common.item;
import net.minecraft.client.renderer.BlockEntityWithoutLevelRenderer;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.level.block.Block;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.client.IItemRenderProperties;
import java.util.concurrent.Callable;
import java.util.function.Consumer;
import java.util.function.Supplier;
public class IronChestBlockItem extends BlockItem {
protected Supplier<BlockEntityWithoutLevelRenderer> itemRenderer;
public IronChestBlockItem(Block block, Properties properties, Supplier<Callable<BlockEntityWithoutLevelRenderer>> itemRenderer) {
super(block, properties);
BlockEntityWithoutLevelRenderer tmp = net.minecraftforge.fml.DistExecutor.callWhenOn(Dist.CLIENT, itemRenderer);
this.itemRenderer = tmp == null ? null : () -> tmp;
}
@Override
public void initializeClient(Consumer<IItemRenderProperties> consumer) {
super.initializeClient(consumer);
consumer.accept(new IItemRenderProperties() {
@Override
public BlockEntityWithoutLevelRenderer getItemStackRenderer() {
System.out.println(itemRenderer);
return itemRenderer.get();
}
});
}
}

View File

@ -3,7 +3,7 @@ package com.progwml6.ironchest.common.item;
import com.google.common.collect.ImmutableMap;
import com.progwml6.ironchest.IronChests;
import net.minecraft.world.item.Item;
import net.minecraftforge.fml.RegistryObject;
import net.minecraftforge.fmllegacy.RegistryObject;
import net.minecraftforge.registries.DeferredRegister;
import net.minecraftforge.registries.ForgeRegistries;
@ -15,11 +15,11 @@ import java.util.stream.Collectors;
public class IronChestsItems {
public static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, IronChests.MODID);
public static final DeferredRegister<Item> ITEMS = DeferredRegister.create(ForgeRegistries.ITEMS, IronChests.MOD_ID);
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",
() -> new ChestUpgradeItem(type, new Item.Properties().tab(IronChests.IRONCHESTS_ITEM_GROUP).stacksTo(1))))));
.collect(Collectors.toMap(Function.identity(), type -> register(type.name().toLowerCase(Locale.ROOT) + "_chest_upgrade",
() -> 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) {
return ITEMS.register(name, sup);

View File

@ -2,6 +2,6 @@
@MethodsReturnNonnullByDefault
package com.progwml6.ironchest.common.item;
import mcp.MethodsReturnNonnullByDefault;
import net.minecraft.MethodsReturnNonnullByDefault;
import javax.annotation.ParametersAreNonnullByDefault;

View File

@ -1,6 +1,6 @@
package com.progwml6.ironchest.common.network;
import com.progwml6.ironchest.common.block.tileentity.CrystalChestTileEntity;
import com.progwml6.ironchest.common.block.entity.CrystalChestBlockEntity;
import com.progwml6.ironchest.common.network.helper.IThreadsafePacket;
import net.minecraft.client.Minecraft;
import net.minecraft.world.item.ItemStack;
@ -9,7 +9,7 @@ import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.core.NonNullList;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.Level;
import net.minecraftforge.fml.network.NetworkEvent.Context;
import net.minecraftforge.fmllegacy.network.NetworkEvent;
public class InventoryTopStacksSyncPacket implements IThreadsafePacket {
@ -48,7 +48,7 @@ public class InventoryTopStacksSyncPacket implements IThreadsafePacket {
}
@Override
public void handleThreadsafe(Context context) {
public void handleThreadsafe(NetworkEvent.Context context) {
HandleClient.handle(this);
}
@ -64,8 +64,9 @@ public class InventoryTopStacksSyncPacket implements IThreadsafePacket {
BlockEntity te = world.getBlockEntity(packet.pos);
if (te != null) {
if (te instanceof CrystalChestTileEntity) {
((CrystalChestTileEntity) te).receiveMessageFromServer(packet.topStacks);
if (te instanceof CrystalChestBlockEntity) {
((CrystalChestBlockEntity) te).receiveMessageFromServer(packet.topStacks);
Minecraft.getInstance().levelRenderer.blockChanged(null, packet.pos, null, null, 0);
}
}

View File

@ -13,11 +13,11 @@ import net.minecraft.world.level.LevelAccessor;
import net.minecraft.world.level.chunk.LevelChunk;
import net.minecraft.server.level.ServerLevel;
import net.minecraftforge.common.util.FakePlayer;
import net.minecraftforge.fml.network.NetworkDirection;
import net.minecraftforge.fml.network.NetworkEvent;
import net.minecraftforge.fml.network.NetworkRegistry;
import net.minecraftforge.fml.network.PacketDistributor;
import net.minecraftforge.fml.network.simple.SimpleChannel;
import net.minecraftforge.fmllegacy.network.NetworkDirection;
import net.minecraftforge.fmllegacy.network.NetworkEvent;
import net.minecraftforge.fmllegacy.network.NetworkRegistry;
import net.minecraftforge.fmllegacy.network.PacketDistributor;
import net.minecraftforge.fmllegacy.network.simple.SimpleChannel;
import javax.annotation.Nullable;
import java.util.Optional;
@ -34,7 +34,7 @@ public class IronChestNetwork {
private static final String PROTOCOL_VERSION = Integer.toString(1);
public IronChestNetwork() {
this.network = NetworkRegistry.ChannelBuilder.named(new ResourceLocation(IronChests.MODID, "network"))
this.network = NetworkRegistry.ChannelBuilder.named(new ResourceLocation(IronChests.MOD_ID, "network"))
.clientAcceptedVersions(PROTOCOL_VERSION::equals)
.serverAcceptedVersions(PROTOCOL_VERSION::equals)
.networkProtocolVersion(() -> PROTOCOL_VERSION)
@ -179,7 +179,7 @@ public class IronChestNetwork {
}
/**
* Same as {@link #sendToClientsAround(Object, ServerWorld, BlockPos)}, but checks that the world is a serverworld
* Same as {@link #sendToClientsAround(Object, ServerLevel, BlockPos)}, but checks that the world is a level accessor
*
* @param msg Packet to send
* @param world World instance

View File

@ -1,7 +1,7 @@
package com.progwml6.ironchest.common.network.helper;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraftforge.fml.network.NetworkEvent;
import net.minecraftforge.fmllegacy.network.NetworkEvent;
import java.util.function.Supplier;

View File

@ -1,7 +1,6 @@
package com.progwml6.ironchest.common.network.helper;
import net.minecraftforge.fml.network.NetworkEvent;
import net.minecraftforge.fmllegacy.network.NetworkEvent;
import java.util.function.Supplier;
@ -9,6 +8,7 @@ import java.util.function.Supplier;
* Packet instance that automatically wraps the logic in {@link NetworkEvent.Context#enqueueWork(Runnable)} for thread safety
*/
public interface IThreadsafePacket extends ISimplePacket {
@Override
default void handle(Supplier<NetworkEvent.Context> supplier) {
NetworkEvent.Context context = supplier.get();
@ -19,7 +19,8 @@ public interface IThreadsafePacket extends ISimplePacket {
/**
* Handles receiving the packet on the correct thread
* Packet is automatically set to handled as well by the base logic
* @param context Packet context
*
* @param context Packet context
*/
void handleThreadsafe(NetworkEvent.Context context);
}

View File

@ -0,0 +1,7 @@
@ParametersAreNonnullByDefault
@MethodsReturnNonnullByDefault
package com.progwml6.ironchest.common.network.helper;
import net.minecraft.MethodsReturnNonnullByDefault;
import javax.annotation.ParametersAreNonnullByDefault;

View File

@ -2,6 +2,6 @@
@MethodsReturnNonnullByDefault
package com.progwml6.ironchest.common.network;
import mcp.MethodsReturnNonnullByDefault;
import net.minecraft.MethodsReturnNonnullByDefault;
import javax.annotation.ParametersAreNonnullByDefault;

View File

@ -2,6 +2,6 @@
@MethodsReturnNonnullByDefault
package com.progwml6.ironchest.common;
import mcp.MethodsReturnNonnullByDefault;
import net.minecraft.MethodsReturnNonnullByDefault;
import javax.annotation.ParametersAreNonnullByDefault;

View File

@ -2,6 +2,6 @@
@MethodsReturnNonnullByDefault
package com.progwml6.ironchest;
import mcp.MethodsReturnNonnullByDefault;
import net.minecraft.MethodsReturnNonnullByDefault;
import javax.annotation.ParametersAreNonnullByDefault;