Fix crystal chests crashing the client upon opening and fix wood to iron upgrade not working. Closes #266, Closes #263 Closes #265

This commit is contained in:
Alexander Behrhof 2021-12-16 18:33:05 -05:00
parent 1d89a105d9
commit 295d887844
5 changed files with 35 additions and 10 deletions

View File

@ -12,10 +12,14 @@ 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.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.Block;
import net.minecraftforge.api.distmarker.Dist;
import net.minecraftforge.api.distmarker.OnlyIn;
import net.minecraftforge.event.RegistryEvent;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.DistExecutor;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
@ -96,4 +100,14 @@ public class IronChests {
}
}
@SubscribeEvent
void missingBlocks(final RegistryEvent.MissingMappings<Block> event) {
}
@SubscribeEvent
void missingItems(final RegistryEvent.MissingMappings<Item> event) {
}
}

View File

@ -10,6 +10,8 @@ import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.state.BlockState;
import javax.annotation.Nullable;
public interface ICrystalChest {
default NonNullList<ItemStack> buildItemStackDataList() {
@ -46,6 +48,7 @@ public interface ICrystalChest {
NonNullList<ItemStack> getTopItems();
@Nullable
Level getChestLevel();
BlockPos getChestWorldPosition();
@ -57,15 +60,15 @@ public interface ICrystalChest {
return;
}
NonNullList<ItemStack> tempCopy = NonNullList.<ItemStack>withSize(this.getContainerSize(), ItemStack.EMPTY);
NonNullList<ItemStack> tempCopy = NonNullList.<ItemStack>withSize(IronChestsTypes.CRYSTAL.size, ItemStack.EMPTY);
boolean hasStuff = false;
int compressedIdx = 0;
mainLoop:
for (int i = 0; i < this.getContainerSize(); i++) {
ItemStack itemStack = this.getItems().get(i);
for (int i = 0; i < IronChestsTypes.CRYSTAL.size; i++) {
ItemStack itemStack = this.getCurrentItems().get(i);
if (!itemStack.isEmpty()) {
for (int j = 0; j < compressedIdx; j++) {
@ -143,11 +146,9 @@ public interface ICrystalChest {
this.sendTopStacksPacket();
}
NonNullList<ItemStack> getItems();
NonNullList<ItemStack> getCurrentItems();
void setHadStuff(boolean hadStuff);
boolean getHadStuff();
int getContainerSize();
}

View File

@ -83,4 +83,9 @@ public class CrystalChestBlockEntity extends AbstractIronChestBlockEntity implem
public boolean getHadStuff() {
return this.hadStuff;
}
@Override
public NonNullList<ItemStack> getCurrentItems() {
return this.getItems();
}
}

View File

@ -75,6 +75,11 @@ public class TrappedCrystalChestBlockEntity extends AbstractTrappedIronChestBloc
this.topStacks = topStacks;
}
@Override
public NonNullList<ItemStack> getCurrentItems() {
return this.getItems();
}
@Override
public void setHadStuff(boolean hadStuff) {
this.hadStuff = hadStuff;

View File

@ -48,8 +48,8 @@ public class ChestUpgradeItem extends Item {
}
if (this.type.canUpgrade(IronChestsTypes.WOOD)) {
if (!(world.getBlockState(blockPos).getBlock() instanceof ChestBlock)) {
return InteractionResult.PASS;
if (world.getBlockState(blockPos).getBlock() instanceof ChestBlock) {
passed = true;
}
} else {
for (Block block : IronChestsTypes.get(this.type.source)) {
@ -130,9 +130,9 @@ public class ChestUpgradeItem extends Item {
boolean trapped = tileEntity instanceof TrappedChestBlockEntity;
if(trapped) {
iBlockState = IronChestsTypes.get(this.type.source).get(1).defaultBlockState();
iBlockState = IronChestsTypes.get(this.type.target).get(1).defaultBlockState();
} else {
iBlockState = IronChestsTypes.get(this.type.source).get(0).defaultBlockState();
iBlockState = IronChestsTypes.get(this.type.target).get(0).defaultBlockState();
}
iBlockState = iBlockState.setValue(AbstractIronChestBlock.FACING, chestFacing);