Patched battery side render
This commit is contained in:
parent
e752bd9ccc
commit
91f402b18f
2 changed files with 214 additions and 187 deletions
|
@ -5,6 +5,7 @@ package resonantinduction.electrical.battery;
|
||||||
|
|
||||||
import static org.lwjgl.opengl.GL11.glPopMatrix;
|
import static org.lwjgl.opengl.GL11.glPopMatrix;
|
||||||
import static org.lwjgl.opengl.GL11.glPushMatrix;
|
import static org.lwjgl.opengl.GL11.glPushMatrix;
|
||||||
|
import static org.lwjgl.opengl.GL11.glRotatef;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
@ -21,14 +22,16 @@ import org.lwjgl.opengl.GL11;
|
||||||
|
|
||||||
import resonant.api.items.ISimpleItemRenderer;
|
import resonant.api.items.ISimpleItemRenderer;
|
||||||
import resonant.lib.render.RenderUtility;
|
import resonant.lib.render.RenderUtility;
|
||||||
|
import resonant.lib.utility.WorldUtility;
|
||||||
import resonantinduction.core.Reference;
|
import resonantinduction.core.Reference;
|
||||||
import universalelectricity.api.vector.Vector3;
|
import universalelectricity.api.vector.Vector3;
|
||||||
import cpw.mods.fml.relauncher.Side;
|
import cpw.mods.fml.relauncher.Side;
|
||||||
import cpw.mods.fml.relauncher.SideOnly;
|
import cpw.mods.fml.relauncher.SideOnly;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author Calclavia
|
* TODO: Make this more efficient.
|
||||||
*
|
*
|
||||||
|
* @author Calclavia
|
||||||
*/
|
*/
|
||||||
@SideOnly(Side.CLIENT)
|
@SideOnly(Side.CLIENT)
|
||||||
public class RenderBattery extends TileEntitySpecialRenderer implements ISimpleItemRenderer
|
public class RenderBattery extends TileEntitySpecialRenderer implements ISimpleItemRenderer
|
||||||
|
@ -83,8 +86,8 @@ public class RenderBattery extends TileEntitySpecialRenderer implements ISimpleI
|
||||||
int energyLevel = (int) Math.round(((double) tile.getEnergyHandler().getEnergy() / (double) TileBattery.getEnergyForTier(tile.getBlockMetadata())) * 8);
|
int energyLevel = (int) Math.round(((double) tile.getEnergyHandler().getEnergy() / (double) TileBattery.getEnergyForTier(tile.getBlockMetadata())) * 8);
|
||||||
RenderUtility.bind(Reference.DOMAIN, Reference.MODEL_PATH + "battery/battery.png");
|
RenderUtility.bind(Reference.DOMAIN, Reference.MODEL_PATH + "battery/battery.png");
|
||||||
|
|
||||||
List<String> disabledParts = new ArrayList<String>();
|
List<String> disabledParts = new ArrayList();
|
||||||
List<String> enabledParts = new ArrayList<String>();
|
List<String> enabledParts = new ArrayList();
|
||||||
|
|
||||||
for (ForgeDirection check : ForgeDirection.VALID_DIRECTIONS)
|
for (ForgeDirection check : ForgeDirection.VALID_DIRECTIONS)
|
||||||
{
|
{
|
||||||
|
@ -128,6 +131,24 @@ public class RenderBattery extends TileEntitySpecialRenderer implements ISimpleI
|
||||||
{
|
{
|
||||||
GL11.glPushMatrix();
|
GL11.glPushMatrix();
|
||||||
RenderUtility.rotateBlockBasedOnDirection(check);
|
RenderUtility.rotateBlockBasedOnDirection(check);
|
||||||
|
|
||||||
|
//TODO: Fix this horrible patch.
|
||||||
|
switch (check)
|
||||||
|
{
|
||||||
|
case NORTH:
|
||||||
|
glRotatef(0, 0, 1, 0);
|
||||||
|
break;
|
||||||
|
case SOUTH:
|
||||||
|
glRotatef(0, 0, 1, 0);
|
||||||
|
break;
|
||||||
|
case WEST:
|
||||||
|
glRotatef(-180, 0, 1, 0);
|
||||||
|
break;
|
||||||
|
case EAST:
|
||||||
|
glRotatef(180, 0, 1, 0);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
GL11.glRotatef(-90, 0, 1, 0);
|
GL11.glRotatef(-90, 0, 1, 0);
|
||||||
|
|
||||||
int io = tile.getIO(check);
|
int io = tile.getIO(check);
|
||||||
|
|
|
@ -21,216 +21,222 @@ import resonantinduction.mechanical.energy.grid.MechanicalNode;
|
||||||
import resonantinduction.mechanical.energy.grid.TileMechanical;
|
import resonantinduction.mechanical.energy.grid.TileMechanical;
|
||||||
import universalelectricity.api.vector.Vector3;
|
import universalelectricity.api.vector.Vector3;
|
||||||
|
|
||||||
/** @author Calclavia */
|
/**
|
||||||
|
* @author Calclavia
|
||||||
|
*/
|
||||||
public class TileGrindingWheel extends TileMechanical implements IRotatable
|
public class TileGrindingWheel extends TileMechanical implements IRotatable
|
||||||
{
|
{
|
||||||
public static final int PROCESS_TIME = 20 * 20;
|
public static final int PROCESS_TIME = 20 * 20;
|
||||||
/** A map of ItemStacks and their remaining grind-time left. */
|
/**
|
||||||
public static final Timer<EntityItem> timer = new Timer<EntityItem>();
|
* A map of ItemStacks and their remaining grind-time left.
|
||||||
|
*/
|
||||||
|
public static final Timer<EntityItem> timer = new Timer();
|
||||||
|
|
||||||
public EntityItem grindingItem = null;
|
public EntityItem grindingItem = null;
|
||||||
|
|
||||||
private final long requiredTorque = 250;
|
private final long requiredTorque = 250;
|
||||||
private double counter = 0;
|
private double counter = 0;
|
||||||
|
|
||||||
public TileGrindingWheel()
|
public TileGrindingWheel()
|
||||||
{
|
{
|
||||||
super(Material.rock);
|
super(Material.rock);
|
||||||
mechanicalNode = new GrinderNode(this).setLoad(2);
|
mechanicalNode = new GrinderNode(this).setLoad(2);
|
||||||
bounds = new Cuboid(0.05f, 0.05f, 0.05f, 0.95f, 0.95f, 0.95f);
|
bounds = new Cuboid(0.05f, 0.05f, 0.05f, 0.95f, 0.95f, 0.95f);
|
||||||
isOpaqueCube = false;
|
isOpaqueCube = false;
|
||||||
normalRender = false;
|
normalRender = false;
|
||||||
customItemRender = true;
|
customItemRender = true;
|
||||||
rotationMask = Byte.parseByte("111111", 2);
|
rotationMask = Byte.parseByte("111111", 2);
|
||||||
textureName = "material_steel_dark";
|
textureName = "material_steel_dark";
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void updateEntity()
|
public void updateEntity()
|
||||||
{
|
{
|
||||||
super.updateEntity();
|
super.updateEntity();
|
||||||
counter = Math.max(counter + Math.abs(mechanicalNode.torque), 0);
|
counter = Math.max(counter + Math.abs(mechanicalNode.torque), 0);
|
||||||
doWork();
|
doWork();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void collide(Entity entity)
|
public void collide(Entity entity)
|
||||||
{
|
{
|
||||||
if (entity instanceof EntityItem)
|
if (entity instanceof EntityItem)
|
||||||
{
|
{
|
||||||
((EntityItem) entity).age--;
|
((EntityItem) entity).age--;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (canWork())
|
if (canWork())
|
||||||
{
|
{
|
||||||
if (entity instanceof EntityItem)
|
if (entity instanceof EntityItem)
|
||||||
{
|
{
|
||||||
if (canGrind(((EntityItem) entity).getEntityItem()))
|
if (canGrind(((EntityItem) entity).getEntityItem()))
|
||||||
{
|
{
|
||||||
if (grindingItem == null)
|
if (grindingItem == null)
|
||||||
{
|
{
|
||||||
grindingItem = (EntityItem) entity;
|
grindingItem = (EntityItem) entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!TileGrindingWheel.timer.containsKey((EntityItem) entity))
|
if (!TileGrindingWheel.timer.containsKey((EntityItem) entity))
|
||||||
{
|
{
|
||||||
TileGrindingWheel.timer.put((EntityItem) entity, TileGrindingWheel.PROCESS_TIME);
|
TileGrindingWheel.timer.put((EntityItem) entity, TileGrindingWheel.PROCESS_TIME);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
entity.setPosition(entity.posX, entity.posY - 1.2, entity.posZ);
|
entity.setPosition(entity.posX, entity.posY - 1.2, entity.posZ);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
entity.attackEntityFrom(new CustomDamageSource("grinder", this), 2);
|
entity.attackEntityFrom(new CustomDamageSource("grinder", this), 2);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
if (mechanicalNode.getAngularSpeed() != 0)
|
if (mechanicalNode.getAngularSpeed() != 0)
|
||||||
{
|
{
|
||||||
// Move entity based on the direction of the block.
|
// Move entity based on the direction of the block.
|
||||||
ForgeDirection dir = getDirection();
|
ForgeDirection dir = getDirection();
|
||||||
dir = ForgeDirection.getOrientation(!(dir.ordinal() % 2 == 0) ? dir.ordinal() - 1 : dir.ordinal()).getOpposite();
|
dir = ForgeDirection.getOrientation(!(dir.ordinal() % 2 == 0) ? dir.ordinal() - 1 : dir.ordinal()).getOpposite();
|
||||||
double speed = mechanicalNode.getAngularSpeed() / 20;
|
double speed = mechanicalNode.getAngularSpeed() / 20;
|
||||||
double speedX = dir.offsetX * speed;
|
double speedX = dir.offsetX * speed;
|
||||||
double speedZ = dir.offsetZ * speed;
|
double speedZ = dir.offsetZ * speed;
|
||||||
double speedY = Math.random() * speed;
|
double speedY = Math.random() * speed;
|
||||||
if(Math.abs(speedX) > 1)
|
if (Math.abs(speedX) > 1)
|
||||||
{
|
{
|
||||||
speedX = speedX > 0 ? 1 : -1;
|
speedX = speedX > 0 ? 1 : -1;
|
||||||
}
|
}
|
||||||
if(Math.abs(speedZ) > 1)
|
if (Math.abs(speedZ) > 1)
|
||||||
{
|
{
|
||||||
speedZ = speedZ > 0 ? 1 : -1;
|
speedZ = speedZ > 0 ? 1 : -1;
|
||||||
}
|
}
|
||||||
if(Math.abs(speedZ) > 1)
|
if (Math.abs(speedZ) > 1)
|
||||||
{
|
{
|
||||||
speedY = speedY > 0 ? 1 : -1;
|
speedY = speedY > 0 ? 1 : -1;
|
||||||
}
|
}
|
||||||
entity.addVelocity(speedX, speedY, speedZ);
|
entity.addVelocity(speedX, speedY, speedZ);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Can this machine work this tick?
|
/**
|
||||||
*
|
* Can this machine work this tick?
|
||||||
* @return */
|
*
|
||||||
public boolean canWork()
|
* @return
|
||||||
{
|
*/
|
||||||
return counter >= requiredTorque;
|
public boolean canWork()
|
||||||
}
|
{
|
||||||
|
return counter >= requiredTorque;
|
||||||
|
}
|
||||||
|
|
||||||
public void doWork()
|
public void doWork()
|
||||||
{
|
{
|
||||||
if (canWork())
|
if (canWork())
|
||||||
{
|
{
|
||||||
boolean didWork = false;
|
boolean didWork = false;
|
||||||
|
|
||||||
if (grindingItem != null)
|
if (grindingItem != null)
|
||||||
{
|
{
|
||||||
if (timer.containsKey(grindingItem) && !grindingItem.isDead && new Vector3(this).add(0.5).distance(grindingItem) < 1)
|
if (timer.containsKey(grindingItem) && !grindingItem.isDead && new Vector3(this).add(0.5).distance(grindingItem) < 1)
|
||||||
{
|
{
|
||||||
int timeLeft = timer.decrease(grindingItem);
|
int timeLeft = timer.decrease(grindingItem);
|
||||||
|
|
||||||
if (timeLeft <= 0)
|
if (timeLeft <= 0)
|
||||||
{
|
{
|
||||||
if (this.doGrind(grindingItem))
|
if (this.doGrind(grindingItem))
|
||||||
{
|
{
|
||||||
if (--grindingItem.getEntityItem().stackSize <= 0)
|
if (--grindingItem.getEntityItem().stackSize <= 0)
|
||||||
{
|
{
|
||||||
grindingItem.setDead();
|
grindingItem.setDead();
|
||||||
timer.remove(grindingItem);
|
timer.remove(grindingItem);
|
||||||
grindingItem = null;
|
grindingItem = null;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
grindingItem.setEntityItemStack(grindingItem.getEntityItem());
|
grindingItem.setEntityItemStack(grindingItem.getEntityItem());
|
||||||
// Reset timer
|
// Reset timer
|
||||||
timer.put(grindingItem, PROCESS_TIME);
|
timer.put(grindingItem, PROCESS_TIME);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
grindingItem.delayBeforeCanPickup = 20;
|
grindingItem.delayBeforeCanPickup = 20;
|
||||||
|
|
||||||
if (grindingItem.getEntityItem().getItem() instanceof ItemBlock)
|
if (grindingItem.getEntityItem().getItem() instanceof ItemBlock)
|
||||||
{
|
{
|
||||||
ResonantInduction.proxy.renderBlockParticle(worldObj, new Vector3(grindingItem), new Vector3((Math.random() - 0.5f) * 3, (Math.random() - 0.5f) * 3, (Math.random() - 0.5f) * 3), ((ItemBlock) grindingItem.getEntityItem().getItem()).getBlockID(), 1);
|
ResonantInduction.proxy.renderBlockParticle(worldObj, new Vector3(grindingItem), new Vector3((Math.random() - 0.5f) * 3, (Math.random() - 0.5f) * 3, (Math.random() - 0.5f) * 3), ((ItemBlock) grindingItem.getEntityItem().getItem()).getBlockID(), 1);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
worldObj.spawnParticle("crit", grindingItem.posX, grindingItem.posY, grindingItem.posZ, (Math.random() - 0.5f) * 3, (Math.random() - 0.5f) * 3, (Math.random() - 0.5f) * 3);
|
worldObj.spawnParticle("crit", grindingItem.posX, grindingItem.posY, grindingItem.posZ, (Math.random() - 0.5f) * 3, (Math.random() - 0.5f) * 3, (Math.random() - 0.5f) * 3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
didWork = true;
|
didWork = true;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
timer.remove(grindingItem);
|
timer.remove(grindingItem);
|
||||||
grindingItem = null;
|
grindingItem = null;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (didWork)
|
if (didWork)
|
||||||
{
|
{
|
||||||
if (this.ticks % 8 == 0)
|
if (this.ticks % 8 == 0)
|
||||||
{
|
{
|
||||||
worldObj.playSoundEffect(this.xCoord + 0.5, this.yCoord + 0.5, this.zCoord + 0.5, Reference.PREFIX + "grinder", 0.5f, 1);
|
worldObj.playSoundEffect(this.xCoord + 0.5, this.yCoord + 0.5, this.zCoord + 0.5, Reference.PREFIX + "grinder", 0.5f, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
counter -= requiredTorque;
|
counter -= requiredTorque;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public boolean canGrind(ItemStack itemStack)
|
public boolean canGrind(ItemStack itemStack)
|
||||||
{
|
{
|
||||||
return MachineRecipes.INSTANCE.getOutput(RecipeType.GRINDER.name(), itemStack).length > 0;
|
return MachineRecipes.INSTANCE.getOutput(RecipeType.GRINDER.name(), itemStack).length > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean doGrind(EntityItem entity)
|
private boolean doGrind(EntityItem entity)
|
||||||
{
|
{
|
||||||
ItemStack itemStack = entity.getEntityItem();
|
ItemStack itemStack = entity.getEntityItem();
|
||||||
|
|
||||||
RecipeResource[] results = MachineRecipes.INSTANCE.getOutput(RecipeType.GRINDER.name(), itemStack);
|
RecipeResource[] results = MachineRecipes.INSTANCE.getOutput(RecipeType.GRINDER.name(), itemStack);
|
||||||
|
|
||||||
for (RecipeResource resource : results)
|
for (RecipeResource resource : results)
|
||||||
{
|
{
|
||||||
ItemStack outputStack = resource.getItemStack();
|
ItemStack outputStack = resource.getItemStack();
|
||||||
|
|
||||||
if (!this.worldObj.isRemote)
|
if (!this.worldObj.isRemote)
|
||||||
{
|
{
|
||||||
EntityItem entityItem = new EntityItem(this.worldObj, entity.posX, entity.posY - 1.2, entity.posZ, outputStack);
|
EntityItem entityItem = new EntityItem(this.worldObj, entity.posX, entity.posY - 1.2, entity.posZ, outputStack);
|
||||||
entityItem.delayBeforeCanPickup = 20;
|
entityItem.delayBeforeCanPickup = 20;
|
||||||
entityItem.motionX = 0;
|
entityItem.motionX = 0;
|
||||||
entityItem.motionY = 0;
|
entityItem.motionY = 0;
|
||||||
entityItem.motionZ = 0;
|
entityItem.motionZ = 0;
|
||||||
this.worldObj.spawnEntityInWorld(entityItem);
|
this.worldObj.spawnEntityInWorld(entityItem);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return results.length > 0;
|
return results.length > 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ForgeDirection getDirection()
|
public ForgeDirection getDirection()
|
||||||
{
|
{
|
||||||
if (worldObj != null)
|
if (worldObj != null)
|
||||||
{
|
{
|
||||||
return ForgeDirection.getOrientation(getBlockMetadata());
|
return ForgeDirection.getOrientation(getBlockMetadata());
|
||||||
}
|
}
|
||||||
|
|
||||||
return ForgeDirection.UNKNOWN;
|
return ForgeDirection.UNKNOWN;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void setDirection(ForgeDirection direction)
|
public void setDirection(ForgeDirection direction)
|
||||||
{
|
{
|
||||||
worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, direction.ordinal(), 3);
|
worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, direction.ordinal(), 3);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue