New sorter model

This commit is contained in:
Calclavia 2014-03-14 18:03:51 +08:00
parent 3cd1b8759f
commit 3f122cd2dd
6 changed files with 6 additions and 433 deletions

View file

@ -255,13 +255,17 @@ public class TileSorter extends TileInventory
GL11.glRotatef(90, 0, 0, 1);
RenderUtility.rotateBlockBasedOnDirection(dir);
MODEL.renderOnly("port");
if (TileSorter.this.isInverted)
MODEL.renderOnly("portRed", "connector");
else
MODEL.renderOnly("portBlue", "connector");
GL11.glPopMatrix();
}
}
}
MODEL.renderAllExcept("port");
MODEL.renderAllExcept("portBlue", "portRed", "connector");
RenderUtility.disableBlending();
GL11.glPopMatrix();
return true;

View file

@ -1,117 +0,0 @@
package resonantinduction.mechanical.logistic.rail;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.ChatMessageComponent;
import net.minecraft.world.World;
import resonantinduction.core.prefab.imprint.BlockImprintable;
import universalelectricity.api.UniversalElectricity;
import calclavia.lib.render.block.BlockRenderingHandler;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
/**
* A block that manipulates item movement between inventories.
*
* @author Calclavia, DarkGuardsman
*/
public class BlockSorter extends BlockImprintable
{
public BlockSorter(int id)
{
super(id, UniversalElectricity.machine);
this.setBlockBounds(0.01f, 0.01f, 0.01f, 0.09f, 0.09f, 0.09f);
}
@Override
public AxisAlignedBB getSelectedBoundingBoxFromPool(World par1World, int par2, int par3, int par4)
{
return AxisAlignedBB.getAABBPool().getAABB(par2, par3, par4, (double) par2 + 1, (double) par3 + 1, (double) par4 + 1);
}
@Override
public boolean onSneakMachineActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float hitX, float hitY, float hitZ)
{
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
if (tileEntity instanceof TileSorter)
{
if (!world.isRemote)
{
((TileSorter) tileEntity).setSelfPulse(!((TileSorter) tileEntity).isSelfPulse());
entityPlayer.sendChatToPlayer(ChatMessageComponent.createFromText("Manipulator set to " + (((TileSorter) tileEntity).isSelfPulse() ? "auto pulse" : "not pulse")));
}
}
return true;
}
@Override
public boolean onSneakUseWrench(World world, int x, int y, int z, EntityPlayer entityPlayer, int side, float hitX, float hitY, float hitZ)
{
TileEntity tileEntity = world.getBlockTileEntity(x, y, z);
if (tileEntity instanceof TileSorter)
{
TileSorter manip = (TileSorter) tileEntity;
boolean manipMode = manip.isOutput();
boolean inverted = manip.isInverted();
if (manipMode && !inverted)
{
manip.toggleInversion();
}
else if (manipMode && inverted)
{
manip.toggleOutput();
manip.toggleInversion();
}
else if (!manipMode && !inverted)
{
manip.toggleInversion();
}
else
{
manip.toggleOutput();
manip.toggleInversion();
}
if (!world.isRemote)
{
entityPlayer.sendChatToPlayer(ChatMessageComponent.createFromText("Manipulator outputing = " + manip.isOutput()));
}
}
return true;
}
@Override
public TileEntity createNewTileEntity(World var1)
{
return new TileSorter();
}
@SideOnly(Side.CLIENT)
@Override
public int getRenderType()
{
return BlockRenderingHandler.ID;
}
@Override
public boolean isOpaqueCube()
{
return false;
}
@Override
@SideOnly(Side.CLIENT)
public boolean renderAsNormalBlock()
{
return false;
}
@Override
public int damageDropped(int par1)
{
return 0;
}
}

View file

@ -1,62 +0,0 @@
package resonantinduction.mechanical.logistic.rail;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ResourceLocation;
import org.lwjgl.opengl.GL11;
import resonantinduction.core.Reference;
import resonantinduction.core.render.RenderImprintable;
import resonantinduction.mechanical.logistic.belt.ModelManipulator;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class RenderSorter extends RenderImprintable
{
public static final ModelManipulator MODEL = new ModelManipulator();
public static final ResourceLocation TEXTURE_INPUT = new ResourceLocation(Reference.DOMAIN, Reference.MODEL_PATH + "manipulator1.png");
public static final ResourceLocation TEXTURE_OUTPUT = new ResourceLocation(Reference.DOMAIN, Reference.MODEL_PATH + "manipulator2.png");
@Override
public void renderTileEntityAt(TileEntity tileEntity, double x, double y, double z, float var8)
{
TileSorter tile = (TileSorter) tileEntity;
int face = tile.getDirection().ordinal();
GL11.glPushMatrix();
GL11.glTranslatef((float) x + 0.5F, (float) y + 1.5F, (float) z + 0.5F);
GL11.glRotatef(180f, 0f, 0f, 1f);
if (tile.isOutput())
{
bindTexture(TEXTURE_INPUT);
}
else
{
bindTexture(TEXTURE_OUTPUT);
}
if (face == 2)
{
GL11.glRotatef(0f, 0f, 1f, 0f);
}
else if (face == 3)
{
GL11.glRotatef(180f, 0f, 1f, 0f);
}
else if (face == 4)
{
GL11.glRotatef(270f, 0f, 1f, 0f);
}
else if (face == 5)
{
GL11.glRotatef(90f, 0f, 1f, 0f);
}
MODEL.render(0.0625F, true, 0);
GL11.glPopMatrix();
}
}

View file

@ -1,252 +0,0 @@
package resonantinduction.mechanical.logistic.rail;
import java.util.List;
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.network.packet.Packet;
import net.minecraft.util.AxisAlignedBB;
import net.minecraftforge.common.ForgeDirection;
import resonantinduction.core.ResonantInduction;
import resonantinduction.core.prefab.imprint.ItemImprint;
import resonantinduction.core.prefab.imprint.TileFilterable;
import universalelectricity.api.vector.Vector3;
import calclavia.api.resonantinduction.mechanical.IManipulator;
import calclavia.lib.network.IPacketReceiver;
import calclavia.lib.prefab.tile.IRotatable;
import calclavia.lib.utility.inventory.InternalInventoryHandler;
import com.google.common.io.ByteArrayDataInput;
public class TileSorter extends TileFilterable implements IRotatable, IManipulator, IPacketReceiver
{
/** True to auto output items with a redstone pulse */
private boolean selfPulse = false;
/** True if outputting items */
private boolean isOutput = false;
/** True if is currently powered by redstone */
private boolean isRedstonePowered = false;
/** The class that interacts with inventories for this machine */
private InternalInventoryHandler invExtractionHelper;
@Override
public void updateEntity()
{
super.updateEntity();
if (!this.worldObj.isRemote)
{
if (this.isFunctioning())
{
if (!this.isOutput)
{
this.enject();
}
else
{
this.isRedstonePowered = this.worldObj.isBlockIndirectlyGettingPowered(xCoord, yCoord, zCoord);
if (this.isSelfPulse() && this.ticks % 10 == 0)
{
this.isRedstonePowered = true;
}
/** Finds the connected inventory and outputs the items upon a redstone pulse. */
if (this.isRedstonePowered)
{
this.inject();
}
}
}
}
}
/**
* Find items going into the manipulator and input them into an inventory behind this
* manipulator.
*/
@Override
public void enject()
{
Vector3 inputPosition = new Vector3(this);
/** output location up */
Vector3 outputUp = new Vector3(this);
outputUp.translate(ForgeDirection.UP);
/** output location down */
Vector3 outputDown = new Vector3(this);
outputDown.translate(ForgeDirection.DOWN);
/** output location facing */
Vector3 outputPosition = new Vector3(this);
outputPosition.translate(this.getDirection().getOpposite());
/** Prevents manipulators from spamming and duping items. */
if (outputPosition.getTileEntity(this.worldObj) instanceof TileSorter)
{
if (((TileSorter) outputPosition.getTileEntity(this.worldObj)).getDirection() == this.getDirection().getOpposite())
{
return;
}
}
AxisAlignedBB bounds = AxisAlignedBB.getBoundingBox(inputPosition.x, inputPosition.y, inputPosition.z, inputPosition.x + 1, inputPosition.y + 1, inputPosition.z + 1);
List<EntityItem> itemsInBound = this.worldObj.getEntitiesWithinAABB(EntityItem.class, bounds);
for (EntityItem entity : itemsInBound)
{
if (entity.isDead)
continue;
/**
* Try top first, then bottom, then the sides to see if it is possible to insert the
* item into a inventory.
*/
ItemStack remainingStack = entity.getEntityItem().copy();
if (this.getFilter() == null || this.isFiltering(remainingStack))
{
remainingStack = invHelper().tryPlaceInPosition(remainingStack, outputUp, ForgeDirection.UP);
if (remainingStack != null)
{
remainingStack = invHelper().tryPlaceInPosition(remainingStack, outputDown, ForgeDirection.DOWN);
}
if (remainingStack != null)
{
remainingStack = invHelper().tryPlaceInPosition(remainingStack, outputPosition, this.getDirection().getOpposite());
}
if (remainingStack != null && remainingStack.stackSize > 0)
{
invHelper().throwItem(outputPosition, remainingStack);
}
entity.setDead();
}
}
}
/** Inject items */
@Override
public void inject()
{
this.isRedstonePowered = false;
/** input location up */
Vector3 inputUp = new Vector3(this).translate(ForgeDirection.UP);
/** input location down */
Vector3 inputDown = new Vector3(this).translate(ForgeDirection.DOWN);
/** input location facing */
Vector3 inputPosition = new Vector3(this).translate(this.getDirection().getOpposite());
/** output location facing */
Vector3 outputPosition = new Vector3(this).translate(this.getDirection());
ItemStack itemStack = invHelper().tryGrabFromPosition(inputUp, ForgeDirection.UP, 1);
if (itemStack == null)
{
itemStack = invHelper().tryGrabFromPosition(inputDown, ForgeDirection.DOWN, 1);
}
if (itemStack == null)
{
itemStack = invHelper().tryGrabFromPosition(inputPosition, this.getDirection().getOpposite(), 1);
}
if (itemStack != null)
{
if (itemStack.stackSize > 0)
{
invHelper().throwItem(outputPosition, itemStack);
}
}
}
@Override
public void readFromNBT(NBTTagCompound nbt)
{
super.readFromNBT(nbt);
this.isOutput = nbt.getBoolean("isOutput");
this.setSelfPulse(nbt.getBoolean("selfpulse"));
}
/** Writes a tile entity to NBT. */
@Override
public void writeToNBT(NBTTagCompound nbt)
{
super.writeToNBT(nbt);
nbt.setBoolean("isOutput", this.isOutput);
nbt.setBoolean("selfpulse", this.isSelfPulse());
}
@Override
public Packet getDescriptionPacket()
{
return ResonantInduction.PACKET_TILE.getPacket(this, this.isInverted(), this.isSelfPulse(), this.isOutput());
}
@Override
public void onReceivePacket(ByteArrayDataInput data, EntityPlayer player, Object... extra)
{
try
{
this.setInverted(data.readBoolean());
this.setSelfPulse(data.readBoolean());
this.setOutput(data.readBoolean());
}
catch (Exception e)
{
e.printStackTrace();
}
}
public boolean isSelfPulse()
{
return selfPulse;
}
public void setSelfPulse(boolean selfPulse)
{
this.selfPulse = selfPulse;
}
/** Gets the class that managed extracting and placing items into inventories */
public InternalInventoryHandler invHelper()
{
if (invExtractionHelper == null || invExtractionHelper.world != this.worldObj)
{
this.invExtractionHelper = new InternalInventoryHandler(this.worldObj, new Vector3(this), this.getFilter() != null ? ItemImprint.getFilters(getFilter()) : null, this.isInverted());
}
return invExtractionHelper;
}
@Override
public void setFilter(ItemStack filter)
{
super.setFilter(filter);
/* Reset inv Helper's filters */
this.invHelper().setFilter(this.getFilter() != null ? ItemImprint.getFilters(this.getFilter()) : null, this.isInverted());
}
/** Is this manipulator set to output items */
public boolean isOutput()
{
return this.isOutput;
}
/** True to output items */
public void setOutput(boolean isOutput)
{
this.isOutput = isOutput;
if (!this.worldObj.isRemote)
{
this.worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}
}
/** Inverts the current output state */
public void toggleOutput()
{
this.setOutput(!this.isOutput());
}
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 3.5 KiB

After

Width:  |  Height:  |  Size: 2.6 KiB