Revert "Perform some minor code clean ups (Such as cleaning up imports, some lines of code, etc) Move the entire TopStacks code to the Crystal versions of the chests/Shulker Boxes to match 1.13 code, Fix chests and Shulker Boxes losing their custom names on upgrading. Finally fix the inventories missing due to tinker construct smelteries. Closes #162"

This reverts commit 930ea9a725.
This commit is contained in:
alexbegt 2019-06-10 21:06:08 -04:00
parent 930ea9a725
commit 4b51dbf062
38 changed files with 765 additions and 920 deletions

View File

@ -37,17 +37,13 @@ public class ClientProxy extends CommonProxy
for (IronChestType type : IronChestType.values())
{
if (type.clazz != null)
{
ClientRegistry.bindTileEntitySpecialRenderer(type.clazz, new TileEntityIronChestRenderer());
}
}
for (IronShulkerBoxType type : IronShulkerBoxType.values())
{
if (type.clazz != null)
{
ClientRegistry.bindTileEntitySpecialRenderer(type.clazz, new TileEntityIronShulkerBoxRenderer());
}
}
}

View File

@ -10,11 +10,13 @@
******************************************************************************/
package cpw.mods.ironchest.client.renderer.chest;
import java.util.Random;
import com.google.common.primitives.SignedBytes;
import cpw.mods.ironchest.common.blocks.chest.BlockIronChest;
import cpw.mods.ironchest.common.blocks.chest.IronChestType;
import cpw.mods.ironchest.common.core.IronChestBlocks;
import cpw.mods.ironchest.common.tileentity.chest.TileEntityCrystalChest;
import cpw.mods.ironchest.common.tileentity.chest.TileEntityIronChest;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
@ -26,8 +28,6 @@ import net.minecraft.entity.item.EntityItem;
import net.minecraft.item.ItemStack;
import net.minecraft.util.EnumFacing;
import java.util.Random;
public class TileEntityIronChestRenderer extends TileEntitySpecialRenderer<TileEntityIronChest>
{
private Random random;
@ -105,31 +105,31 @@ public class TileEntityIronChestRenderer extends TileEntitySpecialRenderer<TileE
switch (facing)
{
case NORTH:
{
GlStateManager.rotate(180F, 0F, 1F, 0F);
break;
}
case SOUTH:
{
GlStateManager.rotate(0F, 0F, 1F, 0F);
break;
}
case WEST:
{
GlStateManager.rotate(90F, 0F, 1F, 0F);
break;
}
case EAST:
{
GlStateManager.rotate(270F, 0F, 1F, 0F);
break;
}
default:
{
GlStateManager.rotate(0F, 0F, 1F, 0F);
break;
}
case NORTH:
{
GlStateManager.rotate(180F, 0F, 1F, 0F);
break;
}
case SOUTH:
{
GlStateManager.rotate(0F, 0F, 1F, 0F);
break;
}
case WEST:
{
GlStateManager.rotate(90F, 0F, 1F, 0F);
break;
}
case EAST:
{
GlStateManager.rotate(270F, 0F, 1F, 0F);
break;
}
default:
{
GlStateManager.rotate(0F, 0F, 1F, 0F);
break;
}
}
GlStateManager.translate(-0.5F, -0.5F, -0.5F);
@ -174,7 +174,7 @@ public class TileEntityIronChestRenderer extends TileEntitySpecialRenderer<TileE
float blockScale = 0.70F;
float timeD = (float) (360D * (System.currentTimeMillis() & 0x3FFFL) / 0x3FFFL) - partialTicks;
if (((TileEntityCrystalChest) te).getTopItems().get(1).isEmpty())
if (te.getTopItems().get(1).isEmpty())
{
shift = 8;
blockScale = 0.85F;
@ -190,7 +190,7 @@ public class TileEntityIronChestRenderer extends TileEntitySpecialRenderer<TileE
customItem.hoverStart = 0F;
for (ItemStack item : ((TileEntityCrystalChest) te).getTopItems())
for (ItemStack item : te.getTopItems())
{
if (shift > shifts.length || shift > 8)
{

View File

@ -16,7 +16,6 @@ import com.google.common.primitives.SignedBytes;
import cpw.mods.ironchest.common.blocks.shulker.BlockIronShulkerBox;
import cpw.mods.ironchest.common.blocks.shulker.IronShulkerBoxType;
import cpw.mods.ironchest.common.tileentity.shulker.TileEntityCrystalShulkerBox;
import cpw.mods.ironchest.common.tileentity.shulker.TileEntityIronShulkerBox;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
@ -166,7 +165,7 @@ public class TileEntityIronShulkerBoxRenderer extends TileEntitySpecialRenderer<
float blockScale = 0.70F;
float timeD = (float) (360D * (System.currentTimeMillis() & 0x3FFFL) / 0x3FFFL) - partialTicks;
if (((TileEntityCrystalShulkerBox) te).getTopItems().get(1).isEmpty())
if (te.getTopItems().get(1).isEmpty())
{
shift = 8;
blockScale = 0.85F;
@ -182,7 +181,7 @@ public class TileEntityIronShulkerBoxRenderer extends TileEntitySpecialRenderer<
customItem.hoverStart = 0F;
for (ItemStack item : ((TileEntityCrystalShulkerBox) te).getTopItems())
for (ItemStack item : te.getTopItems())
{
if (shift > shifts.length || shift > 8)
{

View File

@ -10,6 +10,10 @@
******************************************************************************/
package cpw.mods.ironchest.common.blocks.chest;
import java.util.Random;
import javax.annotation.Nullable;
import cpw.mods.ironchest.IronChest;
import cpw.mods.ironchest.common.core.IronChestCreativeTabs;
import cpw.mods.ironchest.common.tileentity.chest.TileEntityIronChest;
@ -49,9 +53,6 @@ import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import javax.annotation.Nullable;
import java.util.Random;
public class BlockIronChest extends Block
{
public static final PropertyEnum<IronChestType> VARIANT_PROP = PropertyEnum.create("variant", IronChestType.class);

View File

@ -82,25 +82,25 @@ public enum IronChestType implements IStringSerializable
{
switch (this)
{
case DIRTCHEST9000:
{
this.breakTexture = "minecraft:blocks/dirt";
break;
}
case OBSIDIAN:
{
this.breakTexture = "minecraft:blocks/obsidian";
break;
}
case WOOD:
{
this.breakTexture = "minecraft:blocks/planks_oak";
break;
}
default:
{
this.breakTexture = "ironchest:blocks/" + this.getName() + "break";
}
case DIRTCHEST9000:
{
this.breakTexture = "minecraft:blocks/dirt";
break;
}
case OBSIDIAN:
{
this.breakTexture = "minecraft:blocks/obsidian";
break;
}
case WOOD:
{
this.breakTexture = "minecraft:blocks/planks_oak";
break;
}
default:
{
this.breakTexture = "ironchest:blocks/" + this.getName() + "break";
}
}
}
@ -162,24 +162,24 @@ public enum IronChestType implements IStringSerializable
{
switch (this)
{
case IRON:
return new TileEntityIronChest();
case GOLD:
return new TileEntityGoldChest();
case DIAMOND:
return new TileEntityDiamondChest();
case COPPER:
return new TileEntityCopperChest();
case SILVER:
return new TileEntitySilverChest();
case CRYSTAL:
return new TileEntityCrystalChest();
case OBSIDIAN:
return new TileEntityObsidianChest();
case DIRTCHEST9000:
return new TileEntityDirtChest();
default:
return null;
case IRON:
return new TileEntityIronChest();
case GOLD:
return new TileEntityGoldChest();
case DIAMOND:
return new TileEntityDiamondChest();
case COPPER:
return new TileEntityCopperChest();
case SILVER:
return new TileEntitySilverChest();
case CRYSTAL:
return new TileEntityCrystalChest();
case OBSIDIAN:
return new TileEntityObsidianChest();
case DIRTCHEST9000:
return new TileEntityDirtChest();
default:
return null;
}
}
}

View File

@ -10,6 +10,10 @@
******************************************************************************/
package cpw.mods.ironchest.common.blocks.shulker;
import java.util.List;
import javax.annotation.Nullable;
import cpw.mods.ironchest.IronChest;
import cpw.mods.ironchest.common.core.IronChestBlocks;
import cpw.mods.ironchest.common.core.IronChestCreativeTabs;
@ -46,9 +50,6 @@ import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import javax.annotation.Nullable;
import java.util.List;
@SuppressWarnings("deprecation")
public class BlockIronShulkerBox extends Block
{
@ -389,7 +390,7 @@ public class BlockIronShulkerBox extends Block
{
if (nbttagcompound1.hasKey("ShulkerBoxSize", 3))
{
NonNullList<ItemStack> nonnulllist = NonNullList.<ItemStack>withSize(nbttagcompound1.getInteger("ShulkerBoxSize"), ItemStack.EMPTY);
NonNullList<ItemStack> nonnulllist = NonNullList.<ItemStack> withSize(nbttagcompound1.getInteger("ShulkerBoxSize"), ItemStack.EMPTY);
ItemStackHelper.loadAllItems(nbttagcompound1, nonnulllist);
int i = 0;
int j = 0;
@ -417,7 +418,7 @@ public class BlockIronShulkerBox extends Block
}
else
{
NonNullList<ItemStack> nonnulllist = NonNullList.<ItemStack>withSize(27, ItemStack.EMPTY);
NonNullList<ItemStack> nonnulllist = NonNullList.<ItemStack> withSize(27, ItemStack.EMPTY);
ItemStackHelper.loadAllItems(nbttagcompound1, nonnulllist);
int i = 0;
int j = 0;
@ -492,39 +493,39 @@ public class BlockIronShulkerBox extends Block
{
switch (colorIn)
{
case WHITE:
return IronChestBlocks.ironShulkerBoxWhiteBlock;
case ORANGE:
return IronChestBlocks.ironShulkerBoxOrangeBlock;
case MAGENTA:
return IronChestBlocks.ironShulkerBoxMagentaBlock;
case LIGHT_BLUE:
return IronChestBlocks.ironShulkerBoxLightBlueBlock;
case YELLOW:
return IronChestBlocks.ironShulkerBoxYellowBlock;
case LIME:
return IronChestBlocks.ironShulkerBoxLimeBlock;
case PINK:
return IronChestBlocks.ironShulkerBoxPinkBlock;
case GRAY:
return IronChestBlocks.ironShulkerBoxGrayBlock;
case SILVER:
return IronChestBlocks.ironShulkerBoxSilverBlock;
case CYAN:
return IronChestBlocks.ironShulkerBoxCyanBlock;
case PURPLE:
default:
return IronChestBlocks.ironShulkerBoxPurpleBlock;
case BLUE:
return IronChestBlocks.ironShulkerBoxBlueBlock;
case BROWN:
return IronChestBlocks.ironShulkerBoxBrownBlock;
case GREEN:
return IronChestBlocks.ironShulkerBoxGreenBlock;
case RED:
return IronChestBlocks.ironShulkerBoxRedBlock;
case BLACK:
return IronChestBlocks.ironShulkerBoxBlackBlock;
case WHITE:
return IronChestBlocks.ironShulkerBoxWhiteBlock;
case ORANGE:
return IronChestBlocks.ironShulkerBoxOrangeBlock;
case MAGENTA:
return IronChestBlocks.ironShulkerBoxMagentaBlock;
case LIGHT_BLUE:
return IronChestBlocks.ironShulkerBoxLightBlueBlock;
case YELLOW:
return IronChestBlocks.ironShulkerBoxYellowBlock;
case LIME:
return IronChestBlocks.ironShulkerBoxLimeBlock;
case PINK:
return IronChestBlocks.ironShulkerBoxPinkBlock;
case GRAY:
return IronChestBlocks.ironShulkerBoxGrayBlock;
case SILVER:
return IronChestBlocks.ironShulkerBoxSilverBlock;
case CYAN:
return IronChestBlocks.ironShulkerBoxCyanBlock;
case PURPLE:
default:
return IronChestBlocks.ironShulkerBoxPurpleBlock;
case BLUE:
return IronChestBlocks.ironShulkerBoxBlueBlock;
case BROWN:
return IronChestBlocks.ironShulkerBoxBrownBlock;
case GREEN:
return IronChestBlocks.ironShulkerBoxGreenBlock;
case RED:
return IronChestBlocks.ironShulkerBoxRedBlock;
case BLACK:
return IronChestBlocks.ironShulkerBoxBlackBlock;
}
}

View File

@ -82,20 +82,20 @@ public enum IronShulkerBoxType implements IStringSerializable
{
switch (this)
{
case OBSIDIAN:
{
this.breakTexture = "minecraft:blocks/obsidian";
break;
}
case VANILLA:
{
this.breakTexture = "minecraft:blocks/planks_oak";
break;
}
default:
{
this.breakTexture = "ironchest:blocks/" + this.getName() + "break";
}
case OBSIDIAN:
{
this.breakTexture = "minecraft:blocks/obsidian";
break;
}
case VANILLA:
{
this.breakTexture = "minecraft:blocks/planks_oak";
break;
}
default:
{
this.breakTexture = "ironchest:blocks/" + this.getName() + "break";
}
}
}
@ -131,22 +131,22 @@ public enum IronShulkerBoxType implements IStringSerializable
{
switch (this)
{
case IRON:
return new TileEntityIronShulkerBox(colorIn);
case GOLD:
return new TileEntityGoldShulkerBox(colorIn);
case DIAMOND:
return new TileEntityDiamondShulkerBox(colorIn);
case COPPER:
return new TileEntityCopperShulkerBox(colorIn);
case SILVER:
return new TileEntitySilverShulkerBox(colorIn);
case CRYSTAL:
return new TileEntityCrystalShulkerBox(colorIn);
case OBSIDIAN:
return new TileEntityObsidianShulkerBox(colorIn);
default:
return null;
case IRON:
return new TileEntityIronShulkerBox(colorIn);
case GOLD:
return new TileEntityGoldShulkerBox(colorIn);
case DIAMOND:
return new TileEntityDiamondShulkerBox(colorIn);
case COPPER:
return new TileEntityCopperShulkerBox(colorIn);
case SILVER:
return new TileEntitySilverShulkerBox(colorIn);
case CRYSTAL:
return new TileEntityCrystalShulkerBox(colorIn);
case OBSIDIAN:
return new TileEntityObsidianShulkerBox(colorIn);
default:
return null;
}
}
}

View File

@ -1,10 +1,11 @@
package cpw.mods.ironchest.common.config;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import cpw.mods.ironchest.IronChest;
import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public final class Config
{

View File

@ -1,5 +1,7 @@
package cpw.mods.ironchest.common.core;
import javax.annotation.Nonnull;
import cpw.mods.ironchest.common.blocks.chest.IronChestType;
import cpw.mods.ironchest.common.util.CreativeTabItems;
import net.minecraft.creativetab.CreativeTabs;
@ -9,8 +11,6 @@ import net.minecraft.util.NonNullList;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import javax.annotation.Nonnull;
public final class IronChestCreativeTabs
{
private IronChestCreativeTabs()

View File

@ -1,13 +1,14 @@
package cpw.mods.ironchest.common.crafting.condition;
import java.util.function.BooleanSupplier;
import com.google.gson.JsonObject;
import cpw.mods.ironchest.common.config.Config;
import net.minecraft.util.JsonUtils;
import net.minecraftforge.common.crafting.IConditionFactory;
import net.minecraftforge.common.crafting.JsonContext;
import java.util.function.BooleanSupplier;
public class IsConfigOptionEnabledConditionFactory implements IConditionFactory
{
@Override
@ -17,10 +18,10 @@ public class IsConfigOptionEnabledConditionFactory implements IConditionFactory
switch (configSetting)
{
case "enableShulkerBoxRecipes":
return () -> Config.enableShulkerBoxRecipes;
default:
throw new RuntimeException(String.format("Invalid config setting: %s", configSetting));
case "enableShulkerBoxRecipes":
return () -> Config.enableShulkerBoxRecipes;
default:
throw new RuntimeException(String.format("Invalid config setting: %s", configSetting));
}
}
}

View File

@ -11,6 +11,7 @@
package cpw.mods.ironchest.common.crafting.recipe;
import com.google.gson.JsonObject;
import cpw.mods.ironchest.common.blocks.shulker.BlockIronShulkerBox;
import net.minecraft.block.Block;
import net.minecraft.init.Items;
@ -122,7 +123,7 @@ public class ShulkerBoxColorRecipeFactory implements IRecipeFactory
@Override
public NonNullList<ItemStack> getRemainingItems(InventoryCrafting inv)
{
NonNullList<ItemStack> nonnulllist = NonNullList.<ItemStack>withSize(inv.getSizeInventory(), ItemStack.EMPTY);
NonNullList<ItemStack> nonnulllist = NonNullList.<ItemStack> withSize(inv.getSizeInventory(), ItemStack.EMPTY);
for (int i = 0; i < nonnulllist.size(); ++i)
{

View File

@ -10,7 +10,10 @@
******************************************************************************/
package cpw.mods.ironchest.common.crafting.recipe;
import javax.annotation.Nonnull;
import com.google.gson.JsonObject;
import cpw.mods.ironchest.IronChest;
import cpw.mods.ironchest.common.blocks.shulker.BlockIronShulkerBox;
import net.minecraft.block.Block;
@ -25,8 +28,6 @@ import net.minecraftforge.common.crafting.IRecipeFactory;
import net.minecraftforge.common.crafting.JsonContext;
import net.minecraftforge.oredict.ShapedOreRecipe;
import javax.annotation.Nonnull;
public class ShulkerBoxRecipeFactory implements IRecipeFactory
{
@Override

View File

@ -114,7 +114,8 @@ public class ContainerIronChest extends Container
{
for (int playerInvCol = 0; playerInvCol < 9; playerInvCol++)
{
this.addSlotToContainer(new Slot(playerInventory, playerInvCol + playerInvRow * 9 + 9, leftCol + playerInvCol * 18, ySize - (4 - playerInvRow) * 18 - 10));
this.addSlotToContainer(
new Slot(playerInventory, playerInvCol + playerInvRow * 9 + 9, leftCol + playerInvCol * 18, ySize - (4 - playerInvRow) * 18 - 10));
}
}

View File

@ -53,7 +53,9 @@ public class ContainerIronShulkerBox extends Container
{
for (int playerInvCol = 0; playerInvCol < 9; playerInvCol++)
{
//@formatter:off
this.addSlotToContainer(new Slot(playerInventory, playerInvCol + playerInvRow * 9 + 9, leftCol + playerInvCol * 18, ySize - (4 - playerInvRow) * 18 - 10));
//@formatter:on
}
}

View File

@ -27,6 +27,8 @@ public class ValidatingShulkerBoxSlot extends Slot
@Override
public boolean isItemValid(ItemStack stack)
{
//@formatter:off
return !(Block.getBlockFromItem(stack.getItem()) instanceof BlockIronShulkerBox) && !(Block.getBlockFromItem(stack.getItem()) instanceof BlockShulkerBox);
//@formatter:on
}
}

View File

@ -6,11 +6,6 @@
******************************************************************************/
package cpw.mods.ironchest.common.items;
import cpw.mods.ironchest.common.blocks.chest.IronChestType;
import cpw.mods.ironchest.common.items.chest.ItemChestChanger;
import net.minecraft.item.Item;
import net.minecraftforge.registries.IForgeRegistry;
import static cpw.mods.ironchest.common.blocks.chest.IronChestType.COPPER;
import static cpw.mods.ironchest.common.blocks.chest.IronChestType.CRYSTAL;
import static cpw.mods.ironchest.common.blocks.chest.IronChestType.DIAMOND;
@ -20,6 +15,11 @@ import static cpw.mods.ironchest.common.blocks.chest.IronChestType.OBSIDIAN;
import static cpw.mods.ironchest.common.blocks.chest.IronChestType.SILVER;
import static cpw.mods.ironchest.common.blocks.chest.IronChestType.WOOD;
import cpw.mods.ironchest.common.blocks.chest.IronChestType;
import cpw.mods.ironchest.common.items.chest.ItemChestChanger;
import net.minecraft.item.Item;
import net.minecraftforge.registries.IForgeRegistry;
public enum ChestChangerType
{
//@formatter:off

View File

@ -6,11 +6,6 @@
******************************************************************************/
package cpw.mods.ironchest.common.items;
import cpw.mods.ironchest.common.blocks.shulker.IronShulkerBoxType;
import cpw.mods.ironchest.common.items.shulker.ItemShulkerBoxChanger;
import net.minecraft.item.Item;
import net.minecraftforge.registries.IForgeRegistry;
import static cpw.mods.ironchest.common.blocks.shulker.IronShulkerBoxType.COPPER;
import static cpw.mods.ironchest.common.blocks.shulker.IronShulkerBoxType.CRYSTAL;
import static cpw.mods.ironchest.common.blocks.shulker.IronShulkerBoxType.DIAMOND;
@ -20,6 +15,11 @@ import static cpw.mods.ironchest.common.blocks.shulker.IronShulkerBoxType.OBSIDI
import static cpw.mods.ironchest.common.blocks.shulker.IronShulkerBoxType.SILVER;
import static cpw.mods.ironchest.common.blocks.shulker.IronShulkerBoxType.VANILLA;
import cpw.mods.ironchest.common.blocks.shulker.IronShulkerBoxType;
import cpw.mods.ironchest.common.items.shulker.ItemShulkerBoxChanger;
import net.minecraft.item.Item;
import net.minecraftforge.registries.IForgeRegistry;
public enum ShulkerBoxChangerType
{
//@formatter:off

View File

@ -10,6 +10,8 @@
******************************************************************************/
package cpw.mods.ironchest.common.items.chest;
import java.util.Locale;
import cpw.mods.ironchest.common.blocks.chest.BlockIronChest;
import cpw.mods.ironchest.common.blocks.chest.IronChestType;
import cpw.mods.ironchest.common.core.IronChestBlocks;
@ -30,8 +32,6 @@ import net.minecraft.util.NonNullList;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import java.util.Locale;
public class ItemChestChanger extends ItemTooltip
{
public final ChestChangerType type;
@ -48,7 +48,9 @@ public class ItemChestChanger extends ItemTooltip
* Called when a Block is right-clicked with this Item
*/
@Override
//@formatter:off
public EnumActionResult onItemUseFirst(EntityPlayer playerIn, World worldIn, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, EnumHand hand)
//@formatter:on
{
ItemStack itemstack = playerIn.getHeldItem(hand);
@ -77,10 +79,8 @@ public class ItemChestChanger extends ItemTooltip
TileEntity te = worldIn.getTileEntity(pos);
TileEntityIronChest newchest = new TileEntityIronChest();
NonNullList<ItemStack> chestContents = NonNullList.<ItemStack>withSize(27, ItemStack.EMPTY);
NonNullList<ItemStack> chestContents = NonNullList.<ItemStack> withSize(27, ItemStack.EMPTY);
EnumFacing chestFacing = EnumFacing.DOWN;
boolean hasCustomName = false;
String customName = "";
if (te != null)
{
@ -88,13 +88,6 @@ public class ItemChestChanger extends ItemTooltip
{
chestContents = ((TileEntityIronChest) te).getItems();
chestFacing = ((TileEntityIronChest) te).getFacing();
if (((TileEntityIronChest) te).hasCustomName())
{
hasCustomName = true;
customName = ((TileEntityIronChest) te).getName();
}
newchest = this.type.target.makeEntity();
if (newchest == null)
@ -117,19 +110,13 @@ public class ItemChestChanger extends ItemTooltip
return EnumActionResult.PASS;
}
chestContents = NonNullList.<ItemStack>withSize(chest.getSizeInventory(), ItemStack.EMPTY);
chestContents = NonNullList.<ItemStack> withSize(chest.getSizeInventory(), ItemStack.EMPTY);
for (int i = 0; i < chestContents.size(); i++)
{
chestContents.set(i, chest.getStackInSlot(i));
}
if (chest.hasCustomName())
{
hasCustomName = true;
customName = chest.getName();
}
newchest = this.type.target.makeEntity();
}
}
@ -157,11 +144,6 @@ public class ItemChestChanger extends ItemTooltip
{
((TileEntityIronChest) te2).setContents(chestContents);
((TileEntityIronChest) te2).setFacing(chestFacing);
if (hasCustomName)
{
((TileEntityIronChest) te2).setCustomName(customName);
}
}
if (!playerIn.capabilities.isCreativeMode)

View File

@ -10,13 +10,13 @@
******************************************************************************/
package cpw.mods.ironchest.common.items.chest;
import java.util.Locale;
import cpw.mods.ironchest.common.blocks.chest.IronChestType;
import net.minecraft.block.Block;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import java.util.Locale;
public class ItemIronChest extends ItemBlock
{
public ItemIronChest(Block block)

View File

@ -10,14 +10,14 @@
******************************************************************************/
package cpw.mods.ironchest.common.items.shulker;
import java.util.Locale;
import cpw.mods.ironchest.common.blocks.shulker.IronShulkerBoxType;
import net.minecraft.block.Block;
import net.minecraft.item.EnumDyeColor;
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;
import java.util.Locale;
public class ItemIronShulkerBox extends ItemBlock
{
private final String colorName;

View File

@ -10,6 +10,8 @@
******************************************************************************/
package cpw.mods.ironchest.common.items.shulker;
import java.util.Locale;
import cpw.mods.ironchest.common.blocks.shulker.BlockIronShulkerBox;
import cpw.mods.ironchest.common.blocks.shulker.IronShulkerBoxType;
import cpw.mods.ironchest.common.core.IronChestCreativeTabs;
@ -32,8 +34,6 @@ import net.minecraft.util.NonNullList;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import java.util.Locale;
public class ItemShulkerBoxChanger extends ItemTooltip
{
public final ShulkerBoxChangerType type;
@ -88,7 +88,9 @@ public class ItemShulkerBoxChanger extends ItemTooltip
* Called when a Block is right-clicked with this Item
*/
@Override
//@formatter:off
public EnumActionResult onItemUseFirst(EntityPlayer playerIn, World worldIn, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, EnumHand hand)
//@formatter:on
{
ItemStack itemstack = playerIn.getHeldItem(hand);
@ -125,11 +127,9 @@ public class ItemShulkerBoxChanger extends ItemTooltip
TileEntityIronShulkerBox newShulkerBox = new TileEntityIronShulkerBox();
NonNullList<ItemStack> shulkerBoxContents = NonNullList.<ItemStack>withSize(27, ItemStack.EMPTY);
NonNullList<ItemStack> shulkerBoxContents = NonNullList.<ItemStack> withSize(27, ItemStack.EMPTY);
EnumFacing shulkerBoxFacing = EnumFacing.UP;
EnumDyeColor shulkerBoxColor = EnumDyeColor.PURPLE;
boolean hasCustomName = false;
String customName = "";
if (te != null)
{
@ -140,12 +140,6 @@ public class ItemShulkerBoxChanger extends ItemTooltip
shulkerBoxColor = getColorFromTileEntity(te, worldIn);
((TileEntityIronShulkerBox) te).setHasBeenUpgraded();
if (((TileEntityIronShulkerBox) te).hasCustomName())
{
hasCustomName = true;
customName = ((TileEntityIronShulkerBox) te).getName();
}
newShulkerBox = this.type.target.makeEntity(shulkerBoxColor);
if (newShulkerBox == null)
@ -164,19 +158,13 @@ public class ItemShulkerBoxChanger extends ItemTooltip
return EnumActionResult.PASS;
}
shulkerBoxContents = NonNullList.<ItemStack>withSize(shulkerBox.getSizeInventory(), ItemStack.EMPTY);
shulkerBoxContents = NonNullList.<ItemStack> withSize(shulkerBox.getSizeInventory(), ItemStack.EMPTY);
for (int i = 0; i < shulkerBoxContents.size(); i++)
{
shulkerBoxContents.set(i, shulkerBox.getStackInSlot(i));
}
if (shulkerBox.hasCustomName())
{
hasCustomName = true;
customName = shulkerBox.getName();
}
shulkerBoxColor = getColorFromTileEntity(te, worldIn);
shulkerBox.clear();
@ -214,11 +202,6 @@ public class ItemShulkerBoxChanger extends ItemTooltip
{
((TileEntityIronShulkerBox) te2).setContents(shulkerBoxContents);
((TileEntityIronShulkerBox) te2).setFacing(shulkerBoxFacing);
if (hasCustomName)
{
((TileEntityIronShulkerBox) te2).setCustomName(customName);
}
}
if (!playerIn.capabilities.isCreativeMode)

View File

@ -1,6 +1,9 @@
package cpw.mods.ironchest.common.lib;
import java.util.List;
import com.google.common.collect.Lists;
import cpw.mods.ironchest.common.core.IronChestBlocks;
import cpw.mods.ironchest.common.util.BehaviorDispenseIronShulkerBox;
import net.minecraft.block.Block;
@ -9,8 +12,6 @@ import net.minecraft.init.Blocks;
import net.minecraft.item.EnumDyeColor;
import net.minecraft.item.ItemBlock;
import java.util.List;
public class BlockLists
{
//@formatter:off

View File

@ -8,14 +8,14 @@
package cpw.mods.ironchest.common.lib;
import javax.annotation.Nonnull;
import cpw.mods.ironchest.common.tileentity.chest.TileEntityIronChest;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraftforge.items.IItemHandlerModifiable;
import net.minecraftforge.items.ItemHandlerHelper;
import javax.annotation.Nonnull;
public class ICChestInventoryHandler implements IItemHandlerModifiable
{
TileEntityIronChest inv;
@ -41,36 +41,29 @@ public class ICChestInventoryHandler implements IItemHandlerModifiable
public ItemStack insertItem(int slot, ItemStack stack, boolean simulate)
{
if (stack.isEmpty())
{
return stack;
}
stack = stack.copy();
if (!this.inv.isItemValidForSlot(slot, stack))
{
if (!inv.isItemValidForSlot(slot, stack))
return stack;
}
ItemStack currentStack = this.inv.getItems().get(slot);
int offsetSlot = slot;
ItemStack currentStack = inv.getItems().get(offsetSlot);
if (currentStack.isEmpty())
{
int accepted = Math.min(stack.getMaxStackSize(), this.inv.getInventoryStackLimit());
int accepted = Math.min(stack.getMaxStackSize(), inv.getInventoryStackLimit());
if (accepted < stack.getCount())
{
if (!simulate)
{
this.inv.getItems().set(slot, stack.splitStack(accepted));
this.inv.markDirty();
inv.getItems().set(offsetSlot, stack.splitStack(accepted));
inv.markDirty();
return stack;
}
else
{
stack.shrink(accepted);
return stack;
}
}
@ -78,21 +71,18 @@ public class ICChestInventoryHandler implements IItemHandlerModifiable
{
if (!simulate)
{
this.inv.getItems().set(slot, stack);
this.inv.markDirty();
inv.getItems().set(offsetSlot, stack);
inv.markDirty();
}
return ItemStack.EMPTY;
}
}
else
{
int accepted = Math.min(stack.getMaxStackSize(), this.inv.getInventoryStackLimit()) - currentStack.getCount();
int accepted = Math.min(stack.getMaxStackSize(), inv.getInventoryStackLimit()) - currentStack.getCount();
if (accepted <= 0 || !ItemHandlerHelper.canItemStacksStack(stack, currentStack))
{
return stack;
}
if (accepted < stack.getCount())
{
@ -100,15 +90,13 @@ public class ICChestInventoryHandler implements IItemHandlerModifiable
{
ItemStack newStack = stack.splitStack(accepted);
newStack.grow(currentStack.getCount());
this.inv.getItems().set(slot, newStack);
this.inv.markDirty();
inv.getItems().set(offsetSlot, newStack);
inv.markDirty();
return stack;
}
else
{
stack.shrink(accepted);
return stack;
}
}
@ -118,10 +106,9 @@ public class ICChestInventoryHandler implements IItemHandlerModifiable
{
ItemStack newStack = stack.copy();
newStack.grow(currentStack.getCount());
this.inv.getItems().set(slot, newStack);
this.inv.markDirty();
inv.getItems().set(offsetSlot, newStack);
inv.markDirty();
}
return ItemStack.EMPTY;
}
}
@ -131,55 +118,45 @@ public class ICChestInventoryHandler implements IItemHandlerModifiable
public ItemStack extractItem(int slot, int amount, boolean simulate)
{
if (amount == 0)
{
return ItemStack.EMPTY;
}
ItemStack currentStack = this.inv.getItems().get(slot);
int offsetSlot = slot;
ItemStack currentStack = inv.getItems().get(offsetSlot);
if (currentStack.isEmpty())
{
return ItemStack.EMPTY;
}
int extracted = Math.min(currentStack.getCount(), amount);
ItemStack copy = currentStack.copy();
copy.setCount(extracted);
if (!simulate)
{
if (extracted < currentStack.getCount())
{
currentStack.shrink(extracted);
}
else
{
currentStack = ItemStack.EMPTY;
}
this.inv.getItems().set(slot, currentStack);
this.inv.markDirty();
inv.getItems().set(offsetSlot, currentStack);
inv.markDirty();
}
return copy;
}
@Override
public int getSlotLimit(int slot)
{
return this.getInv().getInventoryStackLimit();
return getInv().getInventoryStackLimit();
}
@Override
public void setStackInSlot(int slot, @Nonnull ItemStack stack)
{
this.inv.getItems().set(slot, stack);
this.inv.markDirty();
inv.getItems().set(slot, stack);
inv.markDirty();
}
public IInventory getInv()
{
return this.inv;
return inv;
}
}

View File

@ -8,14 +8,14 @@
package cpw.mods.ironchest.common.lib;
import javax.annotation.Nonnull;
import cpw.mods.ironchest.common.tileentity.shulker.TileEntityIronShulkerBox;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraftforge.items.IItemHandlerModifiable;
import net.minecraftforge.items.ItemHandlerHelper;
import javax.annotation.Nonnull;
public class ICShulkerInventoryHandler implements IItemHandlerModifiable
{
TileEntityIronShulkerBox inv;
@ -41,36 +41,29 @@ public class ICShulkerInventoryHandler implements IItemHandlerModifiable
public ItemStack insertItem(int slot, ItemStack stack, boolean simulate)
{
if (stack.isEmpty())
{
return stack;
}
stack = stack.copy();
if (!this.inv.isItemValidForSlot(slot, stack))
{
if (!inv.isItemValidForSlot(slot, stack))
return stack;
}
ItemStack currentStack = this.inv.getItems().get(slot);
int offsetSlot = slot;
ItemStack currentStack = inv.getItems().get(offsetSlot);
if (currentStack.isEmpty())
{
int accepted = Math.min(stack.getMaxStackSize(), this.inv.getInventoryStackLimit());
int accepted = Math.min(stack.getMaxStackSize(), inv.getInventoryStackLimit());
if (accepted < stack.getCount())
{
if (!simulate)
{
this.inv.getItems().set(slot, stack.splitStack(accepted));
this.inv.markDirty();
inv.getItems().set(offsetSlot, stack.splitStack(accepted));
inv.markDirty();
return stack;
}
else
{
stack.shrink(accepted);
return stack;
}
}
@ -78,21 +71,18 @@ public class ICShulkerInventoryHandler implements IItemHandlerModifiable
{
if (!simulate)
{
this.inv.getItems().set(slot, stack);
this.inv.markDirty();
inv.getItems().set(offsetSlot, stack);
inv.markDirty();
}
return ItemStack.EMPTY;
}
}
else
{
int accepted = Math.min(stack.getMaxStackSize(), this.inv.getInventoryStackLimit()) - currentStack.getCount();
int accepted = Math.min(stack.getMaxStackSize(), inv.getInventoryStackLimit()) - currentStack.getCount();
if (accepted <= 0 || !ItemHandlerHelper.canItemStacksStack(stack, currentStack))
{
return stack;
}
if (accepted < stack.getCount())
{
@ -100,15 +90,13 @@ public class ICShulkerInventoryHandler implements IItemHandlerModifiable
{
ItemStack newStack = stack.splitStack(accepted);
newStack.grow(currentStack.getCount());
this.inv.getItems().set(slot, newStack);
this.inv.markDirty();
inv.getItems().set(offsetSlot, newStack);
inv.markDirty();
return stack;
}
else
{
stack.shrink(accepted);
return stack;
}
}
@ -118,10 +106,9 @@ public class ICShulkerInventoryHandler implements IItemHandlerModifiable
{
ItemStack newStack = stack.copy();
newStack.grow(currentStack.getCount());
this.inv.getItems().set(slot, newStack);
this.inv.markDirty();
inv.getItems().set(offsetSlot, newStack);
inv.markDirty();
}
return ItemStack.EMPTY;
}
}
@ -131,55 +118,45 @@ public class ICShulkerInventoryHandler implements IItemHandlerModifiable
public ItemStack extractItem(int slot, int amount, boolean simulate)
{
if (amount == 0)
{
return ItemStack.EMPTY;
}
ItemStack currentStack = this.inv.getItems().get(slot);
int offsetSlot = slot;
ItemStack currentStack = inv.getItems().get(offsetSlot);
if (currentStack.isEmpty())
{
return ItemStack.EMPTY;
}
int extracted = Math.min(currentStack.getCount(), amount);
ItemStack copy = currentStack.copy();
copy.setCount(extracted);
if (!simulate)
{
if (extracted < currentStack.getCount())
{
currentStack.shrink(extracted);
}
else
{
currentStack = ItemStack.EMPTY;
}
this.inv.getItems().set(slot, currentStack);
this.inv.markDirty();
inv.getItems().set(offsetSlot, currentStack);
inv.markDirty();
}
return copy;
}
@Override
public int getSlotLimit(int slot)
{
return this.getInv().getInventoryStackLimit();
return getInv().getInventoryStackLimit();
}
@Override
public void setStackInSlot(int slot, @Nonnull ItemStack stack)
{
this.inv.getItems().set(slot, stack);
this.inv.markDirty();
inv.getItems().set(slot, stack);
inv.markDirty();
}
public IInventory getInv()
{
return this.inv;
return inv;
}
}

View File

@ -11,7 +11,6 @@
package cpw.mods.ironchest.common.network;
import cpw.mods.ironchest.IronChest;
import cpw.mods.ironchest.common.tileentity.chest.TileEntityCrystalChest;
import cpw.mods.ironchest.common.tileentity.chest.TileEntityIronChest;
import io.netty.buffer.ByteBuf;
import net.minecraft.item.ItemStack;
@ -27,21 +26,14 @@ import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
public class MessageCrystalChestSync implements IMessage
{
int dimension;
BlockPos pos;
private NonNullList<ItemStack> topStacks;
public MessageCrystalChestSync(int dimensionId, BlockPos tilePos, NonNullList<ItemStack> stackList)
public MessageCrystalChestSync(TileEntityIronChest tile, NonNullList<ItemStack> stack)
{
this.dimension = dimensionId;
this.pos = tilePos;
this.topStacks = stackList;
}
public MessageCrystalChestSync(TileEntityIronChest tile, NonNullList<ItemStack> stacklist)
{
this(tile.getWorld().provider.getDimension(), tile.getPos(), stacklist);
this.dimension = tile.getWorld().provider.getDimension();
this.pos = tile.getPos();
this.topStacks = stack;
}
public MessageCrystalChestSync()
@ -55,7 +47,7 @@ public class MessageCrystalChestSync implements IMessage
this.pos = new BlockPos(buf.readInt(), buf.readInt(), buf.readInt());
int size = buf.readInt();
this.topStacks = NonNullList.<ItemStack>withSize(size, ItemStack.EMPTY);
this.topStacks = NonNullList.<ItemStack> withSize(size, ItemStack.EMPTY);
for (int i = 0; i < size; i++)
{
@ -91,10 +83,8 @@ public class MessageCrystalChestSync implements IMessage
{
TileEntity tile = world.getTileEntity(message.pos);
if (tile instanceof TileEntityCrystalChest)
{
((TileEntityCrystalChest) tile).receiveMessageFromServer(message.topStacks);
}
if (tile instanceof TileEntityIronChest)
((TileEntityIronChest) tile).receiveMessageFromServer(message.topStacks);
}
return null;

View File

@ -11,7 +11,6 @@
package cpw.mods.ironchest.common.network;
import cpw.mods.ironchest.IronChest;
import cpw.mods.ironchest.common.tileentity.shulker.TileEntityCrystalShulkerBox;
import cpw.mods.ironchest.common.tileentity.shulker.TileEntityIronShulkerBox;
import io.netty.buffer.ByteBuf;
import net.minecraft.item.ItemStack;
@ -32,16 +31,11 @@ public class MessageCrystalShulkerSync implements IMessage
private NonNullList<ItemStack> topStacks;
public MessageCrystalShulkerSync(int dimensionId, BlockPos tilePos, NonNullList<ItemStack> stackList)
public MessageCrystalShulkerSync(TileEntityIronShulkerBox tile, NonNullList<ItemStack> stack)
{
this.dimension = dimensionId;
this.pos = tilePos;
this.topStacks = stackList;
}
public MessageCrystalShulkerSync(TileEntityIronShulkerBox tile, NonNullList<ItemStack> stacklist)
{
this(tile.getWorld().provider.getDimension(), tile.getPos(), stacklist);
this.dimension = tile.getWorld().provider.getDimension();
this.pos = tile.getPos();
this.topStacks = stack;
}
public MessageCrystalShulkerSync()
@ -55,7 +49,7 @@ public class MessageCrystalShulkerSync implements IMessage
this.pos = new BlockPos(buf.readInt(), buf.readInt(), buf.readInt());
int size = buf.readInt();
this.topStacks = NonNullList.<ItemStack>withSize(size, ItemStack.EMPTY);
this.topStacks = NonNullList.<ItemStack> withSize(size, ItemStack.EMPTY);
for (int i = 0; i < size; i++)
{
@ -91,10 +85,8 @@ public class MessageCrystalShulkerSync implements IMessage
{
TileEntity tile = world.getTileEntity(message.pos);
if (tile instanceof TileEntityCrystalShulkerBox)
{
((TileEntityCrystalShulkerBox) tile).receiveMessageFromServer(message.topStacks);
}
if (tile instanceof TileEntityIronShulkerBox)
((TileEntityIronShulkerBox) tile).receiveMessageFromServer(message.topStacks);
}
return null;

View File

@ -10,238 +10,16 @@
******************************************************************************/
package cpw.mods.ironchest.common.tileentity.chest;
import cpw.mods.ironchest.IronChest;
import cpw.mods.ironchest.common.blocks.chest.IronChestType;
import cpw.mods.ironchest.common.network.MessageCrystalChestSync;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.NonNullList;
import net.minecraft.util.datafix.DataFixer;
import net.minecraft.util.datafix.FixTypes;
import net.minecraft.util.datafix.walkers.ItemStackDataLists;
import net.minecraftforge.fml.common.network.NetworkRegistry;
import java.util.Collections;
public class TileEntityCrystalChest extends TileEntityIronChest
{
/** Crystal Chest top stacks */
private NonNullList<ItemStack> topStacks;
/** If the inventory got touched */
private boolean inventoryTouched;
/** If the inventory had items */
private boolean hadStuff;
public TileEntityCrystalChest()
{
super(IronChestType.CRYSTAL);
this.topStacks = NonNullList.<ItemStack>withSize(8, ItemStack.EMPTY);
}
public NonNullList<ItemStack> getTopItems()
{
return this.topStacks;
}
@Override
public void setContents(NonNullList<ItemStack> contents)
{
super.setContents(contents);
this.inventoryTouched = true;
}
@Override
public ItemStack getStackInSlot(int index)
{
this.fillWithLoot((EntityPlayer) null);
this.inventoryTouched = true;
return this.getItems().get(index);
}
@Override
public void markDirty()
{
super.markDirty();
this.sortTopStacks();
}
@Override
public void readFromNBT(NBTTagCompound compound)
{
super.readFromNBT(compound);
this.sortTopStacks();
}
@Override
public void update()
{
super.update();
if (!this.world.isRemote && this.inventoryTouched)
{
this.inventoryTouched = false;
this.sortTopStacks();
}
}
protected void sortTopStacks()
{
if (!this.getType().isTransparent() || (this.world != null && this.world.isRemote))
{
return;
}
NonNullList<ItemStack> tempCopy = NonNullList.<ItemStack>withSize(this.getSizeInventory(), ItemStack.EMPTY);
boolean hasStuff = false;
int compressedIdx = 0;
mainLoop:
for (int i = 0; i < this.getSizeInventory(); i++)
{
ItemStack itemStack = this.getItems().get(i);
if (!itemStack.isEmpty())
{
for (int j = 0; j < compressedIdx; j++)
{
ItemStack tempCopyStack = tempCopy.get(j);
if (ItemStack.areItemsEqualIgnoreDurability(tempCopyStack, itemStack))
{
if (itemStack.getCount() != tempCopyStack.getCount())
{
tempCopyStack.grow(itemStack.getCount());
}
continue mainLoop;
}
}
tempCopy.set(compressedIdx, itemStack.copy());
compressedIdx++;
hasStuff = true;
}
}
if (!hasStuff && this.hadStuff)
{
this.hadStuff = false;
for (int i = 0; i < this.getTopItems().size(); i++)
{
this.getTopItems().set(i, ItemStack.EMPTY);
}
if (this.world != null)
{
IBlockState iblockstate = this.world.getBlockState(this.pos);
this.world.notifyBlockUpdate(this.pos, iblockstate, iblockstate, 3);
}
return;
}
this.hadStuff = true;
Collections.sort(tempCopy, (stack1, stack2) -> {
if (stack1.isEmpty())
{
return 1;
}
else if (stack2.isEmpty())
{
return -1;
}
else
{
return stack2.getCount() - stack1.getCount();
}
});
int p = 0;
for (ItemStack element : tempCopy)
{
if (!element.isEmpty() && element.getCount() > 0)
{
if (p == this.getTopItems().size())
{
break;
}
this.getTopItems().set(p, element);
p++;
}
}
for (int i = p; i < this.getTopItems().size(); i++)
{
this.getTopItems().set(i, ItemStack.EMPTY);
}
if (this.world != null)
{
IBlockState iblockstate = this.world.getBlockState(this.pos);
this.world.notifyBlockUpdate(this.pos, iblockstate, iblockstate, 3);
}
this.sendTopStacksPacket();
}
public NonNullList<ItemStack> buildItemStackDataList()
{
if (this.getType().isTransparent())
{
NonNullList<ItemStack> sortList = NonNullList.<ItemStack>withSize(this.getTopItems().size(), ItemStack.EMPTY);
int pos = 0;
for (ItemStack is : this.topStacks)
{
if (!is.isEmpty())
{
sortList.set(pos, is);
}
else
{
sortList.set(pos, ItemStack.EMPTY);
}
pos++;
}
return sortList;
}
return NonNullList.<ItemStack>withSize(this.getTopItems().size(), ItemStack.EMPTY);
}
protected void sendTopStacksPacket()
{
NonNullList<ItemStack> stacks = this.buildItemStackDataList();
IronChest.packetHandler.sendToAllAround(new MessageCrystalChestSync(this.getWorld().provider.getDimension(), this.getPos(), stacks), new NetworkRegistry.TargetPoint(world.provider.getDimension(), getPos().getX(), getPos().getY(), getPos().getZ(), 128));
}
public void receiveMessageFromServer(NonNullList<ItemStack> topStacks)
{
this.topStacks = topStacks;
}
public static void registerFixesChest(DataFixer fixer)

View File

@ -10,11 +10,16 @@
******************************************************************************/
package cpw.mods.ironchest.common.tileentity.chest;
import java.util.Collections;
import java.util.Comparator;
import cpw.mods.ironchest.IronChest;
import cpw.mods.ironchest.common.blocks.chest.BlockIronChest;
import cpw.mods.ironchest.common.blocks.chest.IronChestType;
import cpw.mods.ironchest.common.core.IronChestBlocks;
import cpw.mods.ironchest.common.gui.chest.ContainerIronChest;
import cpw.mods.ironchest.common.lib.ICChestInventoryHandler;
import cpw.mods.ironchest.common.network.MessageCrystalChestSync;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
@ -37,6 +42,7 @@ import net.minecraft.util.datafix.walkers.ItemStackDataLists;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.util.Constants;
import net.minecraftforge.fml.common.network.NetworkRegistry.TargetPoint;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.IItemHandler;
@ -45,6 +51,9 @@ public class TileEntityIronChest extends TileEntityLockableLoot implements ITick
/** Chest Contents */
public NonNullList<ItemStack> chestContents;
/** Crystal Chest top stacks */
private NonNullList<ItemStack> topStacks;
/** The current angle of the lid (between 0 and 1) */
public float lidAngle;
@ -60,6 +69,12 @@ public class TileEntityIronChest extends TileEntityLockableLoot implements ITick
/** Direction chest is facing */
private EnumFacing facing;
/** If the inventory got touched */
private boolean inventoryTouched;
/** If the inventory had items */
private boolean hadStuff;
private String customName;
private IronChestType chestType;
@ -73,13 +88,14 @@ public class TileEntityIronChest extends TileEntityLockableLoot implements ITick
{
super();
this.chestType = type;
this.chestContents = NonNullList.withSize(type.size, ItemStack.EMPTY);
this.chestContents = NonNullList.<ItemStack> withSize(type.size, ItemStack.EMPTY);
this.topStacks = NonNullList.<ItemStack> withSize(8, ItemStack.EMPTY);
this.facing = EnumFacing.NORTH;
}
public void setContents(NonNullList<ItemStack> contents)
{
this.chestContents = NonNullList.withSize(this.getType().size, ItemStack.EMPTY);
this.chestContents = NonNullList.<ItemStack> withSize(this.getType().size, ItemStack.EMPTY);
for (int i = 0; i < contents.size(); i++)
{
@ -88,6 +104,8 @@ public class TileEntityIronChest extends TileEntityLockableLoot implements ITick
this.getItems().set(i, contents.get(i));
}
}
this.inventoryTouched = true;
}
@Override
@ -121,7 +139,9 @@ public class TileEntityIronChest extends TileEntityLockableLoot implements ITick
@Override
public ItemStack getStackInSlot(int index)
{
this.fillWithLoot(null);
this.fillWithLoot((EntityPlayer) null);
this.inventoryTouched = true;
return this.getItems().get(index);
}
@ -130,6 +150,124 @@ public class TileEntityIronChest extends TileEntityLockableLoot implements ITick
public void markDirty()
{
super.markDirty();
this.sortTopStacks();
}
protected void sortTopStacks()
{
if (!this.getType().isTransparent() || (this.world != null && this.world.isRemote))
{
return;
}
NonNullList<ItemStack> tempCopy = NonNullList.<ItemStack> withSize(this.getSizeInventory(), ItemStack.EMPTY);
boolean hasStuff = false;
int compressedIdx = 0;
mainLoop:
for (int i = 0; i < this.getSizeInventory(); i++)
{
ItemStack itemStack = this.getItems().get(i);
if (!itemStack.isEmpty())
{
for (int j = 0; j < compressedIdx; j++)
{
ItemStack tempCopyStack = tempCopy.get(j);
if (ItemStack.areItemsEqualIgnoreDurability(tempCopyStack, itemStack))
{
if (itemStack.getCount() != tempCopyStack.getCount())
{
tempCopyStack.grow(itemStack.getCount());
}
continue mainLoop;
}
}
tempCopy.set(compressedIdx, itemStack.copy());
compressedIdx++;
hasStuff = true;
}
}
if (!hasStuff && this.hadStuff)
{
this.hadStuff = false;
for (int i = 0; i < this.getTopItems().size(); i++)
{
this.getTopItems().set(i, ItemStack.EMPTY);
}
if (this.world != null)
{
IBlockState iblockstate = this.world.getBlockState(this.pos);
this.world.notifyBlockUpdate(this.pos, iblockstate, iblockstate, 3);
}
return;
}
this.hadStuff = true;
Collections.sort(tempCopy, new Comparator<ItemStack>()
{
@Override
public int compare(ItemStack stack1, ItemStack stack2)
{
if (stack1.isEmpty())
{
return 1;
}
else if (stack2.isEmpty())
{
return -1;
}
else
{
return stack2.getCount() - stack1.getCount();
}
}
});
int p = 0;
for (ItemStack element : tempCopy)
{
if (!element.isEmpty() && element.getCount() > 0)
{
if (p == this.getTopItems().size())
{
break;
}
this.getTopItems().set(p, element);
p++;
}
}
for (int i = p; i < this.getTopItems().size(); i++)
{
this.getTopItems().set(i, ItemStack.EMPTY);
}
if (this.world != null)
{
IBlockState iblockstate = this.world.getBlockState(this.pos);
this.world.notifyBlockUpdate(this.pos, iblockstate, iblockstate, 3);
}
sendTopStacksPacket();
}
@Override
@ -155,7 +293,7 @@ public class TileEntityIronChest extends TileEntityLockableLoot implements ITick
{
super.readFromNBT(compound);
this.chestContents = NonNullList.withSize(this.getSizeInventory(), ItemStack.EMPTY);
this.chestContents = NonNullList.<ItemStack> withSize(this.getSizeInventory(), ItemStack.EMPTY);
if (compound.hasKey("CustomName", Constants.NBT.TAG_STRING))
{
@ -168,6 +306,8 @@ public class TileEntityIronChest extends TileEntityLockableLoot implements ITick
}
this.facing = EnumFacing.VALUES[compound.getByte("facing")];
this.sortTopStacks();
}
@Override
@ -215,17 +355,18 @@ public class TileEntityIronChest extends TileEntityLockableLoot implements ITick
@Override
public void update()
{
int x = this.pos.getX();
int y = this.pos.getY();
int z = this.pos.getZ();
++this.ticksSinceSync;
// Resynchronizes clients with the server state
if (this.world != null && !this.world.isRemote && this.numPlayersUsing != 0 && (this.ticksSinceSync + x + y + z) % 200 == 0)
//@formatter:off
if (this.world != null && !this.world.isRemote && this.numPlayersUsing != 0 && (this.ticksSinceSync + this.pos.getX() + this.pos.getY() + this.pos.getZ()) % 200 == 0)
//@formatter:on
{
this.numPlayersUsing = 0;
for (EntityPlayer player : this.world.getEntitiesWithinAABB(EntityPlayer.class, new AxisAlignedBB(x - 5.0F, y - 5.0F, z - 5.0F, x + 1 + 5.0F, y + 1 + 5.0F, z + 1 + 5.0F)))
float f = 5.0F;
//@formatter:off
for (EntityPlayer player : this.world.getEntitiesWithinAABB(EntityPlayer.class, new AxisAlignedBB(this.pos.getX() - f, this.pos.getY() - f, this.pos.getZ() - f, this.pos.getX() + 1 + f, this.pos.getY() + 1 + f, this.pos.getZ() + 1 + f)))
//@formatter:on
{
if (player.openContainer instanceof ContainerIronChest)
{
@ -239,16 +380,26 @@ public class TileEntityIronChest extends TileEntityLockableLoot implements ITick
this.world.addBlockEvent(this.pos, IronChestBlocks.ironChestBlock, 3, ((this.numPlayersUsing << 3) & 0xF8) | (this.facing.ordinal() & 0x7));
}
if (!this.world.isRemote && this.inventoryTouched)
{
this.inventoryTouched = false;
this.sortTopStacks();
}
this.ticksSinceSync++;
this.prevLidAngle = this.lidAngle;
float angle = 0.1F;
if (this.numPlayersUsing > 0 && this.lidAngle == 0.0F)
{
double soundX = x + 0.5D;
double soundY = y + 0.5D;
double soundZ = z + 0.5D;
double x = this.pos.getX() + 0.5D;
double y = this.pos.getY() + 0.5D;
double z = this.pos.getZ() + 0.5D;
this.world.playSound(null, soundX, soundY, soundZ, SoundEvents.BLOCK_CHEST_OPEN, SoundCategory.BLOCKS, 0.5F, this.world.rand.nextFloat() * 0.1F + 0.9F);
this.world.playSound(null, x, y, z, SoundEvents.BLOCK_CHEST_OPEN, SoundCategory.BLOCKS, 0.5F, this.world.rand.nextFloat() * 0.1F + 0.9F);
}
if (this.numPlayersUsing == 0 && this.lidAngle > 0.0F || this.numPlayersUsing > 0 && this.lidAngle < 1.0F)
@ -273,11 +424,11 @@ public class TileEntityIronChest extends TileEntityLockableLoot implements ITick
if (this.lidAngle < maxAngle && currentAngle >= maxAngle)
{
double soundX = x + 0.5D;
double soundY = y + 0.5D;
double soundZ = z + 0.5D;
double x = this.pos.getX() + 0.5D;
double y = this.pos.getY() + 0.5D;
double z = this.pos.getZ() + 0.5D;
this.world.playSound(null, soundX, soundY, soundZ, SoundEvents.BLOCK_CHEST_CLOSE, SoundCategory.BLOCKS, 0.5F, this.world.rand.nextFloat() * 0.1F + 0.9F);
this.world.playSound(null, x, y, z, SoundEvents.BLOCK_CHEST_CLOSE, SoundCategory.BLOCKS, 0.5F, this.world.rand.nextFloat() * 0.1F + 0.9F);
}
if (this.lidAngle < 0.0F)
@ -304,7 +455,7 @@ public class TileEntityIronChest extends TileEntityLockableLoot implements ITick
this.numPlayersUsing = (type & 0xF8) >> 3;
}
return super.receiveClientEvent(id, type);
return true;
}
@Override
@ -312,6 +463,11 @@ public class TileEntityIronChest extends TileEntityLockableLoot implements ITick
{
if (!player.isSpectator())
{
if (this.world == null)
{
return;
}
if (this.numPlayersUsing < 0)
{
this.numPlayersUsing = 0;
@ -321,6 +477,7 @@ public class TileEntityIronChest extends TileEntityLockableLoot implements ITick
this.world.addBlockEvent(this.pos, IronChestBlocks.ironChestBlock, 1, this.numPlayersUsing);
this.world.notifyNeighborsOfStateChange(this.pos, IronChestBlocks.ironChestBlock, false);
this.world.notifyNeighborsOfStateChange(this.pos.down(), IronChestBlocks.ironChestBlock, false);
}
}
@ -329,10 +486,16 @@ public class TileEntityIronChest extends TileEntityLockableLoot implements ITick
{
if (!player.isSpectator())
{
if (this.world == null)
{
return;
}
--this.numPlayersUsing;
this.world.addBlockEvent(this.pos, IronChestBlocks.ironChestBlock, 1, this.numPlayersUsing);
this.world.notifyNeighborsOfStateChange(this.pos, IronChestBlocks.ironChestBlock, false);
this.world.notifyNeighborsOfStateChange(this.pos.down(), IronChestBlocks.ironChestBlock, false);
}
}
@ -362,6 +525,34 @@ public class TileEntityIronChest extends TileEntityLockableLoot implements ITick
}
}
public NonNullList<ItemStack> buildItemStackDataList()
{
if (this.getType().isTransparent())
{
NonNullList<ItemStack> sortList = NonNullList.<ItemStack> withSize(this.getTopItems().size(), ItemStack.EMPTY);
int pos = 0;
for (ItemStack is : this.topStacks)
{
if (!is.isEmpty())
{
sortList.set(pos, is);
}
else
{
sortList.set(pos, ItemStack.EMPTY);
}
pos++;
}
return sortList;
}
return NonNullList.<ItemStack> withSize(this.getTopItems().size(), ItemStack.EMPTY);
}
@Override
public boolean isItemValidForSlot(int index, ItemStack stack)
{
@ -407,19 +598,7 @@ public class TileEntityIronChest extends TileEntityLockableLoot implements ITick
public NBTTagCompound getUpdateTag()
{
NBTTagCompound compound = super.getUpdateTag();
if (!this.checkLootAndWrite(compound))
{
ItemStackHelper.saveAllItems(compound, this.chestContents);
}
compound.setByte("facing", (byte) this.facing.ordinal());
if (this.hasCustomName())
{
compound.setString("CustomName", this.customName);
}
return compound;
}
@ -429,6 +608,11 @@ public class TileEntityIronChest extends TileEntityLockableLoot implements ITick
return this.chestContents;
}
public NonNullList<ItemStack> getTopItems()
{
return this.topStacks;
}
@Override
public boolean isEmpty()
{
@ -443,18 +627,29 @@ public class TileEntityIronChest extends TileEntityLockableLoot implements ITick
return true;
}
protected void sendTopStacksPacket()
{
NonNullList<ItemStack> stacks = this.buildItemStackDataList();
//@formatter:off
IronChest.packetHandler.sendToAllAround(new MessageCrystalChestSync(this, stacks), new TargetPoint(world.provider.getDimension(), getPos().getX(), getPos().getY(), getPos().getZ(), 128));
//@formatter:on
}
public void receiveMessageFromServer(NonNullList<ItemStack> topStacks)
{
this.topStacks = topStacks;
}
public static void registerFixesChest(DataFixer fixer)
{
fixer.registerWalker(FixTypes.BLOCK_ENTITY, new ItemStackDataLists(TileEntityIronChest.class, "Items"));
fixer.registerWalker(FixTypes.BLOCK_ENTITY, new ItemStackDataLists(TileEntityIronChest.class, new String[] { "Items" }));
}
@Override
public boolean hasCapability(Capability<?> capability, EnumFacing facing)
{
if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY)
{
return true;
}
return super.hasCapability(capability, facing);
}
@ -471,9 +666,7 @@ public class TileEntityIronChest extends TileEntityLockableLoot implements ITick
public <T> T getCapability(Capability<T> capability, EnumFacing facing)
{
if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY)
{
return (T) (this.itemHandler == null ? (this.itemHandler = this.createUnSidedHandler()) : this.itemHandler);
}
return (T) (itemHandler == null ? (itemHandler = createUnSidedHandler()) : itemHandler);
return super.getCapability(capability, facing);
}
}

View File

@ -10,14 +10,14 @@
******************************************************************************/
package cpw.mods.ironchest.common.tileentity.shulker;
import javax.annotation.Nullable;
import cpw.mods.ironchest.common.blocks.shulker.IronShulkerBoxType;
import net.minecraft.item.EnumDyeColor;
import net.minecraft.util.datafix.DataFixer;
import net.minecraft.util.datafix.FixTypes;
import net.minecraft.util.datafix.walkers.ItemStackDataLists;
import javax.annotation.Nullable;
public class TileEntityCopperShulkerBox extends TileEntityIronShulkerBox
{
public TileEntityCopperShulkerBox()

View File

@ -10,32 +10,16 @@
******************************************************************************/
package cpw.mods.ironchest.common.tileentity.shulker;
import cpw.mods.ironchest.IronChest;
import javax.annotation.Nullable;
import cpw.mods.ironchest.common.blocks.shulker.IronShulkerBoxType;
import cpw.mods.ironchest.common.network.MessageCrystalShulkerSync;
import net.minecraft.item.EnumDyeColor;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.NonNullList;
import net.minecraft.util.datafix.DataFixer;
import net.minecraft.util.datafix.FixTypes;
import net.minecraft.util.datafix.walkers.ItemStackDataLists;
import net.minecraftforge.fml.common.network.NetworkRegistry;
import javax.annotation.Nullable;
import java.util.Collections;
public class TileEntityCrystalShulkerBox extends TileEntityIronShulkerBox
{
/** Crystal Shulker Boxes top stacks */
private NonNullList<ItemStack> topStacks;
/** If the inventory got touched */
private boolean inventoryTouched;
/** If the inventory had items */
private boolean hadStuff;
public TileEntityCrystalShulkerBox()
{
this(null);
@ -44,199 +28,10 @@ public class TileEntityCrystalShulkerBox extends TileEntityIronShulkerBox
public TileEntityCrystalShulkerBox(@Nullable EnumDyeColor colorIn)
{
super(colorIn, IronShulkerBoxType.CRYSTAL);
this.topStacks = NonNullList.withSize(8, ItemStack.EMPTY);
}
@Override
public void setContents(NonNullList<ItemStack> contents)
{
super.setContents(contents);
this.inventoryTouched = true;
}
@Override
public ItemStack getStackInSlot(int index)
{
this.fillWithLoot(null);
this.inventoryTouched = true;
return this.getItems().get(index);
}
@Override
public void markDirty()
{
super.markDirty();
this.sortTopStacks();
}
@Override
public void loadFromNbt(NBTTagCompound compound)
{
super.loadFromNbt(compound);
this.sortTopStacks();
}
@Override
public void update()
{
super.update();
if (!this.world.isRemote && this.inventoryTouched)
{
this.inventoryTouched = false;
this.sortTopStacks();
}
}
protected void sortTopStacks()
{
if (!this.getType().isTransparent() || (this.world != null && this.world.isRemote))
{
return;
}
NonNullList<ItemStack> tempCopy = NonNullList.withSize(this.getSizeInventory(), ItemStack.EMPTY);
boolean hasStuff = false;
int compressedIdx = 0;
mainLoop:
for (int i = 0; i < this.getSizeInventory(); i++)
{
ItemStack itemStack = this.getItems().get(i);
if (!itemStack.isEmpty())
{
for (int j = 0; j < compressedIdx; j++)
{
ItemStack tempCopyStack = tempCopy.get(j);
if (ItemStack.areItemsEqualIgnoreDurability(tempCopyStack, itemStack))
{
if (itemStack.getCount() != tempCopyStack.getCount())
{
tempCopyStack.grow(itemStack.getCount());
}
continue mainLoop;
}
}
tempCopy.set(compressedIdx, itemStack.copy());
compressedIdx++;
hasStuff = true;
}
}
if (!hasStuff && this.hadStuff)
{
this.hadStuff = false;
for (int i = 0; i < this.getTopItems().size(); i++)
{
this.getTopItems().set(i, ItemStack.EMPTY);
}
return;
}
this.hadStuff = true;
Collections.sort(tempCopy, (stack1, stack2) -> {
if (stack1.isEmpty())
{
return 1;
}
else if (stack2.isEmpty())
{
return -1;
}
else
{
return stack2.getCount() - stack1.getCount();
}
});
int p = 0;
for (ItemStack element : tempCopy)
{
if (!element.isEmpty() && element.getCount() > 0)
{
if (p == this.getTopItems().size())
{
break;
}
this.getTopItems().set(p, element);
p++;
}
}
for (int i = p; i < this.getTopItems().size(); i++)
{
this.getTopItems().set(i, ItemStack.EMPTY);
}
this.sendTopStacksPacket();
}
public NonNullList<ItemStack> getTopItems()
{
return this.topStacks;
}
public NonNullList<ItemStack> buildItemStackDataList()
{
if (this.getType().isTransparent())
{
NonNullList<ItemStack> sortList = NonNullList.withSize(this.getTopItems().size(), ItemStack.EMPTY);
int pos = 0;
for (ItemStack is : this.topStacks)
{
if (!is.isEmpty())
{
sortList.set(pos, is);
}
else
{
sortList.set(pos, ItemStack.EMPTY);
}
pos++;
}
return sortList;
}
return NonNullList.withSize(this.getTopItems().size(), ItemStack.EMPTY);
}
protected void sendTopStacksPacket()
{
NonNullList<ItemStack> stacks = this.buildItemStackDataList();
IronChest.packetHandler.sendToAllAround(new MessageCrystalShulkerSync(this.getWorld().provider.getDimension(), this.getPos(), stacks), new NetworkRegistry.TargetPoint(this.world.provider.getDimension(), this.getPos().getX(), this.getPos().getY(), this.getPos().getZ(), 128));
}
public void receiveMessageFromServer(NonNullList<ItemStack> topStacks)
{
this.topStacks = topStacks;
}
public static void registerFixesShulkerBox(DataFixer fixer)
{
fixer.registerWalker(FixTypes.BLOCK_ENTITY, new ItemStackDataLists(TileEntityCrystalShulkerBox.class, "Items"));
fixer.registerWalker(FixTypes.BLOCK_ENTITY, new ItemStackDataLists(TileEntityCrystalShulkerBox.class, new String[] { "Items" }));
}
}

View File

@ -10,14 +10,14 @@
******************************************************************************/
package cpw.mods.ironchest.common.tileentity.shulker;
import javax.annotation.Nullable;
import cpw.mods.ironchest.common.blocks.shulker.IronShulkerBoxType;
import net.minecraft.item.EnumDyeColor;
import net.minecraft.util.datafix.DataFixer;
import net.minecraft.util.datafix.FixTypes;
import net.minecraft.util.datafix.walkers.ItemStackDataLists;
import javax.annotation.Nullable;
public class TileEntityDiamondShulkerBox extends TileEntityIronShulkerBox
{
public TileEntityDiamondShulkerBox()

View File

@ -10,14 +10,14 @@
******************************************************************************/
package cpw.mods.ironchest.common.tileentity.shulker;
import javax.annotation.Nullable;
import cpw.mods.ironchest.common.blocks.shulker.IronShulkerBoxType;
import net.minecraft.item.EnumDyeColor;
import net.minecraft.util.datafix.DataFixer;
import net.minecraft.util.datafix.FixTypes;
import net.minecraft.util.datafix.walkers.ItemStackDataLists;
import javax.annotation.Nullable;
public class TileEntityGoldShulkerBox extends TileEntityIronShulkerBox
{
public TileEntityGoldShulkerBox()

View File

@ -10,10 +10,18 @@
******************************************************************************/
package cpw.mods.ironchest.common.tileentity.shulker;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import javax.annotation.Nullable;
import cpw.mods.ironchest.IronChest;
import cpw.mods.ironchest.common.blocks.shulker.BlockIronShulkerBox;
import cpw.mods.ironchest.common.blocks.shulker.IronShulkerBoxType;
import cpw.mods.ironchest.common.gui.shulker.ContainerIronShulkerBox;
import cpw.mods.ironchest.common.lib.ICShulkerInventoryHandler;
import cpw.mods.ironchest.common.network.MessageCrystalShulkerSync;
import net.minecraft.block.Block;
import net.minecraft.block.BlockShulkerBox;
import net.minecraft.block.material.EnumPushReaction;
@ -42,14 +50,12 @@ import net.minecraft.util.datafix.FixTypes;
import net.minecraft.util.datafix.walkers.ItemStackDataLists;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.fml.common.network.NetworkRegistry.TargetPoint;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.items.CapabilityItemHandler;
import net.minecraftforge.items.IItemHandler;
import javax.annotation.Nullable;
import java.util.List;
public class TileEntityIronShulkerBox extends TileEntityLockableLoot implements ITickable, ISidedInventory
{
private final int[] SLOTS;
@ -57,12 +63,21 @@ public class TileEntityIronShulkerBox extends TileEntityLockableLoot implements
/** Shulker Box Contents */
private NonNullList<ItemStack> items;
/** Crystal Shulker Boxes top stacks */
private NonNullList<ItemStack> topStacks;
/** Direction Shulker ox is facing */
private EnumFacing facing;
/** If the inventory got touched */
private boolean inventoryTouched;
/** Server sync counter (once per 20 ticks) */
private int ticksSinceSync;
/** If the inventory had items */
private boolean hadStuff;
private boolean hasBeenCleared;
private int openCount;
@ -100,7 +115,8 @@ public class TileEntityIronShulkerBox extends TileEntityLockableLoot implements
this.SLOTS = new int[typeIn.size];
this.items = NonNullList.withSize(typeIn.size, ItemStack.EMPTY);
this.items = NonNullList.<ItemStack> withSize(typeIn.size, ItemStack.EMPTY);
this.topStacks = NonNullList.<ItemStack> withSize(8, ItemStack.EMPTY);
this.animationStatus = AnimationStatus.CLOSED;
this.color = colorIn;
@ -112,7 +128,7 @@ public class TileEntityIronShulkerBox extends TileEntityLockableLoot implements
public void setContents(NonNullList<ItemStack> contents)
{
this.items = NonNullList.withSize(this.getType().size, ItemStack.EMPTY);
this.items = NonNullList.<ItemStack> withSize(this.getType().size, ItemStack.EMPTY);
for (int i = 0; i < contents.size(); i++)
{
@ -121,6 +137,8 @@ public class TileEntityIronShulkerBox extends TileEntityLockableLoot implements
this.getItems().set(i, contents.get(i));
}
}
this.inventoryTouched = true;
}
@Override
@ -154,7 +172,9 @@ public class TileEntityIronShulkerBox extends TileEntityLockableLoot implements
@Override
public ItemStack getStackInSlot(int index)
{
this.fillWithLoot(null);
this.fillWithLoot((EntityPlayer) null);
this.inventoryTouched = true;
return this.getItems().get(index);
}
@ -163,6 +183,110 @@ public class TileEntityIronShulkerBox extends TileEntityLockableLoot implements
public void markDirty()
{
super.markDirty();
this.sortTopStacks();
}
protected void sortTopStacks()
{
if (!this.getType().isTransparent() || (this.world != null && this.world.isRemote))
{
return;
}
NonNullList<ItemStack> tempCopy = NonNullList.<ItemStack> withSize(this.getSizeInventory(), ItemStack.EMPTY);
boolean hasStuff = false;
int compressedIdx = 0;
mainLoop:
for (int i = 0; i < this.getSizeInventory(); i++)
{
ItemStack itemStack = this.getItems().get(i);
if (!itemStack.isEmpty())
{
for (int j = 0; j < compressedIdx; j++)
{
ItemStack tempCopyStack = tempCopy.get(j);
if (ItemStack.areItemsEqualIgnoreDurability(tempCopyStack, itemStack))
{
if (itemStack.getCount() != tempCopyStack.getCount())
{
tempCopyStack.grow(itemStack.getCount());
}
continue mainLoop;
}
}
tempCopy.set(compressedIdx, itemStack.copy());
compressedIdx++;
hasStuff = true;
}
}
if (!hasStuff && this.hadStuff)
{
this.hadStuff = false;
for (int i = 0; i < this.getTopItems().size(); i++)
{
this.getTopItems().set(i, ItemStack.EMPTY);
}
return;
}
this.hadStuff = true;
Collections.sort(tempCopy, new Comparator<ItemStack>()
{
@Override
public int compare(ItemStack stack1, ItemStack stack2)
{
if (stack1.isEmpty())
{
return 1;
}
else if (stack2.isEmpty())
{
return -1;
}
else
{
return stack2.getCount() - stack1.getCount();
}
}
});
int p = 0;
for (ItemStack element : tempCopy)
{
if (!element.isEmpty() && element.getCount() > 0)
{
if (p == this.getTopItems().size())
{
break;
}
this.getTopItems().set(p, element);
p++;
}
}
for (int i = p; i < this.getTopItems().size(); i++)
{
this.getTopItems().set(i, ItemStack.EMPTY);
}
sendTopStacksPacket();
}
/**
@ -192,7 +316,7 @@ public class TileEntityIronShulkerBox extends TileEntityLockableLoot implements
public void loadFromNbt(NBTTagCompound compound)
{
this.items = NonNullList.withSize(this.getSizeInventory(), ItemStack.EMPTY);
this.items = NonNullList.<ItemStack> withSize(this.getSizeInventory(), ItemStack.EMPTY);
if (!this.checkLootAndRead(compound) && compound.hasKey("Items", 9))
{
@ -205,6 +329,8 @@ public class TileEntityIronShulkerBox extends TileEntityLockableLoot implements
}
this.facing = EnumFacing.VALUES[compound.getByte("facing")];
this.sortTopStacks();
}
public NBTTagCompound saveToNbt(NBTTagCompound compound)
@ -258,6 +384,13 @@ public class TileEntityIronShulkerBox extends TileEntityLockableLoot implements
this.world.addBlockEvent(this.pos, this.getBlockType(), 3, ((this.openCount << 3) & 0xF8) | (this.facing.ordinal() & 0x7));
}
if (!this.world.isRemote && this.inventoryTouched)
{
this.inventoryTouched = false;
this.sortTopStacks();
}
this.ticksSinceSync++;
}
@ -267,32 +400,32 @@ public class TileEntityIronShulkerBox extends TileEntityLockableLoot implements
switch (this.animationStatus)
{
case CLOSED:
this.progress = 0.0F;
break;
case OPENING:
this.progress += 0.1F;
case CLOSED:
this.progress = 0.0F;
break;
case OPENING:
this.progress += 0.1F;
if (this.progress >= 1.0F)
{
this.moveCollidedEntities();
this.animationStatus = AnimationStatus.OPENED;
this.progress = 1.0F;
}
break;
case CLOSING:
this.progress -= 0.1F;
if (this.progress <= 0.0F)
{
this.animationStatus = AnimationStatus.CLOSED;
this.progress = 0.0F;
}
break;
case OPENED:
if (this.progress >= 1.0F)
{
this.moveCollidedEntities();
this.animationStatus = AnimationStatus.OPENED;
this.progress = 1.0F;
}
break;
case CLOSING:
this.progress -= 0.1F;
if (this.progress <= 0.0F)
{
this.animationStatus = AnimationStatus.CLOSED;
this.progress = 0.0F;
}
break;
case OPENED:
this.progress = 1.0F;
}
}
@ -328,7 +461,7 @@ public class TileEntityIronShulkerBox extends TileEntityLockableLoot implements
{
EnumFacing enumfacing = this.getFacing();
AxisAlignedBB axisalignedbb = this.getTopBoundingBox(enumfacing).offset(this.pos);
List<Entity> list = this.world.getEntitiesWithinAABBExcludingEntity(null, axisalignedbb);
List<Entity> list = this.world.getEntitiesWithinAABBExcludingEntity((Entity) null, axisalignedbb);
if (!list.isEmpty())
{
@ -345,47 +478,49 @@ public class TileEntityIronShulkerBox extends TileEntityLockableLoot implements
switch (enumfacing.getAxis())
{
case X:
case X:
if (enumfacing.getAxisDirection() == EnumFacing.AxisDirection.POSITIVE)
{
d0 = axisalignedbb.maxX - axisalignedbb1.minX;
}
else
{
d0 = axisalignedbb1.maxX - axisalignedbb.minX;
}
if (enumfacing.getAxisDirection() == EnumFacing.AxisDirection.POSITIVE)
{
d0 = axisalignedbb.maxX - axisalignedbb1.minX;
}
else
{
d0 = axisalignedbb1.maxX - axisalignedbb.minX;
}
d0 = d0 + 0.01D;
break;
case Y:
d0 = d0 + 0.01D;
break;
case Y:
if (enumfacing.getAxisDirection() == EnumFacing.AxisDirection.POSITIVE)
{
d1 = axisalignedbb.maxY - axisalignedbb1.minY;
}
else
{
d1 = axisalignedbb1.maxY - axisalignedbb.minY;
}
if (enumfacing.getAxisDirection() == EnumFacing.AxisDirection.POSITIVE)
{
d1 = axisalignedbb.maxY - axisalignedbb1.minY;
}
else
{
d1 = axisalignedbb1.maxY - axisalignedbb.minY;
}
d1 = d1 + 0.01D;
break;
case Z:
d1 = d1 + 0.01D;
break;
case Z:
if (enumfacing.getAxisDirection() == EnumFacing.AxisDirection.POSITIVE)
{
d2 = axisalignedbb.maxZ - axisalignedbb1.minZ;
}
else
{
d2 = axisalignedbb1.maxZ - axisalignedbb.minZ;
}
if (enumfacing.getAxisDirection() == EnumFacing.AxisDirection.POSITIVE)
{
d2 = axisalignedbb.maxZ - axisalignedbb1.minZ;
}
else
{
d2 = axisalignedbb1.maxZ - axisalignedbb.minZ;
}
d2 = d2 + 0.01D;
d2 = d2 + 0.01D;
}
//@formatter:off
entity.move(MoverType.SHULKER_BOX, d0 * enumfacing.getFrontOffsetX(), d1 * enumfacing.getFrontOffsetY(), d2 * enumfacing.getFrontOffsetZ());
//@formatter:on
}
}
}
@ -447,7 +582,9 @@ public class TileEntityIronShulkerBox extends TileEntityLockableLoot implements
if (this.openCount == 1)
{
this.world.playSound(null, this.pos, SoundEvents.BLOCK_SHULKER_BOX_OPEN, SoundCategory.BLOCKS, 0.5F, this.world.rand.nextFloat() * 0.1F + 0.9F);
//@formatter:off
this.world.playSound((EntityPlayer) null, this.pos, SoundEvents.BLOCK_SHULKER_BOX_OPEN, SoundCategory.BLOCKS, 0.5F, this.world.rand.nextFloat() * 0.1F + 0.9F);
//@formatter:on
}
}
}
@ -463,7 +600,9 @@ public class TileEntityIronShulkerBox extends TileEntityLockableLoot implements
if (this.openCount <= 0)
{
this.world.playSound(null, this.pos, SoundEvents.BLOCK_SHULKER_BOX_CLOSE, SoundCategory.BLOCKS, 0.5F, this.world.rand.nextFloat() * 0.1F + 0.9F);
//@formatter:off
this.world.playSound((EntityPlayer) null, this.pos, SoundEvents.BLOCK_SHULKER_BOX_CLOSE, SoundCategory.BLOCKS, 0.5F, this.world.rand.nextFloat() * 0.1F + 0.9F);
//@formatter:on
}
}
}
@ -495,6 +634,34 @@ public class TileEntityIronShulkerBox extends TileEntityLockableLoot implements
}
}
public NonNullList<ItemStack> buildItemStackDataList()
{
if (this.getType().isTransparent())
{
NonNullList<ItemStack> sortList = NonNullList.<ItemStack> withSize(this.getTopItems().size(), ItemStack.EMPTY);
int pos = 0;
for (ItemStack is : this.topStacks)
{
if (!is.isEmpty())
{
sortList.set(pos, is);
}
else
{
sortList.set(pos, ItemStack.EMPTY);
}
pos++;
}
return sortList;
}
return NonNullList.<ItemStack> withSize(this.getTopItems().size(), ItemStack.EMPTY);
}
@Override
public Container createContainer(InventoryPlayer playerInventory, EntityPlayer playerIn)
{
@ -519,19 +686,7 @@ public class TileEntityIronShulkerBox extends TileEntityLockableLoot implements
public NBTTagCompound getUpdateTag()
{
NBTTagCompound compound = super.getUpdateTag();
if (!this.checkLootAndWrite(compound))
{
ItemStackHelper.saveAllItems(compound, this.items, false);
}
compound.setByte("facing", (byte) this.facing.ordinal());
if (this.hasCustomName())
{
compound.setString("CustomName", this.customName);
}
return compound;
}
@ -541,6 +696,11 @@ public class TileEntityIronShulkerBox extends TileEntityLockableLoot implements
return this.items;
}
public NonNullList<ItemStack> getTopItems()
{
return this.topStacks;
}
@Override
public boolean isEmpty()
{
@ -558,7 +718,7 @@ public class TileEntityIronShulkerBox extends TileEntityLockableLoot implements
@Override
public int[] getSlotsForFace(EnumFacing side)
{
return this.SLOTS;
return SLOTS;
}
/**
@ -661,14 +821,27 @@ public class TileEntityIronShulkerBox extends TileEntityLockableLoot implements
return ItemStack.EMPTY;
}
public enum AnimationStatus
protected void sendTopStacksPacket()
{
CLOSED, OPENING, OPENED, CLOSING
NonNullList<ItemStack> stacks = this.buildItemStackDataList();
//@formatter:off
IronChest.packetHandler.sendToAllAround(new MessageCrystalShulkerSync(this, stacks), new TargetPoint(world.provider.getDimension(), getPos().getX(), getPos().getY(), getPos().getZ(), 128));
//@formatter:on
}
public void receiveMessageFromServer(NonNullList<ItemStack> topStacks)
{
this.topStacks = topStacks;
}
public static enum AnimationStatus
{
CLOSED, OPENING, OPENED, CLOSING;
}
public static void registerFixesShulkerBox(DataFixer fixer)
{
fixer.registerWalker(FixTypes.BLOCK_ENTITY, new ItemStackDataLists(TileEntityIronShulkerBox.class, "Items"));
fixer.registerWalker(FixTypes.BLOCK_ENTITY, new ItemStackDataLists(TileEntityIronShulkerBox.class, new String[] { "Items" }));
}
private IItemHandler itemHandler;
@ -684,9 +857,7 @@ public class TileEntityIronShulkerBox extends TileEntityLockableLoot implements
public <T> T getCapability(Capability<T> capability, EnumFacing facing)
{
if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY)
{
return (T) (this.itemHandler == null ? (this.itemHandler = this.createUnSidedHandler()) : this.itemHandler);
}
return (T) (itemHandler == null ? (itemHandler = createUnSidedHandler()) : itemHandler);
return super.getCapability(capability, facing);
}

View File

@ -10,14 +10,14 @@
******************************************************************************/
package cpw.mods.ironchest.common.tileentity.shulker;
import javax.annotation.Nullable;
import cpw.mods.ironchest.common.blocks.shulker.IronShulkerBoxType;
import net.minecraft.item.EnumDyeColor;
import net.minecraft.util.datafix.DataFixer;
import net.minecraft.util.datafix.FixTypes;
import net.minecraft.util.datafix.walkers.ItemStackDataLists;
import javax.annotation.Nullable;
public class TileEntityObsidianShulkerBox extends TileEntityIronShulkerBox
{
public TileEntityObsidianShulkerBox()

View File

@ -10,14 +10,14 @@
******************************************************************************/
package cpw.mods.ironchest.common.tileentity.shulker;
import javax.annotation.Nullable;
import cpw.mods.ironchest.common.blocks.shulker.IronShulkerBoxType;
import net.minecraft.item.EnumDyeColor;
import net.minecraft.util.datafix.DataFixer;
import net.minecraft.util.datafix.FixTypes;
import net.minecraft.util.datafix.walkers.ItemStackDataLists;
import javax.annotation.Nullable;
public class TileEntitySilverShulkerBox extends TileEntityIronShulkerBox
{
public TileEntitySilverShulkerBox()

View File

@ -10,7 +10,12 @@
******************************************************************************/
package cpw.mods.ironchest.common.util;
import java.util.List;
import javax.annotation.Nullable;
import com.google.common.collect.Lists;
import net.minecraft.client.util.ITooltipFlag;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
@ -20,9 +25,6 @@ import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import javax.annotation.Nullable;
import java.util.List;
@SuppressWarnings("deprecation")
public class ItemTooltip extends Item
{
@ -56,9 +58,7 @@ public class ItemTooltip extends Item
{
List<String> list = Lists.newLinkedList();
if (text == null)
{
return list;
}
int j = 0;
int k;
while ((k = text.indexOf("\\n", j)) >= 0)

View File

@ -10,6 +10,8 @@
******************************************************************************/
package cpw.mods.ironchest.common.util;
import javax.annotation.Nonnull;
import net.minecraft.block.Block;
import net.minecraft.item.Item;
import net.minecraft.util.ResourceLocation;
@ -18,8 +20,6 @@ import net.minecraftforge.event.RegistryEvent.MissingMappings.Mapping;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.registry.ForgeRegistries;
import javax.annotation.Nonnull;
public class MissingMappingsHandler
{
@SubscribeEvent

View File

@ -10,6 +10,8 @@
******************************************************************************/
package cpw.mods.ironchest.common.util;
import java.util.HashSet;
import cpw.mods.ironchest.common.ai.IronChestAIOcelotSit;
import net.minecraft.entity.ai.EntityAIOcelotSit;
import net.minecraft.entity.ai.EntityAITasks.EntityAITaskEntry;
@ -17,8 +19,6 @@ import net.minecraft.entity.passive.EntityOcelot;
import net.minecraftforge.event.entity.living.LivingEvent.LivingUpdateEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import java.util.HashSet;
public class OcelotsSitOnChestsHandler
{
@SubscribeEvent