Made detectors use filters

This commit is contained in:
Henry Mao 2012-12-27 18:04:46 +08:00
parent e88d2d9ee3
commit 91d48f4628
13 changed files with 138 additions and 304 deletions

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.1 KiB

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

View file

@ -1,7 +1,5 @@
package assemblyline.api;
import net.minecraft.item.ItemStack;
import universalelectricity.core.vector.Vector3;
/**
* Interface applied to the manipulator.

View file

@ -6,13 +6,11 @@ import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.client.MinecraftForgeClient;
import universalelectricity.core.vector.Vector3;
import assemblyline.client.gui.GuiDetector;
import assemblyline.client.gui.GuiRejector;
import assemblyline.client.gui.GuiStamper;
import assemblyline.client.render.BlockRenderingHandler;
import assemblyline.client.render.RenderConveyorBelt;
import assemblyline.client.render.RenderCrate;
import assemblyline.client.render.RenderDetector;
import assemblyline.client.render.RenderManipulator;
import assemblyline.client.render.RenderSorter;
import assemblyline.common.AssemblyLine;
@ -21,7 +19,6 @@ import assemblyline.common.block.TileEntityCrate;
import assemblyline.common.machine.TileEntityManipulator;
import assemblyline.common.machine.TileEntityRejector;
import assemblyline.common.machine.belt.TileEntityConveyorBelt;
import assemblyline.common.machine.detector.TileEntityDetector;
import cpw.mods.fml.client.registry.ClientRegistry;
import cpw.mods.fml.client.registry.RenderingRegistry;
@ -56,8 +53,6 @@ public class ClientProxy extends CommonProxy
return new GuiRejector(player.inventory, ((TileEntityRejector) tileEntity));
case GUI_STAMPER:
return new GuiStamper(player.inventory, world, new Vector3(x, y, z));
case GUI_DETECTOR:
return new GuiDetector(player.inventory, ((TileEntityDetector) tileEntity));
}
return null;

View file

@ -1,54 +0,0 @@
package assemblyline.client.gui;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.util.StatCollector;
import org.lwjgl.opengl.GL11;
import assemblyline.common.machine.detector.ContainerDetector;
import assemblyline.common.machine.detector.TileEntityDetector;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
/**
* @author Briman0094
*/
@SideOnly(Side.CLIENT)
public class GuiDetector extends GuiContainer
{
private TileEntityDetector tileEntity;
public GuiDetector(InventoryPlayer inventory, TileEntityDetector tileEntity)
{
super(new ContainerDetector(inventory, tileEntity));
this.tileEntity = tileEntity;
this.allowUserInput = false;
short baseHeight = 222;
int var4 = baseHeight - 108;
this.ySize = var4 + 3 * 18;
}
/**
* Draw the foreground layer for the GuiContainer (everything in front of the items)
*/
protected void drawGuiContainerForegroundLayer(int par1, int par2)
{
fontRenderer.drawString(this.tileEntity.getInvName(), 8, 6, 4210752);
fontRenderer.drawString(StatCollector.translateToLocal("container.inventory"), 8, ySize - 96 + 2, 4210752);
}
/**
* Draw the background layer for the GuiContainer (everything behind the items)
*/
protected void drawGuiContainerBackgroundLayer(float par1, int par2, int par3)
{
int var4 = this.mc.renderEngine.getTexture("/gui/container.png");
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
this.mc.renderEngine.bindTexture(var4);
int var5 = (this.width - this.xSize) / 2;
int var6 = (this.height - this.ySize) / 2;
this.drawTexturedModalRect(var5, var6, 0, 0, this.xSize, 3 * 18 + 17);
this.drawTexturedModalRect(var5, var6 + 3 * 18 + 17, 0, 126, this.xSize, 96);
}
}

View file

@ -9,7 +9,6 @@ import assemblyline.common.machine.ContainerRejector;
import assemblyline.common.machine.TileEntityManipulator;
import assemblyline.common.machine.TileEntityRejector;
import assemblyline.common.machine.belt.TileEntityConveyorBelt;
import assemblyline.common.machine.detector.ContainerDetector;
import assemblyline.common.machine.detector.TileEntityDetector;
import assemblyline.common.machine.filter.ContainerStamper;
import cpw.mods.fml.common.network.IGuiHandler;
@ -20,7 +19,6 @@ public class CommonProxy implements IGuiHandler
public static final int GUI_REJECTOR = 0;
public static final int GUI_STAMPER = 1;
public static final int GUI_ARCHITECHT_TABLE = 2;
public static final int GUI_DETECTOR = 3;
public void preInit()
{
@ -47,9 +45,6 @@ public class CommonProxy implements IGuiHandler
return new ContainerRejector(player.inventory, ((TileEntityRejector) tileEntity));
case GUI_STAMPER:
return new ContainerStamper(player.inventory, world, new Vector3(x, y, z));
case GUI_DETECTOR:
return new ContainerDetector(player.inventory, ((TileEntityDetector) tileEntity));
}
return null;

View file

@ -1,6 +1,5 @@
package assemblyline.common.block;
import net.minecraft.client.gui.GuiScreen;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;

View file

@ -1,36 +1,24 @@
package assemblyline.common.machine.detector;
import java.util.Random;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.common.ForgeDirection;
import universalelectricity.core.UniversalElectricity;
import universalelectricity.prefab.BlockMachine;
import universalelectricity.prefab.UETab;
import assemblyline.client.ClientProxy;
import assemblyline.client.render.BlockRenderingHandler;
import assemblyline.common.AssemblyLine;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
/**
* @author Briman0094
*/
public class BlockDetector extends BlockMachine
public class BlockDetector extends BlockFilterable
{
private Random random = new Random();
public BlockDetector(int blockID, int texture)
{
super("detector", blockID, UniversalElectricity.machine, UETab.INSTANCE);
this.blockIndexInTexture = texture;
this.setTextureFile(AssemblyLine.BLOCK_TEXTURE_PATH);
}
@Override
@ -64,23 +52,6 @@ public class BlockDetector extends BlockMachine
return this.blockIndexInTexture;
}
@Override
public boolean onMachineActivated(World world, int x, int y, int z, EntityPlayer player, int par6, float par7, float par8, float par9)
{
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
if (tileEntity != null)
{
if (tileEntity instanceof TileEntityDetector)
{
player.openGui(AssemblyLine.instance, ClientProxy.GUI_DETECTOR, world, x, y, z);
return true;
}
}
return false;
}
@Override
public boolean onSneakUseWrench(World world, int x, int y, int z, EntityPlayer par5EntityPlayer, int side, float hitX, float hitY, float hitZ)
{
@ -91,57 +62,13 @@ public class BlockDetector extends BlockMachine
if (tileEntity instanceof TileEntityDetector)
{
((TileEntityDetector) tileEntity).toggleInversion();
world.markBlockForRenderUpdate(x, y, z);
}
}
return true;
}
@Override
public void breakBlock(World world, int x, int y, int z, int int1, int int2)
{
TileEntityDetector te = (TileEntityDetector) world.getBlockTileEntity(x, y, z);
if (te != null)
{
for (int i = 0; i < te.getSizeInventory(); ++i)
{
ItemStack stack = te.getStackInSlot(i);
if (stack != null)
{
float xShift = this.random.nextFloat() * 0.8F + 0.1F;
float yShift = this.random.nextFloat() * 0.8F + 0.1F;
EntityItem eI;
for (float zShift = this.random.nextFloat() * 0.8F + 0.1F; stack.stackSize > 0; world.spawnEntityInWorld(eI))
{
int count = this.random.nextInt(21) + 10;
if (count > stack.stackSize)
{
count = stack.stackSize;
}
stack.stackSize -= count;
eI = new EntityItem(world, (double) ((float) x + xShift), (double) ((float) y + yShift), (double) ((float) z + zShift), new ItemStack(stack.itemID, count, stack.getItemDamage()));
float var15 = 0.05F;
eI.motionX = (double) ((float) this.random.nextGaussian() * var15);
eI.motionY = (double) ((float) this.random.nextGaussian() * var15 + 0.2F);
eI.motionZ = (double) ((float) this.random.nextGaussian() * var15);
if (stack.hasTagCompound())
{
eI.func_92014_d().setTagCompound((NBTTagCompound) stack.getTagCompound().copy());
}
}
}
}
}
super.breakBlock(world, x, y, z, int1, int2);
}
@Override
public void onNeighborBlockChange(World world, int x, int y, int z, int blockID)
{

View file

@ -0,0 +1,70 @@
package assemblyline.common.machine.detector;
import net.minecraft.block.material.Material;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import universalelectricity.prefab.BlockMachine;
import assemblyline.common.machine.filter.ItemFilter;
/**
* Extend this block class if a filter is allowed to be placed inside of this block.
*
* @author Calclavia
*/
public abstract class BlockFilterable extends BlockMachine
{
public BlockFilterable(String name, int id, Material material, CreativeTabs creativeTab)
{
super(name, id, material, creativeTab);
}
/**
* Allows filters to be placed inside of this block.
*/
@Override
public boolean onMachineActivated(World world, int x, int y, int z, EntityPlayer player, int par6, float par7, float par8, float par9)
{
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
if (tileEntity != null)
{
if (tileEntity instanceof TileEntityDetector)
{
ItemStack containingStack = ((TileEntityDetector) tileEntity).getStackInSlot(0);
if (containingStack != null)
{
if (!world.isRemote)
{
EntityItem dropStack = new EntityItem(world, player.posX, player.posY, player.posZ, containingStack);
dropStack.delayBeforeCanPickup = 0;
world.spawnEntityInWorld(dropStack);
}
((TileEntityDetector) tileEntity).setInventorySlotContents(0, null);
return true;
}
else
{
if (player.getCurrentEquippedItem() != null)
{
if (player.getCurrentEquippedItem().getItem() instanceof ItemFilter)
{
((TileEntityDetector) tileEntity).setInventorySlotContents(0, player.getCurrentEquippedItem());
player.inventory.setInventorySlotContents(player.inventory.currentItem, null);
return true;
}
}
}
}
}
return false;
}
}

View file

@ -1,79 +0,0 @@
package assemblyline.common.machine.detector;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
public class ContainerDetector extends Container
{
protected TileEntityDetector tileEntity;
private int numRows = 3;
public ContainerDetector(InventoryPlayer inventoryPlayer, TileEntityDetector tileEntity)
{
this.tileEntity = tileEntity;
int var3 = (numRows - 4) * 18;
int x;
int y;
for (x = 0; x < numRows; ++x)
{
for (y = 0; y < 9; ++y)
{
this.addSlotToContainer(new Slot(tileEntity, y + x * 9, 8 + y * 18, 18 + x * 18));
}
}
for (x = 0; x < 3; ++x)
{
for (y = 0; y < 9; ++y)
{
this.addSlotToContainer(new Slot(inventoryPlayer, y + x * 9 + 9, 8 + y * 18, 103 + x * 18 + var3));
}
}
for (x = 0; x < 9; ++x)
{
this.addSlotToContainer(new Slot(inventoryPlayer, x, 8 + x * 18, 161 + var3));
}
}
@Override
public ItemStack transferStackInSlot(EntityPlayer par1EntityPlayer, int par2)
{
ItemStack var3 = null;
Slot var4 = (Slot) this.inventorySlots.get(par2);
if (var4 != null && var4.getHasStack())
{
ItemStack var5 = var4.getStack();
var3 = var5.copy();
if (par2 < this.numRows * 9)
{
if (!this.mergeItemStack(var5, this.numRows * 9, this.inventorySlots.size(), true)) { return null; }
}
else if (!this.mergeItemStack(var5, 0, this.numRows * 9, false)) { return null; }
if (var5.stackSize == 0)
{
var4.putStack((ItemStack) null);
}
else
{
var4.onSlotChanged();
}
}
return var3;
}
@Override
public boolean canInteractWith(EntityPlayer player)
{
return tileEntity.isUseableByPlayer(player);
}
}

View file

@ -2,11 +2,6 @@ package assemblyline.common.machine.detector;
import java.util.ArrayList;
import com.google.common.io.ByteArrayDataInput;
import cpw.mods.fml.common.network.IPacketHandler;
import cpw.mods.fml.common.network.Player;
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
@ -16,47 +11,55 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.network.INetworkManager;
import net.minecraft.network.packet.Packet;
import net.minecraft.network.packet.Packet132TileEntityData;
import net.minecraft.network.packet.Packet250CustomPayload;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraftforge.common.ForgeDirection;
import universalelectricity.prefab.TranslationHelper;
import universalelectricity.prefab.implement.IRedstoneProvider;
import universalelectricity.prefab.network.IPacketReceiver;
import universalelectricity.prefab.network.PacketManager;
import universalelectricity.prefab.tile.TileEntityAdvanced;
import assemblyline.common.AssemblyLine;
import assemblyline.common.machine.filter.ItemFilter;
public class TileEntityDetector extends TileEntity implements IInventory, IRedstoneProvider, IPacketReceiver
import com.google.common.io.ByteArrayDataInput;
public class TileEntityDetector extends TileEntityAdvanced implements IInventory, IRedstoneProvider, IPacketReceiver
{
private boolean powering = false;
private boolean isInverted = false;
private ItemStack[] containingItems = new ItemStack[27];
private ItemStack[] containingItems = new ItemStack[1];
@Override
public void updateEntity()
{
int metadata = this.worldObj.getBlockMetadata(xCoord, yCoord, zCoord) & 3;
AxisAlignedBB testArea = AxisAlignedBB.getBoundingBox(this.xCoord, this.yCoord - 1, this.yCoord, this.xCoord + 1, this.yCoord, this.zCoord + 1);
super.updateEntity();
ArrayList<Entity> entities = (ArrayList<Entity>) this.worldObj.getEntitiesWithinAABB(EntityItem.class, testArea);
boolean powerCheck = false;
if (entities.size() > 0)
if (!this.worldObj.isRemote && this.ticks % 10 == 0)
{
if (hasItems())
{
for (int i = 0; i < entities.size(); i++)
{
EntityItem e = (EntityItem) entities.get(i);
ItemStack item = e.func_92014_d();
boolean tFound = false;
int metadata = this.worldObj.getBlockMetadata(this.xCoord, this.yCoord, this.zCoord);
AxisAlignedBB testArea = AxisAlignedBB.getBoundingBox(this.xCoord, this.yCoord - 1, this.yCoord, this.xCoord + 1, this.yCoord, this.zCoord + 1);
for (int ii = 0; ii < this.containingItems.length; ii++)
ArrayList<Entity> entities = (ArrayList<Entity>) this.worldObj.getEntitiesWithinAABB(EntityItem.class, testArea);
boolean powerCheck = false;
if (entities.size() > 0)
{
if (this.containingItems[0] != null)
{
for (int i = 0; i < entities.size(); i++)
{
ItemStack compare = this.containingItems[ii];
if (compare != null)
EntityItem e = (EntityItem) entities.get(i);
ItemStack item = e.func_92014_d();
boolean found = false;
ArrayList<ItemStack> checkStacks = ItemFilter.getFilters(this.containingItems[0]);
for (int ii = 0; ii < checkStacks.size(); ii++)
{
if (this.isInverted)
ItemStack compare = checkStacks.get(ii);
if (compare != null)
{
if (item.itemID == compare.itemID)
{
@ -66,84 +69,65 @@ public class TileEntityDetector extends TileEntity implements IInventory, IRedst
{
if (item.getTagCompound().equals(compare.getTagCompound()))
{
tFound = true;
found = true;
break;
}
}
else
{
tFound = true;
break;
}
}
}
}
else
{
if (item.itemID == compare.itemID)
{
if (item.getItemDamage() == compare.getItemDamage())
{
if (item.hasTagCompound())
{
if (item.getTagCompound().equals(compare.getTagCompound()))
{
powerCheck = true;
break;
}
}
else
{
powerCheck = true;
found = true;
break;
}
}
}
}
}
}
if (this.isInverted)
{
if (!tFound)
if (this.isInverted)
{
if (!found)
{
powerCheck = true;
break;
}
}
else if (found)
{
powerCheck = true;
break;
}
}
}
else
{
powerCheck = true;
}
}
else
{
powerCheck = true;
powerCheck = false;
}
}
else
{
powerCheck = false;
}
if (powerCheck != this.powering)
{
this.powering = powerCheck;
this.worldObj.notifyBlocksOfNeighborChange(this.xCoord, this.yCoord, this.zCoord, AssemblyLine.blockDetector.blockID);
this.worldObj.notifyBlocksOfNeighborChange(this.xCoord, this.yCoord + 1, this.zCoord, AssemblyLine.blockDetector.blockID);
for (int x = this.xCoord - 1; x <= this.xCoord + 1; x++)
if (powerCheck != this.powering)
{
for (int z = this.zCoord - 1; z <= this.zCoord + 1; z++)
this.powering = powerCheck;
this.worldObj.notifyBlocksOfNeighborChange(this.xCoord, this.yCoord, this.zCoord, AssemblyLine.blockDetector.blockID);
this.worldObj.notifyBlocksOfNeighborChange(this.xCoord, this.yCoord + 1, this.zCoord, AssemblyLine.blockDetector.blockID);
for (int x = this.xCoord - 1; x <= this.xCoord + 1; x++)
{
this.worldObj.notifyBlocksOfNeighborChange(x, this.yCoord + 1, z, AssemblyLine.blockDetector.blockID);
for (int z = this.zCoord - 1; z <= this.zCoord + 1; z++)
{
this.worldObj.notifyBlocksOfNeighborChange(x, this.yCoord + 1, z, AssemblyLine.blockDetector.blockID);
}
}
}
}
}
public boolean hasItems()
@Override
public void invalidate()
{
for (int i = 0; i < this.containingItems.length; i++)
{
if (this.containingItems[i] != null) { return true; }
}
return false;
this.worldObj.notifyBlocksOfNeighborChange(this.xCoord, this.yCoord + 1, this.zCoord, AssemblyLine.blockDetector.blockID);
super.invalidate();
}
public boolean isInverted()
@ -233,7 +217,7 @@ public class TileEntityDetector extends TileEntity implements IInventory, IRedst
@Override
public int getSizeInventory()
{
return 27;
return this.containingItems.length;
}
@Override
@ -312,7 +296,7 @@ public class TileEntityDetector extends TileEntity implements IInventory, IRedst
@Override
public int getInventoryStackLimit()
{
return 64;
return 1;
}
@Override

View file

@ -1,6 +1,5 @@
package assemblyline.common.machine.filter;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.world.World;
@ -14,9 +13,10 @@ public class BlockStamper extends BlockMachine
public BlockStamper(int id, int texture)
{
super(id, Material.wood);
this.blockIndexInTexture = 59;
this.blockIndexInTexture = 0;
this.setBlockName("stamper");
this.setCreativeTab(UETab.INSTANCE);
this.setTextureFile(AssemblyLine.BLOCK_TEXTURE_PATH);
}
/**
@ -24,7 +24,7 @@ public class BlockStamper extends BlockMachine
*/
public int getBlockTextureFromSide(int par1)
{
return Block.blockSteel.blockIndexInTexture;
return this.blockIndexInTexture;
}
/**

View file

@ -1,10 +1,9 @@
package assemblyline.common.machine.filter;
import assemblyline.common.AssemblyLine;
import net.minecraft.inventory.IInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import assemblyline.common.AssemblyLine;
public class SlotFilter extends Slot
{