Search in sources :

Example 16 with IAxleHandler

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();
    }
}
Also used : IAxleHandler(com.Da_Technomancer.crossroads.API.rotary.IAxleHandler) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem)

Example 17 with IAxleHandler

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();
    }
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) IAxleHandler(com.Da_Technomancer.crossroads.API.rotary.IAxleHandler) Vec3i(net.minecraft.util.math.Vec3i) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) EntityPlayer(net.minecraft.entity.player.EntityPlayer) FoodStats(net.minecraft.util.FoodStats)

Example 18 with IAxleHandler

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;
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IAxleHandler(com.Da_Technomancer.crossroads.API.rotary.IAxleHandler) EnumFacing(net.minecraft.util.EnumFacing)

Example 19 with IAxleHandler

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();
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IAxleHandler(com.Da_Technomancer.crossroads.API.rotary.IAxleHandler)

Example 20 with IAxleHandler

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();
        }
    }
}
Also used : IAxleHandler(com.Da_Technomancer.crossroads.API.rotary.IAxleHandler) Color(java.awt.Color) EnumFacing(net.minecraft.util.EnumFacing)

Aggregations

IAxleHandler (com.Da_Technomancer.crossroads.API.rotary.IAxleHandler)37 TileEntity (net.minecraft.tileentity.TileEntity)17 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)3 EnumFacing (net.minecraft.util.EnumFacing)3 SendSpinToClient (com.Da_Technomancer.crossroads.API.packets.SendSpinToClient)2 ChunkPos (net.minecraft.util.math.ChunkPos)2 TextComponentString (net.minecraft.util.text.TextComponentString)2 TargetPoint (net.minecraftforge.fml.common.network.NetworkRegistry.TargetPoint)2 BeamRenderTEBase (com.Da_Technomancer.crossroads.API.magic.BeamRenderTEBase)1 MagicUnit (com.Da_Technomancer.crossroads.API.magic.MagicUnit)1 SendFieldsToClient (com.Da_Technomancer.crossroads.API.packets.SendFieldsToClient)1 FieldWorldSavedData (com.Da_Technomancer.crossroads.API.technomancy.FieldWorldSavedData)1 RatiatorTileEntity (com.Da_Technomancer.crossroads.tileentities.RatiatorTileEntity)1 CrystalMasterAxisTileEntity (com.Da_Technomancer.crossroads.tileentities.magic.CrystalMasterAxisTileEntity)1 Color (java.awt.Color)1 EntityItem (net.minecraft.entity.item.EntityItem)1 EntityPlayer (net.minecraft.entity.player.EntityPlayer)1 ItemStack (net.minecraft.item.ItemStack)1 FoodStats (net.minecraft.util.FoodStats)1 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)1