Readded Crates
This commit is contained in:
parent
d62a3e075e
commit
99a3827bbd
13 changed files with 471 additions and 487 deletions
|
@ -1,8 +1,12 @@
|
|||
package resonantinduction.archaic;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import resonantinduction.archaic.crate.BlockCrate;
|
||||
import resonantinduction.archaic.crate.TileCrate;
|
||||
import resonantinduction.core.Reference;
|
||||
import resonantinduction.core.ResonantInduction;
|
||||
import resonantinduction.core.Settings;
|
||||
import calclavia.lib.content.ContentRegistry;
|
||||
import calclavia.lib.network.PacketHandler;
|
||||
import cpw.mods.fml.common.Mod;
|
||||
import cpw.mods.fml.common.Mod.EventHandler;
|
||||
|
@ -37,15 +41,22 @@ public class Archaic
|
|||
@Mod.Metadata(ID)
|
||||
public static ModMetadata metadata;
|
||||
|
||||
public static final ContentRegistry contentRegistry = new ContentRegistry(Settings.CONFIGURATION, ID);
|
||||
|
||||
public static Block blockCrate;
|
||||
|
||||
@EventHandler
|
||||
public void preInit(FMLPreInitializationEvent evt)
|
||||
{
|
||||
NetworkRegistry.instance().registerGuiHandler(this, proxy);
|
||||
blockCrate = contentRegistry.createTile(BlockCrate.class, TileCrate.class);
|
||||
proxy.preInit();
|
||||
}
|
||||
|
||||
@EventHandler
|
||||
public void init(FMLInitializationEvent evt)
|
||||
{
|
||||
Settings.setModMetadata(metadata, ID, NAME);
|
||||
proxy.init();
|
||||
}
|
||||
}
|
||||
|
|
422
src/main/java/resonantinduction/archaic/crate/BlockCrate.java
Normal file
422
src/main/java/resonantinduction/archaic/crate/BlockCrate.java
Normal file
|
@ -0,0 +1,422 @@
|
|||
package resonantinduction.archaic.crate;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import codechicken.multipart.ControlKeyModifer;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.renderer.texture.IconRegister;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.Icon;
|
||||
import net.minecraft.world.World;
|
||||
import resonantinduction.core.Reference;
|
||||
import resonantinduction.core.prefab.block.BlockRI;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
/**
|
||||
* A block that allows the placement of mass amount of a specific item within it. It will be allowed
|
||||
* to go on Conveyor Belts.
|
||||
*
|
||||
* NOTE: Crates should be upgraded with an item.
|
||||
*
|
||||
* @author DarkGuardsman
|
||||
*/
|
||||
public class BlockCrate extends BlockRI
|
||||
{
|
||||
Icon advanced, elite;
|
||||
|
||||
public BlockCrate()
|
||||
{
|
||||
super("crate");
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void registerIcons(IconRegister iconReg)
|
||||
{
|
||||
this.blockIcon = iconReg.registerIcon(Reference.PREFIX + "crate");
|
||||
this.advanced = iconReg.registerIcon(Reference.PREFIX + "crate_adv");
|
||||
this.elite = iconReg.registerIcon(Reference.PREFIX + "crate_elt");
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public Icon getIcon(int side, int meta)
|
||||
{
|
||||
if (meta == 1)
|
||||
{
|
||||
return advanced;
|
||||
}
|
||||
else if (meta == 2)
|
||||
{
|
||||
return elite;
|
||||
}
|
||||
return this.blockIcon;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockClicked(World world, int x, int y, int z, EntityPlayer player)
|
||||
{
|
||||
if (!world.isRemote)
|
||||
{
|
||||
if (world.getBlockTileEntity(x, y, z) instanceof TileCrate)
|
||||
{
|
||||
TileCrate tileEntity = (TileCrate) world.getBlockTileEntity(x, y, z);
|
||||
|
||||
/** Make double clicking input all stacks. */
|
||||
boolean allMode = (world.getWorldTime() - tileEntity.prevClickTime < 10);
|
||||
|
||||
tileEntity.prevClickTime = world.getWorldTime();
|
||||
|
||||
this.tryEject(tileEntity, player, allMode);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/** Placed the item the player is holding into the crate. */
|
||||
@Override
|
||||
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
if (super.onBlockActivated(world, x, y, z, player, side, hitX, hitY, hitZ))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!world.isRemote)
|
||||
{
|
||||
if (world.getBlockTileEntity(x, y, z) instanceof TileCrate)
|
||||
{
|
||||
TileCrate tileEntity = (TileCrate) world.getBlockTileEntity(x, y, z);
|
||||
|
||||
/** Make double clicking input all stacks. */
|
||||
boolean allMode = (world.getWorldTime() - tileEntity.prevClickTime < 10);
|
||||
|
||||
tileEntity.prevClickTime = world.getWorldTime();
|
||||
|
||||
if (ControlKeyModifer.isControlDown(player))
|
||||
{
|
||||
this.tryEject(tileEntity, player, allMode);
|
||||
}
|
||||
else
|
||||
{
|
||||
ItemStack current = player.inventory.getCurrentItem();
|
||||
if (side == 1 && player.capabilities.isCreativeMode)
|
||||
{
|
||||
if (current != null && tileEntity.getSampleStack() == null)
|
||||
{
|
||||
ItemStack cStack = current.copy();
|
||||
cStack.stackSize = TileCrate.getSlotCount(world.getBlockMetadata(x, y, z)) * 64;
|
||||
BlockCrate.addStackToCrate(tileEntity, cStack);
|
||||
}
|
||||
}
|
||||
// Add items
|
||||
if (side == 1 || (side > 1 && hitY > 0.5) || !player.capabilities.isCreativeMode)
|
||||
{
|
||||
this.tryInsert(tileEntity, player, allMode);
|
||||
}
|
||||
// Remove items
|
||||
else if (side == 0 || (side > 1 && hitY <= 0.5))
|
||||
{
|
||||
this.tryEject(tileEntity, player, allMode);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Try to inject it into the crate. Otherwise, look around for nearby crates and try to put them
|
||||
* in.
|
||||
*/
|
||||
public void tryInsert(TileCrate tileEntity, EntityPlayer player, boolean allMode, boolean doSearch)
|
||||
{
|
||||
boolean success;
|
||||
|
||||
if (allMode)
|
||||
{
|
||||
success = this.insertAllItems(tileEntity, player);
|
||||
}
|
||||
else
|
||||
{
|
||||
success = this.insertCurrentItem(tileEntity, player);
|
||||
}
|
||||
|
||||
if (!success && doSearch)
|
||||
{
|
||||
PathfinderCrate pathfinder = new PathfinderCrate().init(tileEntity);
|
||||
|
||||
for (TileEntity checkTile : pathfinder.iteratedNodes)
|
||||
{
|
||||
if (checkTile instanceof TileCrate)
|
||||
{
|
||||
this.tryInsert(((TileCrate) checkTile), player, allMode, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void tryInsert(TileCrate tileEntity, EntityPlayer player, boolean allMode)
|
||||
{
|
||||
this.tryInsert(tileEntity, player, allMode, true);
|
||||
}
|
||||
|
||||
public void tryEject(TileCrate tileEntity, EntityPlayer player, boolean allMode)
|
||||
{
|
||||
if (tileEntity.getSampleStack() == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (allMode && !player.isSneaking())
|
||||
{
|
||||
this.ejectItems(tileEntity, player, tileEntity.getSlotCount() * 64);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (player.isSneaking())
|
||||
{
|
||||
this.ejectItems(tileEntity, player, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.ejectItems(tileEntity, player, tileEntity.getSampleStack().getMaxStackSize());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Inserts a the itemStack the player is holding into the crate. */
|
||||
public boolean insertCurrentItem(TileCrate tileEntity, EntityPlayer player)
|
||||
{
|
||||
ItemStack currentStack = player.getCurrentEquippedItem();
|
||||
|
||||
if (currentStack != null)
|
||||
{
|
||||
if (currentStack.getItem().itemID == this.blockID)
|
||||
{
|
||||
ItemStack containedStack = ItemBlockCrate.getContainingItemStack(currentStack);
|
||||
ItemStack crateStack = tileEntity.getSampleStack();
|
||||
if (containedStack != null && (crateStack == null || (crateStack != null && containedStack.isItemEqual(crateStack))))
|
||||
{
|
||||
ItemStack returned = BlockCrate.addStackToCrate(tileEntity, containedStack);
|
||||
ItemBlockCrate.setContainingItemStack(currentStack, returned);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
if (tileEntity.getSampleStack() != null)
|
||||
{
|
||||
if (!tileEntity.getSampleStack().isItemEqual(currentStack))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
player.inventory.setInventorySlotContents(player.inventory.currentItem, BlockCrate.addStackToCrate(tileEntity, currentStack));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Inserts all items of the same type this player has into the crate.
|
||||
*
|
||||
* @return True on success
|
||||
*/
|
||||
public boolean insertAllItems(TileCrate tileEntity, EntityPlayer player)
|
||||
{
|
||||
ItemStack requestStack = null;
|
||||
|
||||
if (tileEntity.getSampleStack() != null)
|
||||
{
|
||||
requestStack = tileEntity.getSampleStack().copy();
|
||||
}
|
||||
|
||||
if (requestStack == null)
|
||||
{
|
||||
requestStack = player.getCurrentEquippedItem();
|
||||
}
|
||||
|
||||
if (requestStack != null && requestStack.itemID != this.blockID)
|
||||
{
|
||||
boolean success = false;
|
||||
|
||||
for (int i = 0; i < player.inventory.getSizeInventory(); i++)
|
||||
{
|
||||
ItemStack currentStack = player.inventory.getStackInSlot(i);
|
||||
|
||||
if (currentStack != null)
|
||||
{
|
||||
if (requestStack.isItemEqual(currentStack))
|
||||
{
|
||||
player.inventory.setInventorySlotContents(i, BlockCrate.addStackToCrate(tileEntity, currentStack));
|
||||
|
||||
if (player instanceof EntityPlayerMP)
|
||||
{
|
||||
((EntityPlayerMP) player).sendContainerToPlayer(player.inventoryContainer);
|
||||
}
|
||||
|
||||
success = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return success;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Ejects and item out of the crate and spawn it under the player entity.
|
||||
*
|
||||
* @param tileEntity
|
||||
* @param player
|
||||
* @param requestSize - The maximum stack size to take out. Default should be 64.
|
||||
* @return True on success
|
||||
*/
|
||||
public boolean ejectItems(TileCrate tileEntity, EntityPlayer player, int requestSize)
|
||||
{
|
||||
World world = tileEntity.worldObj;
|
||||
if (!world.isRemote)
|
||||
{
|
||||
ItemStack sampleStack = tileEntity.getSampleStack();
|
||||
int ammountEjected = 0;
|
||||
if (sampleStack != null && requestSize > 0)
|
||||
{
|
||||
for (int slot = 0; slot < tileEntity.getInventory().getSizeInventory(); slot++)
|
||||
{
|
||||
ItemStack slotStack = tileEntity.getInventory().getStackInSlot(slot);
|
||||
|
||||
if (slotStack != null && slotStack.stackSize > 0)
|
||||
{
|
||||
int amountToTake = Math.min(slotStack.stackSize, requestSize);
|
||||
|
||||
ItemStack dropStack = slotStack.copy();
|
||||
dropStack.stackSize = amountToTake;
|
||||
|
||||
EntityItem entityItem = new EntityItem(world, player.posX, player.posY, player.posZ, dropStack);
|
||||
entityItem.delayBeforeCanPickup = 0;
|
||||
world.spawnEntityInWorld(entityItem);
|
||||
|
||||
slotStack.stackSize -= amountToTake;
|
||||
ammountEjected += amountToTake;
|
||||
if (slotStack.stackSize <= 0)
|
||||
{
|
||||
slotStack = null;
|
||||
}
|
||||
tileEntity.getInventory().setInventorySlotContents(slot, slotStack);
|
||||
|
||||
}
|
||||
if (ammountEjected >= requestSize)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Puts an itemStack into the crate.
|
||||
*
|
||||
* @param tileEntity
|
||||
* @param itemStack
|
||||
*/
|
||||
public static ItemStack addStackToCrate(TileCrate tileEntity, ItemStack itemStack)
|
||||
{
|
||||
if (itemStack == null || itemStack.getItem().isDamageable() && itemStack.getItem().getDamage(itemStack) > 0)
|
||||
{
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
ItemStack containingStack = tileEntity.getSampleStack();
|
||||
|
||||
if (containingStack == null || containingStack != null && containingStack.isItemEqual(itemStack))
|
||||
{
|
||||
int room = Math.max((tileEntity.getInventory().getSizeInventory() * 64) - (containingStack != null ? containingStack.stackSize : 0), 0);
|
||||
if (itemStack.stackSize <= room)
|
||||
{
|
||||
tileEntity.addToStack(itemStack);
|
||||
itemStack = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
tileEntity.addToStack(itemStack, room);
|
||||
itemStack.stackSize -= room;
|
||||
}
|
||||
return itemStack;
|
||||
|
||||
}
|
||||
|
||||
if (itemStack.stackSize <= 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onUseWrench(World world, int x, int y, int z, EntityPlayer par5EntityPlayer, int side, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
if (!world.isRemote && world.getBlockTileEntity(x, y, z) != null)
|
||||
{
|
||||
TileCrate tileEntity = (TileCrate) world.getBlockTileEntity(x, y, z);
|
||||
ItemStack containingStack = tileEntity.getSampleStack();
|
||||
tileEntity.buildSampleStack();
|
||||
|
||||
if (containingStack != null)
|
||||
{
|
||||
if (containingStack.stackSize > 0)
|
||||
{
|
||||
float area = 0.7F;
|
||||
double dropX = (world.rand.nextFloat() * area) + (1.0F - area) * 0.5D;
|
||||
double dropY = (world.rand.nextFloat() * area) + (1.0F - area) * 0.5D;
|
||||
double dropZ = (world.rand.nextFloat() * area) + (1.0F - area) * 0.5D;
|
||||
|
||||
ItemStack dropStack = new ItemStack(this, 1, tileEntity.getBlockMetadata());
|
||||
ItemBlockCrate.setContainingItemStack(dropStack, containingStack);
|
||||
|
||||
EntityItem var13 = new EntityItem(world, x + dropX, y + dropY, z + dropZ, dropStack);
|
||||
var13.delayBeforeCanPickup = 10;
|
||||
world.spawnEntityInWorld(var13);
|
||||
|
||||
for (int i = 0; i < tileEntity.getInventory().getSizeInventory(); i++)
|
||||
{
|
||||
tileEntity.getInventory().setInventorySlotContents(i, null);
|
||||
}
|
||||
world.setBlock(x, y, z, 0, 0, 3);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int damageDropped(int metadata)
|
||||
{
|
||||
return metadata;
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity createNewTileEntity(World var1)
|
||||
{
|
||||
return new TileCrate();
|
||||
}
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package resonantinduction.old.transport.crate;
|
||||
package resonantinduction.archaic.crate;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
|
@ -39,9 +39,9 @@ public class InventoryCrate extends InvChest
|
|||
@Override
|
||||
public int getSizeInventory()
|
||||
{
|
||||
if (this.hostTile instanceof TileEntityCrate)
|
||||
if (this.hostTile instanceof TileCrate)
|
||||
{
|
||||
return ((TileEntityCrate) this.hostTile).getSlotCount();
|
||||
return ((TileCrate) this.hostTile).getSlotCount();
|
||||
}
|
||||
return 512;
|
||||
}
|
|
@ -1,4 +1,4 @@
|
|||
package resonantinduction.old.transport.crate;
|
||||
package resonantinduction.archaic.crate;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
|
@ -57,7 +57,7 @@ public class ItemBlockCrate extends ItemBlock
|
|||
|
||||
if (containingStack != null && !player.capabilities.isCreativeMode)
|
||||
{
|
||||
player.addPotionEffect(new PotionEffect(Potion.moveSlowdown.id, 5, (int) ((float) containingStack.stackSize / (float) TileEntityCrate.getSlotCount(itemStack.getItemDamage())) * 5));
|
||||
player.addPotionEffect(new PotionEffect(Potion.moveSlowdown.id, 5, (int) ((float) containingStack.stackSize / (float) TileCrate.getSlotCount(itemStack.getItemDamage())) * 5));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -121,7 +121,7 @@ public class ItemBlockCrate extends ItemBlock
|
|||
{
|
||||
if (containingItem.stackSize > 0)
|
||||
{
|
||||
TileEntityCrate tileEntity = (TileEntityCrate) world.getBlockTileEntity(x, y, z);
|
||||
TileCrate tileEntity = (TileCrate) world.getBlockTileEntity(x, y, z);
|
||||
int count = containingItem.stackSize;
|
||||
|
||||
for (int slot = 0; slot < tileEntity.getInventory().getSizeInventory(); slot++)
|
|
@ -1,4 +1,4 @@
|
|||
package resonantinduction.old.transport.crate;
|
||||
package resonantinduction.archaic.crate;
|
||||
|
||||
/**
|
||||
* Can that is used to store items such as food, parts, or solid fuels.
|
|
@ -1,4 +1,4 @@
|
|||
package resonantinduction.old.transport.crate;
|
||||
package resonantinduction.archaic.crate;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
@ -52,7 +52,7 @@ public class PathfinderCrate
|
|||
@Override
|
||||
public boolean isValidNode(PathfinderCrate finder, ForgeDirection direction, TileEntity provider, TileEntity node)
|
||||
{
|
||||
return node instanceof TileEntityCrate;
|
||||
return node instanceof TileCrate;
|
||||
}
|
||||
|
||||
@Override
|
|
@ -1,4 +1,4 @@
|
|||
package resonantinduction.old.client.render;
|
||||
package resonantinduction.archaic.crate;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
|
@ -17,7 +17,7 @@ import net.minecraftforge.common.ForgeDirection;
|
|||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
import resonantinduction.old.transport.crate.TileEntityCrate;
|
||||
import resonantinduction.archaic.crate.TileCrate;
|
||||
import universalelectricity.api.vector.Vector3;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
@ -32,10 +32,10 @@ public class RenderCrate extends TileEntitySpecialRenderer
|
|||
{
|
||||
Vector3 vec = new Vector3(x, y, z);
|
||||
double distance = vec.distance(new Vector3(0, 0, 0));
|
||||
if (tileEntity instanceof TileEntityCrate)
|
||||
if (tileEntity instanceof TileCrate)
|
||||
{
|
||||
|
||||
TileEntityCrate tileCrate = (TileEntityCrate) tileEntity;
|
||||
TileCrate tileCrate = (TileCrate) tileEntity;
|
||||
|
||||
RenderItem renderItem = ((RenderItem) RenderManager.instance.getEntityClassRenderObject(EntityItem.class));
|
||||
|
|
@ -1,18 +1,18 @@
|
|||
package resonantinduction.old.transport.crate;
|
||||
package resonantinduction.archaic.crate;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.network.packet.Packet;
|
||||
import net.minecraftforge.common.ForgeDirection;
|
||||
import resonantinduction.core.network.ISimplePacketReceiver;
|
||||
import resonantinduction.core.ResonantInduction;
|
||||
import resonantinduction.core.prefab.tile.TileEntityInv;
|
||||
import resonantinduction.mechanical.Mechanical;
|
||||
import calclavia.lib.network.IPacketReceiver;
|
||||
import calclavia.lib.network.PacketHandler;
|
||||
|
||||
import com.google.common.io.ByteArrayDataInput;
|
||||
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
import cpw.mods.fml.common.network.Player;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import dark.lib.interfaces.IExtendedStorage;
|
||||
|
||||
|
@ -21,7 +21,7 @@ import dark.lib.interfaces.IExtendedStorage;
|
|||
*
|
||||
* @author DarkGuardsman
|
||||
*/
|
||||
public class TileEntityCrate extends TileEntityInv implements ISimplePacketReceiver, IExtendedStorage
|
||||
public class TileCrate extends TileEntityInv implements IPacketReceiver, IExtendedStorage
|
||||
{
|
||||
/*
|
||||
* TODO
|
||||
|
@ -155,7 +155,7 @@ public class TileEntityCrate extends TileEntityInv implements ISimplePacketRecei
|
|||
{
|
||||
if (FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER)
|
||||
{
|
||||
PacketHandler.instance().sendPacketToClients(this.getDescriptionPacket(), this.worldObj);
|
||||
PacketHandler.sendPacketToClients(this.getDescriptionPacket(), this.worldObj);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -171,9 +171,9 @@ public class TileEntityCrate extends TileEntityInv implements ISimplePacketRecei
|
|||
{
|
||||
if (this.worldObj == null)
|
||||
{
|
||||
return TileEntityCrate.getSlotCount(TileEntityCrate.maxSize);
|
||||
return TileCrate.getSlotCount(TileCrate.maxSize);
|
||||
}
|
||||
return TileEntityCrate.getSlotCount(this.getBlockMetadata());
|
||||
return TileCrate.getSlotCount(this.getBlockMetadata());
|
||||
}
|
||||
|
||||
/** Gets the slot count for the crate meta */
|
||||
|
@ -197,32 +197,27 @@ public class TileEntityCrate extends TileEntityInv implements ISimplePacketRecei
|
|||
}
|
||||
|
||||
@Override
|
||||
public boolean simplePacket(String id, ByteArrayDataInput data, Player player)
|
||||
public void onReceivePacket(ByteArrayDataInput data, EntityPlayer player, Object... extra)
|
||||
{
|
||||
if (this.worldObj.isRemote)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (id.equalsIgnoreCase("InventoryItem"))
|
||||
if (data.readBoolean())
|
||||
{
|
||||
if (data.readBoolean())
|
||||
{
|
||||
this.sampleStack = ItemStack.loadItemStackFromNBT(PacketHandler.readNBTTagCompound(data));
|
||||
this.sampleStack.stackSize = data.readInt();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.sampleStack = null;
|
||||
}
|
||||
this.sampleStack = ItemStack.loadItemStackFromNBT(PacketHandler.readNBTTagCompound(data));
|
||||
this.sampleStack.stackSize = data.readInt();
|
||||
}
|
||||
else
|
||||
{
|
||||
this.sampleStack = null;
|
||||
}
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -232,11 +227,11 @@ public class TileEntityCrate extends TileEntityInv implements ISimplePacketRecei
|
|||
ItemStack stack = this.getSampleStack();
|
||||
if (stack != null)
|
||||
{
|
||||
return PacketHandler.instance().getTilePacket(Mechanical.CHANNEL, "InventoryItem", this, true, stack.writeToNBT(new NBTTagCompound()), stack.stackSize);
|
||||
return ResonantInduction.PACKET_TILE.getPacket(this, true, stack.writeToNBT(new NBTTagCompound()), stack.stackSize);
|
||||
}
|
||||
else
|
||||
{
|
||||
return PacketHandler.instance().getTilePacket(Mechanical.CHANNEL, "InventoryItem", this, false);
|
||||
return ResonantInduction.PACKET_TILE.getPacket(this, false);
|
||||
}
|
||||
}
|
||||
|
|
@ -10,6 +10,7 @@ import cpw.mods.fml.common.network.Player;
|
|||
*
|
||||
* @author DarkGuardsman
|
||||
*/
|
||||
@Deprecated
|
||||
public interface ISimplePacketReceiver
|
||||
{
|
||||
/**
|
||||
|
|
|
@ -10,12 +10,12 @@ import net.minecraftforge.common.Configuration;
|
|||
import net.minecraftforge.oredict.OreDictionary;
|
||||
import net.minecraftforge.oredict.ShapedOreRecipe;
|
||||
import net.minecraftforge.oredict.ShapelessOreRecipe;
|
||||
import resonantinduction.archaic.crate.BlockCrate;
|
||||
import resonantinduction.core.resource.item.ItemParts.Parts;
|
||||
import resonantinduction.mechanical.fluid.pipe.FluidContainerMaterial;
|
||||
import resonantinduction.old.core.ItemOreDirv;
|
||||
import resonantinduction.old.core.misc.EnumTool;
|
||||
import resonantinduction.old.mechanics.processor.BlockProcessor;
|
||||
import resonantinduction.old.transport.crate.BlockCrate;
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import dark.lib.EnumMaterial;
|
||||
import dark.lib.EnumOrePart;
|
||||
|
|
|
@ -1,447 +0,0 @@
|
|||
package resonantinduction.old.transport.crate;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.client.renderer.texture.IconRegister;
|
||||
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
|
||||
import net.minecraft.creativetab.CreativeTabs;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.Icon;
|
||||
import net.minecraft.world.World;
|
||||
import resonantinduction.core.Reference;
|
||||
import resonantinduction.core.Settings;
|
||||
import resonantinduction.core.prefab.block.BlockRI;
|
||||
import resonantinduction.old.client.render.RenderCrate;
|
||||
import universalelectricity.api.UniversalElectricity;
|
||||
|
||||
import com.builtbroken.common.Pair;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
|
||||
/** A block that allows the placement of mass amount of a specific item within it. It will be allowed
|
||||
* to go on Conveyor Belts
|
||||
*
|
||||
* @author DarkGuardsman */
|
||||
public class BlockCrate extends BlockRI
|
||||
{
|
||||
Icon adv, elt;
|
||||
|
||||
public BlockCrate()
|
||||
{
|
||||
super(Settings.CONFIGURATION, "crate", UniversalElectricity.machine);
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public void registerIcons(IconRegister iconReg)
|
||||
{
|
||||
this.blockIcon = iconReg.registerIcon(Reference.PREFIX + "crate");
|
||||
this.adv = iconReg.registerIcon(Reference.PREFIX + "crate_adv");
|
||||
this.elt = iconReg.registerIcon(Reference.PREFIX + "crate_elt");
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public Icon getIcon(int side, int meta)
|
||||
{
|
||||
if (meta == 1)
|
||||
{
|
||||
return adv;
|
||||
}
|
||||
else if (meta == 2)
|
||||
{
|
||||
return elt;
|
||||
}
|
||||
return this.blockIcon;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBlockClicked(World world, int x, int y, int z, EntityPlayer player)
|
||||
{
|
||||
if (!world.isRemote)
|
||||
{
|
||||
if (world.getBlockTileEntity(x, y, z) instanceof TileEntityCrate)
|
||||
{
|
||||
TileEntityCrate tileEntity = (TileEntityCrate) world.getBlockTileEntity(x, y, z);
|
||||
|
||||
/** Make double clicking input all stacks. */
|
||||
boolean allMode = (world.getWorldTime() - tileEntity.prevClickTime < 10);
|
||||
|
||||
tileEntity.prevClickTime = world.getWorldTime();
|
||||
|
||||
this.tryEject(tileEntity, player, allMode);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
/** Placed the item the player is holding into the crate. */
|
||||
@Override
|
||||
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
if (super.onBlockActivated(world, x, y, z, entityPlayer, side, hitX, hitY, hitZ))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if (!world.isRemote)
|
||||
{
|
||||
if (world.getBlockTileEntity(x, y, z) instanceof TileEntityCrate)
|
||||
{
|
||||
TileEntityCrate tileEntity = (TileEntityCrate) world.getBlockTileEntity(x, y, z);
|
||||
|
||||
/** Make double clicking input all stacks. */
|
||||
boolean allMode = (world.getWorldTime() - tileEntity.prevClickTime < 10);
|
||||
|
||||
tileEntity.prevClickTime = world.getWorldTime();
|
||||
ItemStack current = entityPlayer.inventory.getCurrentItem();
|
||||
if (side == 1 && entityPlayer.capabilities.isCreativeMode)
|
||||
{
|
||||
if (current != null && tileEntity.getSampleStack() == null)
|
||||
{
|
||||
ItemStack cStack = current.copy();
|
||||
cStack.stackSize = TileEntityCrate.getSlotCount(world.getBlockMetadata(x, y, z)) * 64;
|
||||
BlockCrate.addStackToCrate(tileEntity, cStack);
|
||||
}
|
||||
}
|
||||
// Add items
|
||||
if (side == 1 || (side > 1 && hitY > 0.5) || !entityPlayer.capabilities.isCreativeMode)
|
||||
{
|
||||
this.tryInsert(tileEntity, entityPlayer, allMode);
|
||||
}
|
||||
// Remove items
|
||||
else if (side == 0 || (side > 1 && hitY <= 0.5))
|
||||
{
|
||||
this.tryEject(tileEntity, entityPlayer, allMode);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
/** Try to inject it into the crate. Otherwise, look around for nearby crates and try to put them
|
||||
* in. */
|
||||
public void tryInsert(TileEntityCrate tileEntity, EntityPlayer player, boolean allMode, boolean doSearch)
|
||||
{
|
||||
boolean success;
|
||||
|
||||
if (allMode)
|
||||
{
|
||||
success = this.insertAllItems(tileEntity, player);
|
||||
}
|
||||
else
|
||||
{
|
||||
success = this.insertCurrentItem(tileEntity, player);
|
||||
}
|
||||
|
||||
if (!success && doSearch)
|
||||
{
|
||||
PathfinderCrate pathfinder = new PathfinderCrate().init(tileEntity);
|
||||
|
||||
for (TileEntity checkTile : pathfinder.iteratedNodes)
|
||||
{
|
||||
if (checkTile instanceof TileEntityCrate)
|
||||
{
|
||||
this.tryInsert(((TileEntityCrate) checkTile), player, allMode, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public void tryInsert(TileEntityCrate tileEntity, EntityPlayer player, boolean allMode)
|
||||
{
|
||||
this.tryInsert(tileEntity, player, allMode, true);
|
||||
}
|
||||
|
||||
public void tryEject(TileEntityCrate tileEntity, EntityPlayer player, boolean allMode)
|
||||
{
|
||||
if (tileEntity.getSampleStack() == null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
if (allMode && !player.isSneaking())
|
||||
{
|
||||
this.ejectItems(tileEntity, player, tileEntity.getSlotCount() * 64);
|
||||
}
|
||||
else
|
||||
{
|
||||
if (player.isSneaking())
|
||||
{
|
||||
this.ejectItems(tileEntity, player, 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
this.ejectItems(tileEntity, player, tileEntity.getSampleStack().getMaxStackSize());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/** Inserts a the itemStack the player is holding into the crate. */
|
||||
public boolean insertCurrentItem(TileEntityCrate tileEntity, EntityPlayer player)
|
||||
{
|
||||
ItemStack currentStack = player.getCurrentEquippedItem();
|
||||
|
||||
if (currentStack != null)
|
||||
{
|
||||
if (currentStack.getItem().itemID == this.blockID)
|
||||
{
|
||||
ItemStack containedStack = ItemBlockCrate.getContainingItemStack(currentStack);
|
||||
ItemStack crateStack = tileEntity.getSampleStack();
|
||||
if (containedStack != null && (crateStack == null || (crateStack != null && containedStack.isItemEqual(crateStack))))
|
||||
{
|
||||
ItemStack returned = BlockCrate.addStackToCrate(tileEntity, containedStack);
|
||||
ItemBlockCrate.setContainingItemStack(currentStack, returned);
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
if (tileEntity.getSampleStack() != null)
|
||||
{
|
||||
if (!tileEntity.getSampleStack().isItemEqual(currentStack))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
player.inventory.setInventorySlotContents(player.inventory.currentItem, BlockCrate.addStackToCrate(tileEntity, currentStack));
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/** Inserts all items of the same type this player has into the crate.
|
||||
*
|
||||
* @return True on success */
|
||||
public boolean insertAllItems(TileEntityCrate tileEntity, EntityPlayer player)
|
||||
{
|
||||
ItemStack requestStack = null;
|
||||
|
||||
if (tileEntity.getSampleStack() != null)
|
||||
{
|
||||
requestStack = tileEntity.getSampleStack().copy();
|
||||
}
|
||||
|
||||
if (requestStack == null)
|
||||
{
|
||||
requestStack = player.getCurrentEquippedItem();
|
||||
}
|
||||
|
||||
if (requestStack != null && requestStack.itemID != this.blockID)
|
||||
{
|
||||
boolean success = false;
|
||||
|
||||
for (int i = 0; i < player.inventory.getSizeInventory(); i++)
|
||||
{
|
||||
ItemStack currentStack = player.inventory.getStackInSlot(i);
|
||||
|
||||
if (currentStack != null)
|
||||
{
|
||||
if (requestStack.isItemEqual(currentStack))
|
||||
{
|
||||
player.inventory.setInventorySlotContents(i, BlockCrate.addStackToCrate(tileEntity, currentStack));
|
||||
|
||||
if (player instanceof EntityPlayerMP)
|
||||
{
|
||||
((EntityPlayerMP) player).sendContainerToPlayer(player.inventoryContainer);
|
||||
}
|
||||
|
||||
success = true;
|
||||
}
|
||||
}
|
||||
}
|
||||
return success;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/** Ejects and item out of the crate and spawn it under the player entity.
|
||||
*
|
||||
* @param tileEntity
|
||||
* @param player
|
||||
* @param requestSize - The maximum stack size to take out. Default should be 64.
|
||||
* @return True on success */
|
||||
public boolean ejectItems(TileEntityCrate tileEntity, EntityPlayer player, int requestSize)
|
||||
{
|
||||
World world = tileEntity.worldObj;
|
||||
if (!world.isRemote)
|
||||
{
|
||||
ItemStack sampleStack = tileEntity.getSampleStack();
|
||||
int ammountEjected = 0;
|
||||
if (sampleStack != null && requestSize > 0)
|
||||
{
|
||||
for (int slot = 0; slot < tileEntity.getInventory().getSizeInventory(); slot++)
|
||||
{
|
||||
ItemStack slotStack = tileEntity.getInventory().getStackInSlot(slot);
|
||||
|
||||
if (slotStack != null && slotStack.stackSize > 0)
|
||||
{
|
||||
int amountToTake = Math.min(slotStack.stackSize, requestSize);
|
||||
|
||||
ItemStack dropStack = slotStack.copy();
|
||||
dropStack.stackSize = amountToTake;
|
||||
|
||||
EntityItem entityItem = new EntityItem(world, player.posX, player.posY, player.posZ, dropStack);
|
||||
entityItem.delayBeforeCanPickup = 0;
|
||||
world.spawnEntityInWorld(entityItem);
|
||||
|
||||
slotStack.stackSize -= amountToTake;
|
||||
ammountEjected += amountToTake;
|
||||
if (slotStack.stackSize <= 0)
|
||||
{
|
||||
slotStack = null;
|
||||
}
|
||||
tileEntity.getInventory().setInventorySlotContents(slot, slotStack);
|
||||
|
||||
}
|
||||
if (ammountEjected >= requestSize)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
/** Puts an itemStack into the crate.
|
||||
*
|
||||
* @param tileEntity
|
||||
* @param itemStack */
|
||||
public static ItemStack addStackToCrate(TileEntityCrate tileEntity, ItemStack itemStack)
|
||||
{
|
||||
if (itemStack == null || itemStack.getItem().isDamageable() && itemStack.getItem().getDamage(itemStack) > 0)
|
||||
{
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
ItemStack containingStack = tileEntity.getSampleStack();
|
||||
|
||||
if (containingStack == null || containingStack != null && containingStack.isItemEqual(itemStack))
|
||||
{
|
||||
int room = Math.max((tileEntity.getInventory().getSizeInventory() * 64) - (containingStack != null ? containingStack.stackSize : 0), 0);
|
||||
if (itemStack.stackSize <= room)
|
||||
{
|
||||
tileEntity.addToStack(itemStack);
|
||||
itemStack = null;
|
||||
}
|
||||
else
|
||||
{
|
||||
tileEntity.addToStack(itemStack, room);
|
||||
itemStack.stackSize -= room;
|
||||
}
|
||||
return itemStack;
|
||||
|
||||
}
|
||||
|
||||
if (itemStack.stackSize <= 0)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
|
||||
return itemStack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onUseWrench(World world, int x, int y, int z, EntityPlayer par5EntityPlayer, int side, float hitX, float hitY, float hitZ)
|
||||
{
|
||||
if (!world.isRemote && world.getBlockTileEntity(x, y, z) != null)
|
||||
{
|
||||
TileEntityCrate tileEntity = (TileEntityCrate) world.getBlockTileEntity(x, y, z);
|
||||
ItemStack containingStack = tileEntity.getSampleStack();
|
||||
tileEntity.buildSampleStack();
|
||||
|
||||
if (containingStack != null)
|
||||
{
|
||||
if (containingStack.stackSize > 0)
|
||||
{
|
||||
float area = 0.7F;
|
||||
double dropX = (world.rand.nextFloat() * area) + (1.0F - area) * 0.5D;
|
||||
double dropY = (world.rand.nextFloat() * area) + (1.0F - area) * 0.5D;
|
||||
double dropZ = (world.rand.nextFloat() * area) + (1.0F - area) * 0.5D;
|
||||
|
||||
ItemStack dropStack = new ItemStack(this, 1, tileEntity.getBlockMetadata());
|
||||
ItemBlockCrate.setContainingItemStack(dropStack, containingStack);
|
||||
|
||||
EntityItem var13 = new EntityItem(world, x + dropX, y + dropY, z + dropZ, dropStack);
|
||||
var13.delayBeforeCanPickup = 10;
|
||||
world.spawnEntityInWorld(var13);
|
||||
|
||||
for (int i = 0; i < tileEntity.getInventory().getSizeInventory(); i++)
|
||||
{
|
||||
tileEntity.getInventory().setInventorySlotContents(i, null);
|
||||
}
|
||||
world.setBlock(x, y, z, 0, 0, 3);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int damageDropped(int metadata)
|
||||
{
|
||||
return metadata;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getTileEntities(int blockID, Set<Pair<String, Class<? extends TileEntity>>> list)
|
||||
{
|
||||
list.add(new Pair<String, Class<? extends TileEntity>>("ALCrate", TileEntityCrate.class));
|
||||
}
|
||||
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void getClientTileEntityRenderers(List<Pair<Class<? extends TileEntity>, TileEntitySpecialRenderer>> list)
|
||||
{
|
||||
list.add(new Pair<Class<? extends TileEntity>, TileEntitySpecialRenderer>(TileEntityCrate.class, new RenderCrate()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public TileEntity createNewTileEntity(World var1)
|
||||
{
|
||||
return new TileEntityCrate();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void getSubBlocks(int par1, CreativeTabs par2CreativeTabs, List list)
|
||||
{
|
||||
for (int i = 0; i < 3; i++)
|
||||
{
|
||||
list.add(new ItemStack(this, 1, i));
|
||||
}
|
||||
try
|
||||
{
|
||||
ItemStack stack = new ItemStack(this, 1, 2);
|
||||
ItemBlockCrate.setContainingItemStack(stack, new ItemStack(Block.cobblestone, 2048, 0));
|
||||
list.add(stack);
|
||||
ItemStack stack2 = new ItemStack(this, 1, 2);
|
||||
ItemBlockCrate.setContainingItemStack(stack2, new ItemStack(Item.coal, 2048, 1));
|
||||
list.add(stack);
|
||||
}
|
||||
catch (Exception e)
|
||||
{
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
|
@ -28,7 +28,7 @@ public class BlockEncoder extends BlockRI
|
|||
|
||||
public BlockEncoder()
|
||||
{
|
||||
super(Settings.CONFIGURATION, "encoder", Material.wood);
|
||||
super("encoder");
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
|
|
|
@ -9,8 +9,11 @@ meta.resonantinduction.credits=Visit website for credits.
|
|||
|
||||
fluid.mixture=Mixture
|
||||
|
||||
### Mechanical Module
|
||||
### Archaic Module
|
||||
## Transport
|
||||
tile.resonantinduction\:crate.name=Crate
|
||||
|
||||
### Mechanical Module
|
||||
## Transport
|
||||
tile.resonantinduction\:pump.name=Pump
|
||||
tile.resonantinduction\:grate.name=Grate
|
||||
|
@ -120,7 +123,6 @@ tile.ReleaseValve.0.name=Release Valve
|
|||
tile.FluidSink.0.name = Sink
|
||||
tile.ConstructionPump.0.name = Construction Pump
|
||||
|
||||
tile.crate.name=Crate
|
||||
tile.crate.0.name=Basic Crate
|
||||
tile.crate.1.name=Advanced Crate
|
||||
tile.crate.2.name=Elite Crate
|
||||
|
|
Loading…
Reference in a new issue