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 commit is contained in:
alexbegt 2019-06-06 16:00:05 -04:00
parent e24b7b5980
commit 930ea9a725
38 changed files with 920 additions and 765 deletions

View File

@ -37,13 +37,17 @@ 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,13 +10,11 @@
******************************************************************************/
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;
@ -28,6 +26,8 @@ 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 (te.getTopItems().get(1).isEmpty())
if (((TileEntityCrystalChest) 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 : te.getTopItems())
for (ItemStack item : ((TileEntityCrystalChest) te).getTopItems())
{
if (shift > shifts.length || shift > 8)
{

View File

@ -16,6 +16,7 @@ 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;
@ -165,7 +166,7 @@ public class TileEntityIronShulkerBoxRenderer extends TileEntitySpecialRenderer<
float blockScale = 0.70F;
float timeD = (float) (360D * (System.currentTimeMillis() & 0x3FFFL) / 0x3FFFL) - partialTicks;
if (te.getTopItems().get(1).isEmpty())
if (((TileEntityCrystalShulkerBox) te).getTopItems().get(1).isEmpty())
{
shift = 8;
blockScale = 0.85F;
@ -181,7 +182,7 @@ public class TileEntityIronShulkerBoxRenderer extends TileEntitySpecialRenderer<
customItem.hoverStart = 0F;
for (ItemStack item : te.getTopItems())
for (ItemStack item : ((TileEntityCrystalShulkerBox) te).getTopItems())
{
if (shift > shifts.length || shift > 8)
{

View File

@ -10,10 +10,6 @@
******************************************************************************/
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;
@ -53,6 +49,9 @@ 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,10 +10,6 @@
******************************************************************************/
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;
@ -50,6 +46,9 @@ 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
{
@ -390,7 +389,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;
@ -418,7 +417,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;
@ -493,39 +492,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,11 +1,10 @@
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,7 +1,5 @@
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;
@ -11,6 +9,8 @@ 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,14 +1,13 @@
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
@ -18,10 +17,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,7 +11,6 @@
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;
@ -123,7 +122,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,10 +10,7 @@
******************************************************************************/
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;
@ -28,6 +25,8 @@ 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,8 +114,7 @@ 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,9 +53,7 @@ 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,8 +27,6 @@ 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,6 +6,11 @@
******************************************************************************/
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;
@ -15,11 +20,6 @@ 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,6 +6,11 @@
******************************************************************************/
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;
@ -15,11 +20,6 @@ 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,8 +10,6 @@
******************************************************************************/
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;
@ -32,6 +30,8 @@ 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,9 +48,7 @@ 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);
@ -79,8 +77,10 @@ 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,6 +88,13 @@ 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)
@ -110,13 +117,19 @@ 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();
}
}
@ -144,6 +157,11 @@ 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,8 +10,6 @@
******************************************************************************/
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;
@ -34,6 +32,8 @@ 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,9 +88,7 @@ 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);
@ -127,9 +125,11 @@ 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,6 +140,12 @@ 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)
@ -158,13 +164,19 @@ 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();
@ -202,6 +214,11 @@ 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,9 +1,6 @@
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;
@ -12,6 +9,8 @@ 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,29 +41,36 @@ public class ICChestInventoryHandler implements IItemHandlerModifiable
public ItemStack insertItem(int slot, ItemStack stack, boolean simulate)
{
if (stack.isEmpty())
{
return stack;
}
stack = stack.copy();
if (!inv.isItemValidForSlot(slot, stack))
if (!this.inv.isItemValidForSlot(slot, stack))
{
return stack;
}
int offsetSlot = slot;
ItemStack currentStack = inv.getItems().get(offsetSlot);
ItemStack currentStack = this.inv.getItems().get(slot);
if (currentStack.isEmpty())
{
int accepted = Math.min(stack.getMaxStackSize(), inv.getInventoryStackLimit());
int accepted = Math.min(stack.getMaxStackSize(), this.inv.getInventoryStackLimit());
if (accepted < stack.getCount())
{
if (!simulate)
{
inv.getItems().set(offsetSlot, stack.splitStack(accepted));
inv.markDirty();
this.inv.getItems().set(slot, stack.splitStack(accepted));
this.inv.markDirty();
return stack;
}
else
{
stack.shrink(accepted);
return stack;
}
}
@ -71,18 +78,21 @@ public class ICChestInventoryHandler implements IItemHandlerModifiable
{
if (!simulate)
{
inv.getItems().set(offsetSlot, stack);
inv.markDirty();
this.inv.getItems().set(slot, stack);
this.inv.markDirty();
}
return ItemStack.EMPTY;
}
}
else
{
int accepted = Math.min(stack.getMaxStackSize(), inv.getInventoryStackLimit()) - currentStack.getCount();
int accepted = Math.min(stack.getMaxStackSize(), this.inv.getInventoryStackLimit()) - currentStack.getCount();
if (accepted <= 0 || !ItemHandlerHelper.canItemStacksStack(stack, currentStack))
{
return stack;
}
if (accepted < stack.getCount())
{
@ -90,13 +100,15 @@ public class ICChestInventoryHandler implements IItemHandlerModifiable
{
ItemStack newStack = stack.splitStack(accepted);
newStack.grow(currentStack.getCount());
inv.getItems().set(offsetSlot, newStack);
inv.markDirty();
this.inv.getItems().set(slot, newStack);
this.inv.markDirty();
return stack;
}
else
{
stack.shrink(accepted);
return stack;
}
}
@ -106,9 +118,10 @@ public class ICChestInventoryHandler implements IItemHandlerModifiable
{
ItemStack newStack = stack.copy();
newStack.grow(currentStack.getCount());
inv.getItems().set(offsetSlot, newStack);
inv.markDirty();
this.inv.getItems().set(slot, newStack);
this.inv.markDirty();
}
return ItemStack.EMPTY;
}
}
@ -118,45 +131,55 @@ public class ICChestInventoryHandler implements IItemHandlerModifiable
public ItemStack extractItem(int slot, int amount, boolean simulate)
{
if (amount == 0)
{
return ItemStack.EMPTY;
}
int offsetSlot = slot;
ItemStack currentStack = inv.getItems().get(offsetSlot);
ItemStack currentStack = this.inv.getItems().get(slot);
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;
inv.getItems().set(offsetSlot, currentStack);
inv.markDirty();
}
this.inv.getItems().set(slot, currentStack);
this.inv.markDirty();
}
return copy;
}
@Override
public int getSlotLimit(int slot)
{
return getInv().getInventoryStackLimit();
return this.getInv().getInventoryStackLimit();
}
@Override
public void setStackInSlot(int slot, @Nonnull ItemStack stack)
{
inv.getItems().set(slot, stack);
inv.markDirty();
this.inv.getItems().set(slot, stack);
this.inv.markDirty();
}
public IInventory getInv()
{
return inv;
return this.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,29 +41,36 @@ public class ICShulkerInventoryHandler implements IItemHandlerModifiable
public ItemStack insertItem(int slot, ItemStack stack, boolean simulate)
{
if (stack.isEmpty())
{
return stack;
}
stack = stack.copy();
if (!inv.isItemValidForSlot(slot, stack))
if (!this.inv.isItemValidForSlot(slot, stack))
{
return stack;
}
int offsetSlot = slot;
ItemStack currentStack = inv.getItems().get(offsetSlot);
ItemStack currentStack = this.inv.getItems().get(slot);
if (currentStack.isEmpty())
{
int accepted = Math.min(stack.getMaxStackSize(), inv.getInventoryStackLimit());
int accepted = Math.min(stack.getMaxStackSize(), this.inv.getInventoryStackLimit());
if (accepted < stack.getCount())
{
if (!simulate)
{
inv.getItems().set(offsetSlot, stack.splitStack(accepted));
inv.markDirty();
this.inv.getItems().set(slot, stack.splitStack(accepted));
this.inv.markDirty();
return stack;
}
else
{
stack.shrink(accepted);
return stack;
}
}
@ -71,18 +78,21 @@ public class ICShulkerInventoryHandler implements IItemHandlerModifiable
{
if (!simulate)
{
inv.getItems().set(offsetSlot, stack);
inv.markDirty();
this.inv.getItems().set(slot, stack);
this.inv.markDirty();
}
return ItemStack.EMPTY;
}
}
else
{
int accepted = Math.min(stack.getMaxStackSize(), inv.getInventoryStackLimit()) - currentStack.getCount();
int accepted = Math.min(stack.getMaxStackSize(), this.inv.getInventoryStackLimit()) - currentStack.getCount();
if (accepted <= 0 || !ItemHandlerHelper.canItemStacksStack(stack, currentStack))
{
return stack;
}
if (accepted < stack.getCount())
{
@ -90,13 +100,15 @@ public class ICShulkerInventoryHandler implements IItemHandlerModifiable
{
ItemStack newStack = stack.splitStack(accepted);
newStack.grow(currentStack.getCount());
inv.getItems().set(offsetSlot, newStack);
inv.markDirty();
this.inv.getItems().set(slot, newStack);
this.inv.markDirty();
return stack;
}
else
{
stack.shrink(accepted);
return stack;
}
}
@ -106,9 +118,10 @@ public class ICShulkerInventoryHandler implements IItemHandlerModifiable
{
ItemStack newStack = stack.copy();
newStack.grow(currentStack.getCount());
inv.getItems().set(offsetSlot, newStack);
inv.markDirty();
this.inv.getItems().set(slot, newStack);
this.inv.markDirty();
}
return ItemStack.EMPTY;
}
}
@ -118,45 +131,55 @@ public class ICShulkerInventoryHandler implements IItemHandlerModifiable
public ItemStack extractItem(int slot, int amount, boolean simulate)
{
if (amount == 0)
{
return ItemStack.EMPTY;
}
int offsetSlot = slot;
ItemStack currentStack = inv.getItems().get(offsetSlot);
ItemStack currentStack = this.inv.getItems().get(slot);
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;
inv.getItems().set(offsetSlot, currentStack);
inv.markDirty();
}
this.inv.getItems().set(slot, currentStack);
this.inv.markDirty();
}
return copy;
}
@Override
public int getSlotLimit(int slot)
{
return getInv().getInventoryStackLimit();
return this.getInv().getInventoryStackLimit();
}
@Override
public void setStackInSlot(int slot, @Nonnull ItemStack stack)
{
inv.getItems().set(slot, stack);
inv.markDirty();
this.inv.getItems().set(slot, stack);
this.inv.markDirty();
}
public IInventory getInv()
{
return inv;
return this.inv;
}
}

View File

@ -11,6 +11,7 @@
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;
@ -26,14 +27,21 @@ import net.minecraftforge.fml.common.network.simpleimpl.MessageContext;
public class MessageCrystalChestSync implements IMessage
{
int dimension;
BlockPos pos;
private NonNullList<ItemStack> topStacks;
public MessageCrystalChestSync(TileEntityIronChest tile, NonNullList<ItemStack> stack)
public MessageCrystalChestSync(int dimensionId, BlockPos tilePos, NonNullList<ItemStack> stackList)
{
this.dimension = tile.getWorld().provider.getDimension();
this.pos = tile.getPos();
this.topStacks = 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);
}
public MessageCrystalChestSync()
@ -47,7 +55,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++)
{
@ -83,8 +91,10 @@ public class MessageCrystalChestSync implements IMessage
{
TileEntity tile = world.getTileEntity(message.pos);
if (tile instanceof TileEntityIronChest)
((TileEntityIronChest) tile).receiveMessageFromServer(message.topStacks);
if (tile instanceof TileEntityCrystalChest)
{
((TileEntityCrystalChest) tile).receiveMessageFromServer(message.topStacks);
}
}
return null;

View File

@ -11,6 +11,7 @@
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;
@ -31,11 +32,16 @@ public class MessageCrystalShulkerSync implements IMessage
private NonNullList<ItemStack> topStacks;
public MessageCrystalShulkerSync(TileEntityIronShulkerBox tile, NonNullList<ItemStack> stack)
public MessageCrystalShulkerSync(int dimensionId, BlockPos tilePos, NonNullList<ItemStack> stackList)
{
this.dimension = tile.getWorld().provider.getDimension();
this.pos = tile.getPos();
this.topStacks = 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);
}
public MessageCrystalShulkerSync()
@ -49,7 +55,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++)
{
@ -85,8 +91,10 @@ public class MessageCrystalShulkerSync implements IMessage
{
TileEntity tile = world.getTileEntity(message.pos);
if (tile instanceof TileEntityIronShulkerBox)
((TileEntityIronShulkerBox) tile).receiveMessageFromServer(message.topStacks);
if (tile instanceof TileEntityCrystalShulkerBox)
{
((TileEntityCrystalShulkerBox) tile).receiveMessageFromServer(message.topStacks);
}
}
return null;

View File

@ -10,16 +10,238 @@
******************************************************************************/
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,16 +10,11 @@
******************************************************************************/
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;
@ -42,7 +37,6 @@ 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;
@ -51,9 +45,6 @@ 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;
@ -69,12 +60,6 @@ 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;
@ -88,14 +73,13 @@ public class TileEntityIronChest extends TileEntityLockableLoot implements ITick
{
super();
this.chestType = type;
this.chestContents = NonNullList.<ItemStack> withSize(type.size, ItemStack.EMPTY);
this.topStacks = NonNullList.<ItemStack> withSize(8, ItemStack.EMPTY);
this.chestContents = NonNullList.withSize(type.size, ItemStack.EMPTY);
this.facing = EnumFacing.NORTH;
}
public void setContents(NonNullList<ItemStack> contents)
{
this.chestContents = NonNullList.<ItemStack> withSize(this.getType().size, ItemStack.EMPTY);
this.chestContents = NonNullList.withSize(this.getType().size, ItemStack.EMPTY);
for (int i = 0; i < contents.size(); i++)
{
@ -104,8 +88,6 @@ public class TileEntityIronChest extends TileEntityLockableLoot implements ITick
this.getItems().set(i, contents.get(i));
}
}
this.inventoryTouched = true;
}
@Override
@ -139,9 +121,7 @@ public class TileEntityIronChest extends TileEntityLockableLoot implements ITick
@Override
public ItemStack getStackInSlot(int index)
{
this.fillWithLoot((EntityPlayer) null);
this.inventoryTouched = true;
this.fillWithLoot(null);
return this.getItems().get(index);
}
@ -150,124 +130,6 @@ 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
@ -293,7 +155,7 @@ public class TileEntityIronChest extends TileEntityLockableLoot implements ITick
{
super.readFromNBT(compound);
this.chestContents = NonNullList.<ItemStack> withSize(this.getSizeInventory(), ItemStack.EMPTY);
this.chestContents = NonNullList.withSize(this.getSizeInventory(), ItemStack.EMPTY);
if (compound.hasKey("CustomName", Constants.NBT.TAG_STRING))
{
@ -306,8 +168,6 @@ public class TileEntityIronChest extends TileEntityLockableLoot implements ITick
}
this.facing = EnumFacing.VALUES[compound.getByte("facing")];
this.sortTopStacks();
}
@Override
@ -355,18 +215,17 @@ 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
//@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
if (this.world != null && !this.world.isRemote && this.numPlayersUsing != 0 && (this.ticksSinceSync + x + y + z) % 200 == 0)
{
this.numPlayersUsing = 0;
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
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)))
{
if (player.openContainer instanceof ContainerIronChest)
{
@ -380,26 +239,16 @@ 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 x = this.pos.getX() + 0.5D;
double y = this.pos.getY() + 0.5D;
double z = this.pos.getZ() + 0.5D;
double soundX = x + 0.5D;
double soundY = y + 0.5D;
double soundZ = z + 0.5D;
this.world.playSound(null, x, y, z, SoundEvents.BLOCK_CHEST_OPEN, SoundCategory.BLOCKS, 0.5F, this.world.rand.nextFloat() * 0.1F + 0.9F);
this.world.playSound(null, soundX, soundY, soundZ, 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)
@ -424,11 +273,11 @@ public class TileEntityIronChest extends TileEntityLockableLoot implements ITick
if (this.lidAngle < maxAngle && currentAngle >= maxAngle)
{
double x = this.pos.getX() + 0.5D;
double y = this.pos.getY() + 0.5D;
double z = this.pos.getZ() + 0.5D;
double soundX = x + 0.5D;
double soundY = y + 0.5D;
double soundZ = z + 0.5D;
this.world.playSound(null, x, y, z, SoundEvents.BLOCK_CHEST_CLOSE, SoundCategory.BLOCKS, 0.5F, this.world.rand.nextFloat() * 0.1F + 0.9F);
this.world.playSound(null, soundX, soundY, soundZ, SoundEvents.BLOCK_CHEST_CLOSE, SoundCategory.BLOCKS, 0.5F, this.world.rand.nextFloat() * 0.1F + 0.9F);
}
if (this.lidAngle < 0.0F)
@ -455,7 +304,7 @@ public class TileEntityIronChest extends TileEntityLockableLoot implements ITick
this.numPlayersUsing = (type & 0xF8) >> 3;
}
return true;
return super.receiveClientEvent(id, type);
}
@Override
@ -463,11 +312,6 @@ public class TileEntityIronChest extends TileEntityLockableLoot implements ITick
{
if (!player.isSpectator())
{
if (this.world == null)
{
return;
}
if (this.numPlayersUsing < 0)
{
this.numPlayersUsing = 0;
@ -477,7 +321,6 @@ 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);
}
}
@ -486,16 +329,10 @@ 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);
}
}
@ -525,34 +362,6 @@ 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)
{
@ -598,7 +407,19 @@ 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;
}
@ -608,11 +429,6 @@ public class TileEntityIronChest extends TileEntityLockableLoot implements ITick
return this.chestContents;
}
public NonNullList<ItemStack> getTopItems()
{
return this.topStacks;
}
@Override
public boolean isEmpty()
{
@ -627,29 +443,18 @@ 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, new String[] { "Items" }));
fixer.registerWalker(FixTypes.BLOCK_ENTITY, new ItemStackDataLists(TileEntityIronChest.class, "Items"));
}
@Override
public boolean hasCapability(Capability<?> capability, EnumFacing facing)
{
if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY)
{
return true;
}
return super.hasCapability(capability, facing);
}
@ -666,7 +471,9 @@ public class TileEntityIronChest extends TileEntityLockableLoot implements ITick
public <T> T getCapability(Capability<T> capability, EnumFacing facing)
{
if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY)
return (T) (itemHandler == null ? (itemHandler = createUnSidedHandler()) : itemHandler);
{
return (T) (this.itemHandler == null ? (this.itemHandler = this.createUnSidedHandler()) : this.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,16 +10,32 @@
******************************************************************************/
package cpw.mods.ironchest.common.tileentity.shulker;
import javax.annotation.Nullable;
import cpw.mods.ironchest.IronChest;
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);
@ -28,10 +44,199 @@ 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, new String[] { "Items" }));
fixer.registerWalker(FixTypes.BLOCK_ENTITY, new ItemStackDataLists(TileEntityCrystalShulkerBox.class, "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,18 +10,10 @@
******************************************************************************/
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;
@ -50,12 +42,14 @@ 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;
@ -63,21 +57,12 @@ 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;
@ -115,8 +100,7 @@ public class TileEntityIronShulkerBox extends TileEntityLockableLoot implements
this.SLOTS = new int[typeIn.size];
this.items = NonNullList.<ItemStack> withSize(typeIn.size, ItemStack.EMPTY);
this.topStacks = NonNullList.<ItemStack> withSize(8, ItemStack.EMPTY);
this.items = NonNullList.withSize(typeIn.size, ItemStack.EMPTY);
this.animationStatus = AnimationStatus.CLOSED;
this.color = colorIn;
@ -128,7 +112,7 @@ public class TileEntityIronShulkerBox extends TileEntityLockableLoot implements
public void setContents(NonNullList<ItemStack> contents)
{
this.items = NonNullList.<ItemStack> withSize(this.getType().size, ItemStack.EMPTY);
this.items = NonNullList.withSize(this.getType().size, ItemStack.EMPTY);
for (int i = 0; i < contents.size(); i++)
{
@ -137,8 +121,6 @@ public class TileEntityIronShulkerBox extends TileEntityLockableLoot implements
this.getItems().set(i, contents.get(i));
}
}
this.inventoryTouched = true;
}
@Override
@ -172,9 +154,7 @@ public class TileEntityIronShulkerBox extends TileEntityLockableLoot implements
@Override
public ItemStack getStackInSlot(int index)
{
this.fillWithLoot((EntityPlayer) null);
this.inventoryTouched = true;
this.fillWithLoot(null);
return this.getItems().get(index);
}
@ -183,110 +163,6 @@ 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();
}
/**
@ -316,7 +192,7 @@ public class TileEntityIronShulkerBox extends TileEntityLockableLoot implements
public void loadFromNbt(NBTTagCompound compound)
{
this.items = NonNullList.<ItemStack> withSize(this.getSizeInventory(), ItemStack.EMPTY);
this.items = NonNullList.withSize(this.getSizeInventory(), ItemStack.EMPTY);
if (!this.checkLootAndRead(compound) && compound.hasKey("Items", 9))
{
@ -329,8 +205,6 @@ public class TileEntityIronShulkerBox extends TileEntityLockableLoot implements
}
this.facing = EnumFacing.VALUES[compound.getByte("facing")];
this.sortTopStacks();
}
public NBTTagCompound saveToNbt(NBTTagCompound compound)
@ -384,13 +258,6 @@ 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++;
}
@ -400,32 +267,32 @@ public class TileEntityIronShulkerBox extends TileEntityLockableLoot implements
switch (this.animationStatus)
{
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;
case CLOSED:
this.progress = 0.0F;
}
break;
case OPENING:
this.progress += 0.1F;
break;
case OPENED:
this.progress = 1.0F;
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;
}
}
@ -461,7 +328,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((Entity) null, axisalignedbb);
List<Entity> list = this.world.getEntitiesWithinAABBExcludingEntity(null, axisalignedbb);
if (!list.isEmpty())
{
@ -478,49 +345,47 @@ 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
}
}
}
@ -582,9 +447,7 @@ public class TileEntityIronShulkerBox extends TileEntityLockableLoot implements
if (this.openCount == 1)
{
//@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
this.world.playSound(null, this.pos, SoundEvents.BLOCK_SHULKER_BOX_OPEN, SoundCategory.BLOCKS, 0.5F, this.world.rand.nextFloat() * 0.1F + 0.9F);
}
}
}
@ -600,9 +463,7 @@ public class TileEntityIronShulkerBox extends TileEntityLockableLoot implements
if (this.openCount <= 0)
{
//@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
this.world.playSound(null, this.pos, SoundEvents.BLOCK_SHULKER_BOX_CLOSE, SoundCategory.BLOCKS, 0.5F, this.world.rand.nextFloat() * 0.1F + 0.9F);
}
}
}
@ -634,34 +495,6 @@ 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)
{
@ -686,7 +519,19 @@ 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;
}
@ -696,11 +541,6 @@ public class TileEntityIronShulkerBox extends TileEntityLockableLoot implements
return this.items;
}
public NonNullList<ItemStack> getTopItems()
{
return this.topStacks;
}
@Override
public boolean isEmpty()
{
@ -718,7 +558,7 @@ public class TileEntityIronShulkerBox extends TileEntityLockableLoot implements
@Override
public int[] getSlotsForFace(EnumFacing side)
{
return SLOTS;
return this.SLOTS;
}
/**
@ -821,27 +661,14 @@ public class TileEntityIronShulkerBox extends TileEntityLockableLoot implements
return ItemStack.EMPTY;
}
protected void sendTopStacksPacket()
public enum AnimationStatus
{
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;
CLOSED, OPENING, OPENED, CLOSING
}
public static void registerFixesShulkerBox(DataFixer fixer)
{
fixer.registerWalker(FixTypes.BLOCK_ENTITY, new ItemStackDataLists(TileEntityIronShulkerBox.class, new String[] { "Items" }));
fixer.registerWalker(FixTypes.BLOCK_ENTITY, new ItemStackDataLists(TileEntityIronShulkerBox.class, "Items"));
}
private IItemHandler itemHandler;
@ -857,7 +684,9 @@ public class TileEntityIronShulkerBox extends TileEntityLockableLoot implements
public <T> T getCapability(Capability<T> capability, EnumFacing facing)
{
if (capability == CapabilityItemHandler.ITEM_HANDLER_CAPABILITY)
return (T) (itemHandler == null ? (itemHandler = createUnSidedHandler()) : itemHandler);
{
return (T) (this.itemHandler == null ? (this.itemHandler = this.createUnSidedHandler()) : this.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,12 +10,7 @@
******************************************************************************/
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;
@ -25,6 +20,9 @@ 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
{
@ -58,7 +56,9 @@ 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,8 +10,6 @@
******************************************************************************/
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;
@ -20,6 +18,8 @@ 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,8 +10,6 @@
******************************************************************************/
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;
@ -19,6 +17,8 @@ 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