use of com.Da_Technomancer.crossroads.API.rotary.IAxleHandler in project Crossroads by Crossroads-Development.
the class FatCongealerTileEntity method update.
@Override
public void update() {
if (world.isRemote) {
return;
}
if (world.getTileEntity(pos.offset(EnumFacing.UP)) != null && world.getTileEntity(pos.offset(EnumFacing.UP)).hasCapability(Capabilities.AXLE_HANDLER_CAPABILITY, EnumFacing.DOWN)) {
IAxleHandler rot = world.getTileEntity(pos.offset(EnumFacing.UP)).getCapability(Capabilities.AXLE_HANDLER_CAPABILITY, EnumFacing.DOWN);
int value = Math.min((int) (Math.abs(rot.getMotionData()[1]) * VALUE_PER_ENERGY), 40);
if (value == 0 || content == null) {
return;
}
int sat = (int) (((double) value) * MiscOp.findEfficiency(rot.getMotionData()[0], 0, SAT_UPPER_SPEED_BOUND));
sat = Math.min(20, sat);
value = Math.min(value, 20 + sat);
if (value * EnergyConverters.FAT_PER_VALUE > content.amount) {
return;
}
rot.addEnergy(-1, false, false);
if ((content.amount -= value * EnergyConverters.FAT_PER_VALUE) <= 0) {
content = null;
}
ItemStack stack = new ItemStack(ModItems.edibleBlob, 1, 0);
NBTTagCompound nbt = new NBTTagCompound();
nbt.setInteger("food", value - sat);
nbt.setInteger("sat", sat);
stack.setTagCompound(nbt);
EntityItem ent = new EntityItem(world, pos.getX() + .5D, pos.getY() - .5D, pos.getZ() + .5D, stack);
ent.motionX = 0;
ent.motionZ = 0;
world.spawnEntity(ent);
markDirty();
}
}
use of com.Da_Technomancer.crossroads.API.rotary.IAxleHandler in project Crossroads by Crossroads-Development.
the class FatFeederTileEntity method update.
@Override
public void update() {
if (world.isRemote) {
return;
}
IAxleHandler upAxle = world.getTileEntity(pos.offset(EnumFacing.UP)) != null ? world.getTileEntity(pos.offset(EnumFacing.UP)).getCapability(Capabilities.AXLE_HANDLER_CAPABILITY, EnumFacing.DOWN) : null;
IAxleHandler downAxle = world.getTileEntity(pos.offset(EnumFacing.DOWN)) != null ? world.getTileEntity(pos.offset(EnumFacing.DOWN)).getCapability(Capabilities.AXLE_HANDLER_CAPABILITY, EnumFacing.UP) : null;
if (upAxle != null && downAxle != null && content != null) {
int range = (int) (downAxle.getMotionData()[0] == 0 ? 0 : Math.abs(upAxle.getMotionData()[0] / downAxle.getMotionData()[0]));
List<EntityPlayer> players = world.getEntitiesWithinAABB(EntityPlayer.class, new AxisAlignedBB(pos.subtract(new Vec3i(range, range, range)), pos.add(new Vec3i(range, range, range))), EntitySelectors.IS_ALIVE);
if (players != null) {
for (EntityPlayer play : players) {
FoodStats food = play.getFoodStats();
int added = (int) Math.min(content.amount / EnergyConverters.FAT_PER_VALUE, Math.min(Math.abs(upAxle.getMotionData()[1]) / ENERGY_PER_VALUE, 40 - (food.getFoodLevel() + food.getSaturationLevel())));
if (added <= 0) {
continue;
}
content.amount -= added * EnergyConverters.FAT_PER_VALUE;
upAxle.addEnergy(-added * ENERGY_PER_VALUE, false, false);
downAxle.addEnergy(added * ENERGY_PER_VALUE, false, false);
int hungerAdded = Math.min(20 - food.getFoodLevel(), added);
// The way saturation is coded is weird, and the best way to do this is through nbt.
NBTTagCompound nbt = new NBTTagCompound();
food.writeNBT(nbt);
nbt.setInteger("foodLevel", hungerAdded + food.getFoodLevel());
nbt.setFloat("foodSaturationLevel", Math.min(20F - food.getSaturationLevel(), added - hungerAdded) + food.getSaturationLevel());
food.readNBT(nbt);
if (content.amount <= 0) {
content = null;
markDirty();
return;
}
}
}
markDirty();
}
}
use of com.Da_Technomancer.crossroads.API.rotary.IAxleHandler in project Crossroads by Crossroads-Development.
the class HamsterWheelTileEntity method update.
@Override
public void update() {
EnumFacing facing = world.getBlockState(pos).getValue(Properties.FACING);
TileEntity te = world.getTileEntity(pos.offset(facing));
if (te != null && te.hasCapability(Capabilities.AXLE_HANDLER_CAPABILITY, facing.getOpposite())) {
IAxleHandler axle = te.getCapability(Capabilities.AXLE_HANDLER_CAPABILITY, facing.getOpposite());
if (world.isRemote) {
angle = (facing.getAxisDirection() == EnumFacing.AxisDirection.NEGATIVE && world.getBlockState(pos.offset(facing)).getBlock() == ModBlocks.axle ? -1F : 1F) * (float) axle.getAngle();
nextAngle = ((float) axle.getNextAngle());
return;
}
axle.addEnergy(facing.getAxisDirection() == EnumFacing.AxisDirection.NEGATIVE && world.getBlockState(pos.offset(facing)).getBlock() == ModBlocks.axle ? -2 : 2, true, true);
} else if (world.isRemote) {
//
nextAngle = angle;
}
}
use of com.Da_Technomancer.crossroads.API.rotary.IAxleHandler in project Crossroads by Crossroads-Development.
the class SteamTurbineTileEntity method update.
@Override
public void update() {
if (world.isRemote) {
IAxleHandler gear = null;
TileEntity te = world.getTileEntity(pos.offset(EnumFacing.UP));
if (te != null && te.hasCapability(Capabilities.AXLE_HANDLER_CAPABILITY, EnumFacing.DOWN)) {
gear = te.getCapability(Capabilities.AXLE_HANDLER_CAPABILITY, EnumFacing.DOWN);
}
completion = (float) (gear == null ? 0 : gear.getAngle());
return;
}
if (steamContent != null) {
runMachine();
}
}
use of com.Da_Technomancer.crossroads.API.rotary.IAxleHandler in project Crossroads by Crossroads-Development.
the class SidedGearHolderRenderer method renderTileEntityAt.
@Override
public void renderTileEntityAt(SidedGearHolderTileEntity gearHolder, double x, double y, double z, float partialTicks, int destroyStage) {
if (!gearHolder.getWorld().isBlockLoaded(gearHolder.getPos(), false)) {
return;
}
Color color;
for (EnumFacing side : EnumFacing.values()) {
if (gearHolder.hasCapability(Capabilities.AXLE_HANDLER_CAPABILITY, side)) {
IAxleHandler handler = gearHolder.getCapability(Capabilities.AXLE_HANDLER_CAPABILITY, side);
color = gearHolder.getMembers()[side.getIndex()].getColor();
GlStateManager.pushMatrix();
GlStateManager.pushAttrib();
GlStateManager.disableLighting();
GlStateManager.translate(x + .5D, y + .5D, z + .5D);
GlStateManager.rotate(side == EnumFacing.DOWN ? 0 : side == EnumFacing.UP ? 180F : side == EnumFacing.NORTH || side == EnumFacing.EAST ? 90F : -90F, side.getAxis() == EnumFacing.Axis.Z ? 1 : 0, 0, side.getAxis() == EnumFacing.Axis.Z ? 0 : 1);
float angle = (float) (handler.getNextAngle() - handler.getAngle());
angle *= partialTicks;
angle += handler.getAngle();
GlStateManager.rotate(-angle, 0F, 1F, 0F);
modelOct.render(res, color);
GlStateManager.enableLighting();
GlStateManager.popAttrib();
GlStateManager.popMatrix();
}
}
}
Aggregations