worked on the advanced hopper

This commit is contained in:
Robert 2013-11-13 19:33:50 -05:00
parent 3b1484e53c
commit 46bb0f1eb4
13 changed files with 375 additions and 549 deletions

BIN
models/AdvancedHopper.tcn Normal file

Binary file not shown.

Binary file not shown.

After

Width:  |  Height:  |  Size: 1,018 B

View file

@ -7,8 +7,8 @@ public interface IManipulator
{
/** Find items going into the manipulator and input them into an inventory behind this
* manipulator. */
public void eject();
public void inject();
/** Injects items */
public void inject();
public void enject();
}

View file

@ -21,10 +21,9 @@ public class ALRecipeLoader extends RecipeLoader
public static Block blockDetector;
public static Block blockRejector;
public static Block blockArmbot;
public static Block blockCraneController;
public static Block blockCraneFrame;
public static Block blockTurntable;
public static Block processorMachine;
public static Block blockAdvancedHopper;
public static Item itemImprint;
public static Item itemDisk;

View file

@ -45,6 +45,7 @@ import dark.assembly.machine.encoder.BlockEncoder;
import dark.assembly.machine.encoder.ItemDisk;
import dark.assembly.machine.encoder.TileEntityEncoder;
import dark.assembly.machine.processor.BlockProcessor;
import dark.assembly.machine.red.BlockAdvancedHopper;
import dark.core.common.DMCreativeTab;
import dark.core.common.DarkMain;
import dark.core.prefab.ItemBlockHolder;
@ -154,6 +155,7 @@ public class AssemblyLine extends ModPrefab
ALRecipeLoader.blockArmbot = new BlockArmbot();
ALRecipeLoader.blockTurntable = new BlockTurntable();
ALRecipeLoader.processorMachine = ModObjectRegistry.createNewBlock("ALBlockProcessor", AssemblyLine.MOD_ID, BlockProcessor.class, ItemBlockHolder.class);
ALRecipeLoader.blockAdvancedHopper = ModObjectRegistry.createNewBlock("ALBlockHopper", AssemblyLine.MOD_ID, BlockAdvancedHopper.class, ItemBlockHolder.class);
ALRecipeLoader.itemImprint = new ItemImprinter(CONFIGURATION.getItem("Imprint", ITEM_ID_PREFIX).getInt());
ALRecipeLoader.itemDisk = new ItemDisk(CONFIGURATION.getItem("Disk", ITEM_ID_PREFIX + 1).getInt());

View file

@ -9,6 +9,7 @@ import cpw.mods.fml.client.registry.ClientRegistry;
import cpw.mods.fml.client.registry.RenderingRegistry;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import dark.assembly.ALRecipeLoader;
import dark.assembly.CommonProxy;
import dark.assembly.armbot.TileEntityArmbot;
import dark.assembly.client.gui.GuiEncoderCoder;
@ -17,6 +18,7 @@ import dark.assembly.client.gui.GuiEncoderInventory;
import dark.assembly.client.gui.GuiImprinter;
import dark.assembly.client.gui.GuiProcessor;
import dark.assembly.client.render.BlockRenderingHandler;
import dark.assembly.client.render.RenderAdvancedHopper;
import dark.assembly.client.render.RenderArmbot;
import dark.assembly.client.render.RenderConveyorBelt;
import dark.assembly.client.render.RenderCrate;
@ -32,6 +34,7 @@ import dark.assembly.machine.TileEntityRejector;
import dark.assembly.machine.belt.TileEntityConveyorBelt;
import dark.assembly.machine.encoder.TileEntityEncoder;
import dark.assembly.machine.processor.TileEntityProcessor;
import dark.assembly.machine.red.TileEntityAdvancedHopper;
@SideOnly(Side.CLIENT)
public class ClientProxy extends CommonProxy
@ -50,11 +53,19 @@ public class ClientProxy extends CommonProxy
super.init();
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityConveyorBelt.class, new RenderConveyorBelt());
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityRejector.class, new RenderRejector());
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityProcessor.class, new RenderProcessor());
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityManipulator.class, new RenderManipulator());
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityCrate.class, new RenderCrate());
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityArmbot.class, new RenderArmbot());
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityDetector.class, new RenderDetector());
if (ALRecipeLoader.processorMachine != null)
{
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityProcessor.class, new RenderProcessor());
}
if (ALRecipeLoader.blockAdvancedHopper != null)
{
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityAdvancedHopper.class, new RenderAdvancedHopper());
}
//ClientRegistry.bindTileEntitySpecialRenderer(TileEntityCraneController.class, new RenderCraneController());
//ClientRegistry.bindTileEntitySpecialRenderer(TileEntityCraneRail.class, new RenderCraneFrame());
}

View file

@ -0,0 +1,140 @@
// Date: 11/13/2013 7:19:55 PM
// Template version 1.1
// Java generated by Techne
// Keep in mind that you still need to fill in some blanks
// - ZeuX
package dark.assembly.client.model;
import net.minecraft.client.model.ModelBase;
import net.minecraft.client.model.ModelRenderer;
import net.minecraftforge.common.ForgeDirection;
public class ModelAdvancedHopper extends ModelBase
{
//fields
ModelRenderer bottomConnection;
ModelRenderer center;
ModelRenderer top;
ModelRenderer top2;
ModelRenderer top3;
ModelRenderer top4;
ModelRenderer top5;
ModelRenderer frontConnection;
ModelRenderer backConnection;
ModelRenderer leftConnection;
ModelRenderer rightConnection;
public ModelAdvancedHopper()
{
textureWidth = 128;
textureHeight = 128;
bottomConnection = new ModelRenderer(this, 18, 0);
bottomConnection.addBox(-2F, 0F, -2F, 4, 4, 4);
bottomConnection.setRotationPoint(0F, 20F, 0F);
bottomConnection.setTextureSize(128, 128);
bottomConnection.mirror = true;
setRotation(bottomConnection, 0F, 0.7853982F, 0F);
center = new ModelRenderer(this, 45, 0);
center.addBox(-4F, 0F, -4F, 8, 6, 8);
center.setRotationPoint(0F, 14F, 0F);
center.setTextureSize(128, 128);
center.mirror = true;
setRotation(center, 0F, 0F, 0F);
top = new ModelRenderer(this, 0, 33);
top.addBox(-8F, -4F, -8F, 16, 6, 2);
top.setRotationPoint(0F, 12F, 0F);
top.setTextureSize(128, 128);
top.mirror = true;
setRotation(top, 0F, 0F, 0F);
top2 = new ModelRenderer(this, 0, 62);
top2.addBox(-8F, -4F, 6F, 16, 6, 2);
top2.setRotationPoint(0F, 12F, 0F);
top2.setTextureSize(128, 128);
top2.mirror = true;
setRotation(top2, 0F, 0F, 0F);
top3 = new ModelRenderer(this, 0, 42);
top3.addBox(-8F, -4F, -6F, 2, 6, 12);
top3.setRotationPoint(0F, 12F, 0F);
top3.setTextureSize(128, 128);
top3.mirror = true;
setRotation(top3, 0F, 0F, 0F);
top4 = new ModelRenderer(this, 30, 42);
top4.addBox(6F, -4F, -6F, 2, 6, 12);
top4.setRotationPoint(0F, 12F, 0F);
top4.setTextureSize(128, 128);
top4.mirror = true;
setRotation(top4, 0F, 0F, 0F);
top5 = new ModelRenderer(this, 61, 44);
top5.addBox(-6F, 0F, -6F, 12, 1, 12);
top5.setRotationPoint(0F, 13F, 0F);
top5.setTextureSize(128, 128);
top5.mirror = true;
setRotation(top5, 0F, 0F, 0F);
frontConnection = new ModelRenderer(this, 0, 0);
frontConnection.addBox(-2F, -2F, -4F, 4, 5, 4);
frontConnection.setRotationPoint(0F, 16F, -4F);
frontConnection.setTextureSize(128, 128);
frontConnection.mirror = true;
setRotation(frontConnection, 0F, 0F, 0F);
backConnection = new ModelRenderer(this, 0, 0);
backConnection.addBox(-2F, -2F, 0F, 4, 5, 4);
backConnection.setRotationPoint(0F, 16F, 4F);
backConnection.setTextureSize(128, 128);
backConnection.mirror = true;
setRotation(backConnection, 0F, 0F, 0F);
leftConnection = new ModelRenderer(this, 0, 0);
leftConnection.addBox(0F, -2F, -2F, 4, 5, 4);
leftConnection.setRotationPoint(4F, 16F, 0F);
leftConnection.setTextureSize(128, 128);
leftConnection.mirror = true;
setRotation(leftConnection, 0F, 0F, 0F);
rightConnection = new ModelRenderer(this, 0, 0);
rightConnection.addBox(-4F, -3F, -2F, 4, 5, 4);
rightConnection.setRotationPoint(-4F, 17F, 0F);
rightConnection.setTextureSize(128, 128);
rightConnection.mirror = true;
setRotation(rightConnection, 0F, 0F, 0F);
}
public void render(float f5)
{
center.render(f5);
top.render(f5);
top2.render(f5);
top3.render(f5);
top4.render(f5);
top5.render(f5);
}
public void render(float f5, ForgeDirection side)
{
switch (side)
{
case NORTH:
frontConnection.render(f5);
break;
case SOUTH:
backConnection.render(f5);
break;
case EAST:
leftConnection.render(f5);
break;
case WEST:
rightConnection.render(f5);
break;
case DOWN:
bottomConnection.render(f5);
break;
}
}
private void setRotation(ModelRenderer model, float x, float y, float z)
{
model.rotateAngleX = x;
model.rotateAngleY = y;
model.rotateAngleZ = z;
}
}

View file

@ -1,7 +1,10 @@
package dark.assembly.client.render;
import net.minecraft.block.Block;
import net.minecraft.block.BlockHopper;
import net.minecraft.client.renderer.EntityRenderer;
import net.minecraft.client.renderer.RenderBlocks;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.util.ResourceLocation;
import net.minecraft.world.IBlockAccess;
@ -19,6 +22,7 @@ import dark.assembly.client.model.ModelCrusher;
import dark.assembly.client.model.ModelGrinder;
import dark.assembly.client.model.ModelManipulator;
import dark.assembly.client.model.ModelRejectorPiston;
import dark.assembly.machine.red.BlockAdvancedHopper;
import dark.core.prefab.ModPrefab;
@SideOnly(Side.CLIENT)
@ -103,6 +107,10 @@ public class BlockRenderingHandler implements ISimpleBlockRenderingHandler
@Override
public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block block, int modelId, RenderBlocks renderer)
{
if (block instanceof BlockAdvancedHopper)
{
return true;
}
return false;
}

View file

@ -0,0 +1,59 @@
package dark.assembly.client.render;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.common.ForgeDirection;
import org.lwjgl.opengl.GL11;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import dark.assembly.AssemblyLine;
import dark.assembly.client.model.ModelAdvancedHopper;
import dark.assembly.client.model.ModelManipulator;
import dark.assembly.machine.TileEntityManipulator;
import dark.assembly.machine.red.TileEntityAdvancedHopper;
import dark.core.prefab.ModPrefab;
@SideOnly(Side.CLIENT)
public class RenderAdvancedHopper extends RenderImprintable
{
private static final ModelAdvancedHopper MODEL = new ModelAdvancedHopper();
public static final ResourceLocation TEXTURE = new ResourceLocation(AssemblyLine.instance.DOMAIN, ModPrefab.MODEL_DIRECTORY + "AdvancedHopper.png");
private void renderAModelAt(TileEntityAdvancedHopper tileEntity, double x, double y, double z, float f)
{
GL11.glPushMatrix();
GL11.glTranslatef((float) x + 0.5F, (float) y + 1.5F, (float) z + 0.5F);
GL11.glRotatef(180f, 0f, 0f, 1f);
bindTexture(TEXTURE);
MODEL.render(0.0625F);
if (tileEntity.singleConnection)
{
MODEL.render(0.0625F, tileEntity.connection);
}
else
{
for (ForgeDirection direction : ForgeDirection.VALID_DIRECTIONS)
{
if (tileEntity.connections[direction.ordinal()])
{
MODEL.render(0.0625F, direction);
}
}
}
GL11.glPopMatrix();
}
@Override
public void renderTileEntityAt(TileEntity tileEntity, double var2, double var4, double var6, float var8)
{
this.renderAModelAt((TileEntityAdvancedHopper) tileEntity, var2, var4, var6, var8);
}
}

View file

@ -16,6 +16,11 @@ public abstract class TileEntityFilterable extends TileEntityAssembly implements
private ItemStack filterItem;
private boolean inverted;
public TileEntityFilterable()
{
super(0f);
}
public TileEntityFilterable(float wattsPerTick, float maxEnergy)
{
super(wattsPerTick, maxEnergy);

View file

@ -47,7 +47,7 @@ public class TileEntityManipulator extends TileEntityFilterable implements IRota
{
if (!this.isOutput)
{
this.inject();
this.enject();
}
else
{
@ -60,7 +60,7 @@ public class TileEntityManipulator extends TileEntityFilterable implements IRota
/** Finds the connected inventory and outputs the items upon a redstone pulse. */
if (this.isRedstonePowered)
{
this.eject();
this.inject();
}
}
}
@ -70,7 +70,7 @@ public class TileEntityManipulator extends TileEntityFilterable implements IRota
/** Find items going into the manipulator and input them into an inventory behind this
* manipulator. */
@Override
public void inject()
public void enject()
{
Vector3 inputPosition = new Vector3(this);
/** output location up */
@ -131,7 +131,7 @@ public class TileEntityManipulator extends TileEntityFilterable implements IRota
/** Inject items */
@Override
public void eject()
public void inject()
{
this.isRedstonePowered = false;
/** input location up */

View file

@ -2,21 +2,20 @@ package dark.assembly.machine.red;
import java.util.List;
import java.util.Random;
import java.util.Set;
import com.builtbroken.common.Pair;
import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.tileentity.TileEntityHopper;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.Facing;
import net.minecraft.util.Icon;
@ -24,13 +23,16 @@ import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import dark.assembly.AssemblyLine;
import dark.core.common.DMCreativeTab;
import dark.core.common.DarkMain;
import dark.core.prefab.machine.BlockMachine;
/** Block for an advanced version of the vanilla minecraft hopper
*
* @author DarkGuardsman */
public class BlockAdvancedHopper extends BlockMachine
{
private final Random rand = new Random();
@SideOnly(Side.CLIENT)
public static Icon hopperIcon;
@SideOnly(Side.CLIENT)
@ -38,255 +40,119 @@ public class BlockAdvancedHopper extends BlockMachine
@SideOnly(Side.CLIENT)
public static Icon hopperInsideIcon;
public BlockAdvancedHopper(int par1)
public BlockAdvancedHopper()
{
super(DarkMain.CONFIGURATION, "DMHopper", Material.iron);
super(AssemblyLine.CONFIGURATION, "DMHopper", Material.iron);
this.setCreativeTab(DMCreativeTab.tabAutomation);
this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
}
/** Updates the blocks bounds based on its current state. Args: world, x, y, z */
public void setBlockBoundsBasedOnState(IBlockAccess par1IBlockAccess, int par2, int par3, int par4)
@Override
public void setBlockBoundsBasedOnState(IBlockAccess world, int x, int y, int z)
{
this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
}
/** Adds all intersecting collision boxes to a list. (Be sure to only add boxes to the list if
* they intersect the mask.) Parameters: World, X, Y, Z, mask, list, colliding entity */
public void addCollisionBoxesToList(World par1World, int par2, int par3, int par4, AxisAlignedBB par5AxisAlignedBB, List par6List, Entity par7Entity)
@Override
public void addCollisionBoxesToList(World world, int x, int y, int z, AxisAlignedBB box, List boxList, Entity entity)
{
this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.625F, 1.0F);
super.addCollisionBoxesToList(par1World, par2, par3, par4, par5AxisAlignedBB, par6List, par7Entity);
float f = 0.125F;
this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 0.625F, 1.0F);
super.addCollisionBoxesToList(world, x, y, z, box, boxList, entity);
this.setBlockBounds(0.0F, 0.0F, 0.0F, f, 1.0F, 1.0F);
super.addCollisionBoxesToList(par1World, par2, par3, par4, par5AxisAlignedBB, par6List, par7Entity);
super.addCollisionBoxesToList(world, x, y, z, box, boxList, entity);
this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, f);
super.addCollisionBoxesToList(par1World, par2, par3, par4, par5AxisAlignedBB, par6List, par7Entity);
super.addCollisionBoxesToList(world, x, y, z, box, boxList, entity);
this.setBlockBounds(1.0F - f, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
super.addCollisionBoxesToList(par1World, par2, par3, par4, par5AxisAlignedBB, par6List, par7Entity);
super.addCollisionBoxesToList(world, x, y, z, box, boxList, entity);
this.setBlockBounds(0.0F, 0.0F, 1.0F - f, 1.0F, 1.0F, 1.0F);
super.addCollisionBoxesToList(par1World, par2, par3, par4, par5AxisAlignedBB, par6List, par7Entity);
super.addCollisionBoxesToList(world, x, y, z, box, boxList, entity);
this.setBlockBounds(0.0F, 0.0F, 0.0F, 1.0F, 1.0F, 1.0F);
}
/** Called when a block is placed using its ItemBlock. Args: World, X, Y, Z, side, hitX, hitY,
* hitZ, block metadata */
public int onBlockPlaced(World par1World, int par2, int par3, int par4, int par5, float par6, float par7, float par8, int par9)
@Override
public int onBlockPlaced(World world, int x, int y, int z, int side, float xSide, float ySide, float zSide, int meta)
{
int j1 = Facing.oppositeSide[par5];
if (j1 == 1)
meta = Facing.oppositeSide[side];
if (meta == 1)
{
j1 = 0;
meta = 0;
}
return j1;
return meta;
}
/** Returns a new instance of a block's tile entity class. Called on placing the block. */
public TileEntity createNewTileEntity(World par1World)
@Override
public TileEntity createNewTileEntity(World world)
{
return new TileEntityAdvancedHopper();
}
/** Called when the block is placed in the world. */
public void onBlockPlacedBy(World par1World, int par2, int par3, int par4, EntityLivingBase par5EntityLivingBase, ItemStack par6ItemStack)
@Override
public void getTileEntities(int blockID, Set<Pair<String, Class<? extends TileEntity>>> list)
{
super.onBlockPlacedBy(par1World, par2, par3, par4, par5EntityLivingBase, par6ItemStack);
if (par6ItemStack.hasDisplayName())
{
TileEntityAdvancedHopper tileentityhopper = getHopperTile(par1World, par2, par3, par4);
tileentityhopper.setInventoryName(par6ItemStack.getDisplayName());
}
}
/** Called whenever the block is added into the world. Args: world, x, y, z */
public void onBlockAdded(World par1World, int par2, int par3, int par4)
{
super.onBlockAdded(par1World, par2, par3, par4);
this.updateMetadata(par1World, par2, par3, par4);
}
/** Called upon block activation (right click on the block.) */
public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9)
{
if (par1World.isRemote)
{
return true;
}
else
{
TileEntityAdvancedHopper tileentityhopper = getHopperTile(par1World, par2, par3, par4);
if (tileentityhopper != null)
{
par5EntityPlayer.displayGUIHopper(tileentityhopper);
}
return true;
}
}
/** Lets the block know when one of its neighbor changes. Doesn't know which neighbor changed
* (coordinates passed are their own) Args: x, y, z, neighbor blockID */
public void onNeighborBlockChange(World par1World, int par2, int par3, int par4, int par5)
{
this.updateMetadata(par1World, par2, par3, par4);
}
/** Updates the Metadata to include if the Hopper gets powered by Redstone or not */
private void updateMetadata(World par1World, int par2, int par3, int par4)
{
int l = par1World.getBlockMetadata(par2, par3, par4);
int i1 = getDirectionFromMetadata(l);
boolean flag = !par1World.isBlockIndirectlyGettingPowered(par2, par3, par4);
boolean flag1 = getIsBlockNotPoweredFromMetadata(l);
if (flag != flag1)
{
par1World.setBlockMetadataWithNotify(par2, par3, par4, i1 | (flag ? 0 : 8), 4);
}
}
/** Called on server worlds only when the block has been replaced by a different block ID, or the
* same block with a different metadata value, but before the new metadata value is set. Args:
* World, x, y, z, old block ID, old metadata */
public void breakBlock(World par1World, int par2, int par3, int par4, int par5, int par6)
{
TileEntityAdvancedHopper tileentityhopper = (TileEntityAdvancedHopper) par1World.getBlockTileEntity(par2, par3, par4);
if (tileentityhopper != null)
{
for (int j1 = 0; j1 < tileentityhopper.getSizeInventory(); ++j1)
{
ItemStack itemstack = tileentityhopper.getStackInSlot(j1);
if (itemstack != null)
{
float f = this.rand.nextFloat() * 0.8F + 0.1F;
float f1 = this.rand.nextFloat() * 0.8F + 0.1F;
float f2 = this.rand.nextFloat() * 0.8F + 0.1F;
while (itemstack.stackSize > 0)
{
int k1 = this.rand.nextInt(21) + 10;
if (k1 > itemstack.stackSize)
{
k1 = itemstack.stackSize;
}
itemstack.stackSize -= k1;
EntityItem entityitem = new EntityItem(par1World, (double) ((float) par2 + f), (double) ((float) par3 + f1), (double) ((float) par4 + f2), new ItemStack(itemstack.itemID, k1, itemstack.getItemDamage()));
if (itemstack.hasTagCompound())
{
entityitem.getEntityItem().setTagCompound((NBTTagCompound) itemstack.getTagCompound().copy());
}
float f3 = 0.05F;
entityitem.motionX = (double) ((float) this.rand.nextGaussian() * f3);
entityitem.motionY = (double) ((float) this.rand.nextGaussian() * f3 + 0.2F);
entityitem.motionZ = (double) ((float) this.rand.nextGaussian() * f3);
par1World.spawnEntityInWorld(entityitem);
}
}
}
par1World.func_96440_m(par2, par3, par4, par5);
}
super.breakBlock(par1World, par2, par3, par4, par5, par6);
list.add(new Pair<String, Class<? extends TileEntity>>("DMTileHopper", TileEntityAdvancedHopper.class));
}
/** The type of render function that is called for this block */
@Override
public int getRenderType()
{
return 38;
return -1;
}
/** If this block doesn't render as an ordinary block it will return False (examples: signs,
* buttons, stairs, etc) */
@Override
public boolean renderAsNormalBlock()
{
return false;
}
/** Is this block (a) opaque and (b) a full 1m cube? This determines whether or not to render the
* shared face of two adjacent blocks and also whether the player can attach torches, redstone
* wire, etc to this block. */
@Override
public boolean isOpaqueCube()
{
return false;
}
public static int getDirectionFromMetadata(int par0)
{
return par0 & 7;
}
@Override
@SideOnly(Side.CLIENT)
/**
* Returns true if the given side of this block type should be rendered, if the adjacent block is at the given
* coordinates. Args: blockAccess, x, y, z, side
*/
public boolean shouldSideBeRendered(IBlockAccess par1IBlockAccess, int par2, int par3, int par4, int par5)
public boolean shouldSideBeRendered(IBlockAccess world, int x, int y, int z, int side)
{
return true;
}
@Override
@SideOnly(Side.CLIENT)
/**
* From the specified side and block metadata retrieves the blocks texture. Args: side, metadata
*/
public Icon getIcon(int par1, int par2)
public Icon getIcon(int side, int meta)
{
return par1 == 1 ? this.hopperTopIcon : this.hopperIcon;
return side == 1 ? BlockAdvancedHopper.hopperTopIcon : BlockAdvancedHopper.hopperIcon;
}
public static boolean getIsBlockNotPoweredFromMetadata(int par0)
{
return (par0 & 8) != 8;
}
/** If this returns true, then comparators facing away from this block will use the value from
* getComparatorInputOverride instead of the actual redstone signal strength. */
@Override
public boolean hasComparatorInputOverride()
{
return true;
}
/** If hasComparatorInputOverride returns true, the return value from this is used instead of the
* redstone signal strength when this block inputs to a comparator. */
public int getComparatorInputOverride(World par1World, int par2, int par3, int par4, int par5)
{
return Container.calcRedstoneFromInventory(getHopperTile(par1World, par2, par3, par4));
}
@Override
@SideOnly(Side.CLIENT)
/**
* When this method is called, your block should register all the icons it needs with the given IconRegister. This
* is the only chance you get to register icons.
*/
public void registerIcons(IconRegister par1IconRegister)
{
this.hopperIcon = par1IconRegister.registerIcon("hopper_outside");
this.hopperTopIcon = par1IconRegister.registerIcon("hopper_top");
this.hopperInsideIcon = par1IconRegister.registerIcon("hopper_inside");
BlockAdvancedHopper.hopperIcon = par1IconRegister.registerIcon("hopper_outside");
BlockAdvancedHopper.hopperTopIcon = par1IconRegister.registerIcon("hopper_top");
BlockAdvancedHopper.hopperInsideIcon = par1IconRegister.registerIcon("hopper_inside");
}
@Override
@SideOnly(Side.CLIENT)
/**
* Gets the icon name of the ItemBlock corresponding to this block. Used by hoppers.
*/
public String getItemIconName()
{
return "hopper";
}
public static TileEntityAdvancedHopper getHopperTile(IBlockAccess par0IBlockAccess, int par1, int par2, int par3)
{
return (TileEntityAdvancedHopper) par0IBlockAccess.getBlockTileEntity(par1, par2, par3);
}
}

View file

@ -2,8 +2,6 @@ package dark.assembly.machine.red;
import java.util.List;
import dark.core.prefab.machine.TileEntityMachine;
import net.minecraft.block.Block;
import net.minecraft.block.BlockChest;
import net.minecraft.command.IEntitySelector;
@ -20,61 +18,121 @@ import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.Facing;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
import universalelectricity.core.vector.Vector3;
import dark.api.al.IManipulator;
import dark.assembly.imprinter.ItemImprinter;
import dark.assembly.imprinter.prefab.TileEntityFilterable;
import dark.assembly.machine.TileEntityManipulator;
import dark.core.helpers.InvInteractionHelper;
import dark.core.helpers.ItemWorldHelper;
import dark.core.prefab.machine.TileEntityMachine;
/** Advanced version of the hopper with features such as redstone control, sorting, filtering, and
* crate version.
*
* @author DarkGuardsman */
public class TileEntityAdvancedHopper extends TileEntityMachine implements Hopper
public class TileEntityAdvancedHopper extends TileEntityFilterable
{
/** The name that is displayed if the hopper was renamed */
private String inventoryName;
private int transferCooldown = -1;
public ForgeDirection connection = ForgeDirection.DOWN;
public boolean[] connections = new boolean[6];
public boolean singleConnection = true;
/** The class that interacts with inventories for this machine */
private InvInteractionHelper invExtractionHelper;
public TileEntityAdvancedHopper()
{
this.invSlots = 5;
}
/** Gets the class that managed extracting and placing items into inventories */
public InvInteractionHelper invHelper()
{
if (invExtractionHelper == null || invExtractionHelper.world != this.worldObj)
{
this.invExtractionHelper = new InvInteractionHelper(this.worldObj, new Vector3(this), this.getFilter() != null ? ItemImprinter.getFilters(getFilter()) : null, this.isInverted());
}
return invExtractionHelper;
}
/** Allows the entity to update its state. Overridden in most subclasses, e.g. the mob spawner
* uses this to count ticks and creates a new spawn inside its implementation. */
@Override
public void updateEntity()
{
if (this.worldObj != null && !this.worldObj.isRemote)
super.updateEntity();
if (!this.worldObj.isRemote && this.ticks % 8 == 0)
{
--this.transferCooldown;
this.grabItems();
this.dumpItems();
}
}
if (!this.isCoolingDown())
public void grabItems()
{
Vector3 inputPos = this.getThisPos().clone().modifyPositionFromSide(ForgeDirection.UP);
List<EntityItem> itemsInBound = ItemWorldHelper.getEntitiesInDirection(worldObj, this.getThisPos(), ForgeDirection.UP);
ItemStack itemStack = invHelper().tryGrabFromPosition(inputPos, ForgeDirection.UP, 1);
if (itemStack != null)
{
itemStack = invHelper().tryPlaceInPosition(itemStack, this.getThisPos(), ForgeDirection.UNKNOWN);
if (itemStack != null)
{
this.setTransferCooldown(0);
this.updateHopper();
itemStack = invHelper().tryPlaceInPosition(itemStack, inputPos, ForgeDirection.DOWN);
if (itemStack != null)
{
invHelper().throwItem(inputPos, itemStack);
}
}
}
else if (inputPos.getTileEntity(worldObj) == null && itemsInBound != null)
{
for (EntityItem entity : itemsInBound)
{
if (entity.isDead)
{
continue;
}
ItemStack remainingStack = entity.getEntityItem().copy();
if (this.getFilter() == null || this.isFiltering(remainingStack))
{
if (remainingStack != null)
{
remainingStack = invHelper().tryPlaceInPosition(itemStack, this.getThisPos(), ForgeDirection.UNKNOWN);
}
if (remainingStack == null || remainingStack.stackSize <= 0)
{
entity.setDead();
}
else
{
entity.setEntityItemStack(remainingStack);
}
}
}
}
}
public boolean updateHopper()
public void dumpItems()
{
if (this.worldObj != null && !this.worldObj.isRemote)
Vector3 outputPos = this.getThisPos().clone().modifyPositionFromSide(this.connection);
for (int slot = 0; slot < this.getInventory().getSizeInventory(); slot++)
{
if (!this.isCoolingDown() && BlockAdvancedHopper.getIsBlockNotPoweredFromMetadata(this.getBlockMetadata()))
if (this.getInventory().getStackInSlot(slot) != null)
{
boolean flag = this.insertItemToInventory();
flag = suckItemsIntoHopper(this) || flag;
if (flag)
ItemStack stack = this.getInventory().getStackInSlot(slot).copy();
if (this.getFilter() == null || this.isFiltering(stack))
{
this.setTransferCooldown(8);
this.onInventoryChanged();
return true;
stack = this.invHelper().tryGrabFromPosition(outputPos, this.connection.getOpposite(), 1);
if (stack == null || !areItemStacksEqualItem(stack, this.getInventory().getStackInSlot(slot)) || this.getInventory().getStackInSlot(slot).stackSize != stack.stackSize)
{
this.getInventory().setInventorySlotContents(slot, stack);
this.onInventoryChanged();
}
}
}
return false;
}
else
{
return false;
}
}
@ -82,344 +140,22 @@ public class TileEntityAdvancedHopper extends TileEntityMachine implements Hoppe
public void readFromNBT(NBTTagCompound nbt)
{
super.readFromNBT(nbt);
if (nbt.hasKey("CustomName"))
{
this.inventoryName = nbt.getString("CustomName");
}
this.transferCooldown = nbt.getInteger("TransferCooldown");
}
@Override
public void writeToNBT(NBTTagCompound nbt)
{
super.writeToNBT(nbt);
nbt.setInteger("TransferCooldown", this.transferCooldown);
if (this.isInvNameLocalized())
{
nbt.setString("CustomName", this.inventoryName);
}
}
/** Returns the name of the inventory. */
@Override
public String getInvName()
{
return this.isInvNameLocalized() ? this.inventoryName : "container.hopper";
return "container.advancedhopper";
}
/** Inserts one item from the hopper into the inventory the hopper is pointing at. */
private boolean insertItemToInventory()
private static boolean areItemStacksEqualItem(ItemStack stack, ItemStack stack2)
{
IInventory iinventory = this.getOutputInventory();
if (iinventory == null)
{
return false;
}
else
{
for (int i = 0; i < this.getSizeInventory(); ++i)
{
if (this.getStackInSlot(i) != null)
{
ItemStack itemstack = this.getStackInSlot(i).copy();
ItemStack itemstack1 = insertStack(iinventory, this.decrStackSize(i, 1), Facing.oppositeSide[BlockAdvancedHopper.getDirectionFromMetadata(this.getBlockMetadata())]);
if (itemstack1 == null || itemstack1.stackSize == 0)
{
iinventory.onInventoryChanged();
return true;
}
this.setInventorySlotContents(i, itemstack);
}
}
return false;
}
}
/** Sucks one item into the given hopper from an inventory or EntityItem above it. */
public static boolean suckItemsIntoHopper(Hopper par0Hopper)
{
IInventory iinventory = getInventoryAboveHopper(par0Hopper);
if (iinventory != null)
{
byte b0 = 0;
if (iinventory instanceof ISidedInventory && b0 > -1)
{
ISidedInventory isidedinventory = (ISidedInventory) iinventory;
int[] aint = isidedinventory.getAccessibleSlotsFromSide(b0);
for (int i = 0; i < aint.length; ++i)
{
if (insertStackFromInventory(par0Hopper, iinventory, aint[i], b0))
{
return true;
}
}
}
else
{
int j = iinventory.getSizeInventory();
for (int k = 0; k < j; ++k)
{
if (insertStackFromInventory(par0Hopper, iinventory, k, b0))
{
return true;
}
}
}
}
else
{
EntityItem entityitem = getEntityAbove(par0Hopper.getWorldObj(), par0Hopper.getXPos(), par0Hopper.getYPos() + 1.0D, par0Hopper.getZPos());
if (entityitem != null)
{
return insertStackFromEntity(par0Hopper, entityitem);
}
}
return false;
}
private static boolean insertStackFromInventory(Hopper par0Hopper, IInventory par1IInventory, int par2, int par3)
{
ItemStack itemstack = par1IInventory.getStackInSlot(par2);
if (itemstack != null && canExtractItemFromInventory(par1IInventory, itemstack, par2, par3))
{
ItemStack itemstack1 = itemstack.copy();
ItemStack itemstack2 = insertStack(par0Hopper, par1IInventory.decrStackSize(par2, 1), -1);
if (itemstack2 == null || itemstack2.stackSize == 0)
{
par1IInventory.onInventoryChanged();
return true;
}
par1IInventory.setInventorySlotContents(par2, itemstack1);
}
return false;
}
public static boolean insertStackFromEntity(IInventory par0IInventory, EntityItem par1EntityItem)
{
boolean flag = false;
if (par1EntityItem == null)
{
return false;
}
else
{
ItemStack itemstack = par1EntityItem.getEntityItem().copy();
ItemStack itemstack1 = insertStack(par0IInventory, itemstack, -1);
if (itemstack1 != null && itemstack1.stackSize != 0)
{
par1EntityItem.setEntityItemStack(itemstack1);
}
else
{
flag = true;
par1EntityItem.setDead();
}
return flag;
}
}
/** Inserts a stack into an inventory. Args: Inventory, stack, side. Returns leftover items. */
public static ItemStack insertStack(IInventory par0IInventory, ItemStack par1ItemStack, int par2)
{
if (par0IInventory instanceof ISidedInventory && par2 > -1)
{
ISidedInventory isidedinventory = (ISidedInventory) par0IInventory;
int[] aint = isidedinventory.getAccessibleSlotsFromSide(par2);
for (int j = 0; j < aint.length && par1ItemStack != null && par1ItemStack.stackSize > 0; ++j)
{
par1ItemStack = func_102014_c(par0IInventory, par1ItemStack, aint[j], par2);
}
}
else
{
int k = par0IInventory.getSizeInventory();
for (int l = 0; l < k && par1ItemStack != null && par1ItemStack.stackSize > 0; ++l)
{
par1ItemStack = func_102014_c(par0IInventory, par1ItemStack, l, par2);
}
}
if (par1ItemStack != null && par1ItemStack.stackSize == 0)
{
par1ItemStack = null;
}
return par1ItemStack;
}
/** Args: inventory, item, slot, side */
private static boolean canInsertItemToInventory(IInventory par0IInventory, ItemStack par1ItemStack, int par2, int par3)
{
return !par0IInventory.isItemValidForSlot(par2, par1ItemStack) ? false : !(par0IInventory instanceof ISidedInventory) || ((ISidedInventory) par0IInventory).canInsertItem(par2, par1ItemStack, par3);
}
private static boolean canExtractItemFromInventory(IInventory par0IInventory, ItemStack par1ItemStack, int par2, int par3)
{
return !(par0IInventory instanceof ISidedInventory) || ((ISidedInventory) par0IInventory).canExtractItem(par2, par1ItemStack, par3);
}
private static ItemStack func_102014_c(IInventory par0IInventory, ItemStack par1ItemStack, int par2, int par3)
{
ItemStack itemstack1 = par0IInventory.getStackInSlot(par2);
if (canInsertItemToInventory(par0IInventory, par1ItemStack, par2, par3))
{
boolean flag = false;
if (itemstack1 == null)
{
int max = Math.min(par1ItemStack.getMaxStackSize(), par0IInventory.getInventoryStackLimit());
if (max >= par1ItemStack.stackSize)
{
par0IInventory.setInventorySlotContents(par2, par1ItemStack);
par1ItemStack = null;
}
else
{
par0IInventory.setInventorySlotContents(par2, par1ItemStack.splitStack(max));
}
flag = true;
}
else if (areItemStacksEqualItem(itemstack1, par1ItemStack))
{
int max = Math.min(par1ItemStack.getMaxStackSize(), par0IInventory.getInventoryStackLimit());
if (max > itemstack1.stackSize)
{
int l = Math.min(par1ItemStack.stackSize, max - itemstack1.stackSize);
par1ItemStack.stackSize -= l;
itemstack1.stackSize += l;
flag = l > 0;
}
}
if (flag)
{
if (par0IInventory instanceof TileEntityAdvancedHopper)
{
((TileEntityAdvancedHopper) par0IInventory).setTransferCooldown(8);
par0IInventory.onInventoryChanged();
}
par0IInventory.onInventoryChanged();
}
}
return par1ItemStack;
}
/** Gets the inventory the hopper is pointing at. */
private IInventory getOutputInventory()
{
int i = BlockAdvancedHopper.getDirectionFromMetadata(this.getBlockMetadata());
return getInventoryAtLocation(this.getWorldObj(), (this.xCoord + Facing.offsetsXForSide[i]), (this.yCoord + Facing.offsetsYForSide[i]), (this.zCoord + Facing.offsetsZForSide[i]));
}
/** Looks for anything, that can hold items (like chests, furnaces, etc.) one block above the
* given hopper. */
public static IInventory getInventoryAboveHopper(Hopper par0Hopper)
{
return getInventoryAtLocation(par0Hopper.getWorldObj(), par0Hopper.getXPos(), par0Hopper.getYPos() + 1.0D, par0Hopper.getZPos());
}
public static EntityItem getEntityAbove(World par0World, double par1, double par3, double par5)
{
List list = par0World.selectEntitiesWithinAABB(EntityItem.class, AxisAlignedBB.getAABBPool().getAABB(par1, par3, par5, par1 + 1.0D, par3 + 1.0D, par5 + 1.0D), IEntitySelector.selectAnything);
return list.size() > 0 ? (EntityItem) list.get(0) : null;
}
/** Gets an inventory at the given location to extract items into or take items from. Can find
* either a tile entity or regular entity implementing IInventory. */
public static IInventory getInventoryAtLocation(World par0World, double par1, double par3, double par5)
{
IInventory iinventory = null;
int i = MathHelper.floor_double(par1);
int j = MathHelper.floor_double(par3);
int k = MathHelper.floor_double(par5);
TileEntity tileentity = par0World.getBlockTileEntity(i, j, k);
if (tileentity != null && tileentity instanceof IInventory)
{
iinventory = (IInventory) tileentity;
if (iinventory instanceof TileEntityChest)
{
int l = par0World.getBlockId(i, j, k);
Block block = Block.blocksList[l];
if (block instanceof BlockChest)
{
iinventory = ((BlockChest) block).getInventory(par0World, i, j, k);
}
}
}
if (iinventory == null)
{
List list = par0World.getEntitiesWithinAABBExcludingEntity((Entity) null, AxisAlignedBB.getAABBPool().getAABB(par1, par3, par5, par1 + 1.0D, par3 + 1.0D, par5 + 1.0D), IEntitySelector.selectInventories);
if (list != null && list.size() > 0)
{
iinventory = (IInventory) list.get(par0World.rand.nextInt(list.size()));
}
}
return iinventory;
}
private static boolean areItemStacksEqualItem(ItemStack par0ItemStack, ItemStack par1ItemStack)
{
return par0ItemStack.itemID != par1ItemStack.itemID ? false : (par0ItemStack.getItemDamage() != par1ItemStack.getItemDamage() ? false : (par0ItemStack.stackSize > par0ItemStack.getMaxStackSize() ? false : ItemStack.areItemStackTagsEqual(par0ItemStack, par1ItemStack)));
}
/** Gets the world X position for this hopper entity. */
@Override
public double getXPos()
{
return this.xCoord;
}
/** Gets the world Y position for this hopper entity. */
@Override
public double getYPos()
{
return this.yCoord;
}
/** Gets the world Z position for this hopper entity. */
@Override
public double getZPos()
{
return this.zCoord;
}
public void setTransferCooldown(int par1)
{
this.transferCooldown = par1;
}
public boolean isCoolingDown()
{
return this.transferCooldown > 0;
return stack.itemID != stack2.itemID ? false : (stack.getItemDamage() != stack2.getItemDamage() ? false : (stack.stackSize > stack.getMaxStackSize() ? false : ItemStack.areItemStackTagsEqual(stack, stack2)));
}
}