Search in sources :

Example 21 with IAxleHandler

use of com.Da_Technomancer.crossroads.API.rotary.IAxleHandler in project Crossroads by Crossroads-Development.

the class OmniMeter method onItemUse.

@Override
public EnumActionResult onItemUse(EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    TileEntity te = worldIn.getTileEntity(pos);
    if (te == null || worldIn.isRemote) {
        return te != null && te instanceof RatiatorTileEntity ? EnumActionResult.SUCCESS : EnumActionResult.PASS;
    }
    boolean pass = true;
    if (te.hasCapability(Capabilities.HEAT_HANDLER_CAPABILITY, null)) {
        pass = false;
        playerIn.sendMessage(new TextComponentString("Temp: " + worldIn.getTileEntity(pos).getCapability(Capabilities.HEAT_HANDLER_CAPABILITY, null).getTemp() + "°C"));
        playerIn.sendMessage(new TextComponentString("Biome Temp: " + EnergyConverters.BIOME_TEMP_MULT * worldIn.getBiomeForCoordsBody(pos).getFloatTemperature(pos) + "°C"));
    }
    if (te.hasCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, null)) {
        pass = false;
        IFluidHandler pipe = te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, null);
        playerIn.sendMessage(new TextComponentString(pipe.getTankProperties().length + " internal tank" + (pipe.getTankProperties().length == 1 ? "." : "s.")));
        for (IFluidTankProperties tank : pipe.getTankProperties()) {
            playerIn.sendMessage(new TextComponentString("Amount: " + (tank.getContents() == null ? 0 : tank.getContents().amount) + ", Type: " + (tank.getContents() == null ? "None" : tank.getContents().getLocalizedName()) + ", Capacity: " + tank.getCapacity()));
        }
    }
    if (te.hasCapability(Capabilities.AXLE_HANDLER_CAPABILITY, facing.getOpposite())) {
        pass = false;
        IAxleHandler gear = te.getCapability(Capabilities.AXLE_HANDLER_CAPABILITY, facing.getOpposite());
        playerIn.sendMessage(new TextComponentString("Speed: " + MiscOp.betterRound(gear.getMotionData()[0], 3) + ", Energy: " + MiscOp.betterRound(gear.getMotionData()[1], 3) + ", Power: " + MiscOp.betterRound(gear.getMotionData()[2], 3) + ", Mass: " + gear.getPhysData()[0] + ", I: " + gear.getPhysData()[1]));
    } else if (te.hasCapability(Capabilities.AXLE_HANDLER_CAPABILITY, facing)) {
        pass = false;
        IAxleHandler gear = te.getCapability(Capabilities.AXLE_HANDLER_CAPABILITY, facing);
        playerIn.sendMessage(new TextComponentString("Speed: " + MiscOp.betterRound(gear.getMotionData()[0], 3) + ", Energy: " + MiscOp.betterRound(gear.getMotionData()[1], 3) + ", Power: " + MiscOp.betterRound(gear.getMotionData()[2], 3) + ", Mass: " + gear.getPhysData()[0] + ", I: " + gear.getPhysData()[1]));
    }
    if (te instanceof BeamRenderTEBase) {
        pass = false;
        MagicUnit[] mag = ((BeamRenderTEBase) te).getLastFullSent();
        if (mag != null) {
            for (int i = 0; i < mag.length; i++) {
                MagicUnit check = mag[i];
                if (check != null) {
                    NBTTagCompound nbt = MiscOp.getPlayerTag(playerIn);
                    if (!nbt.hasKey("elements")) {
                        nbt.setTag("elements", new NBTTagCompound());
                    }
                    nbt = nbt.getCompoundTag("elements");
                    if (!nbt.hasKey(MagicElements.getElement(check).name())) {
                        nbt.setBoolean(MagicElements.getElement(check).name(), true);
                        playerIn.sendMessage(new TextComponentString(TextFormatting.BOLD.toString() + "New Element Discovered: " + MagicElements.getElement(check).toString()));
                        StoreNBTToClient.syncNBTToClient((EntityPlayerMP) playerIn, false);
                    }
                    playerIn.sendMessage(new TextComponentString(EnumFacing.getFront(i).toString() + ": " + check.toString()));
                }
            }
        }
    }
    if (te instanceof CrystalMasterAxisTileEntity) {
        pass = false;
        playerIn.sendMessage(new TextComponentString("Element: " + ((((CrystalMasterAxisTileEntity) te).getElement() == null) ? "NONE" : (((CrystalMasterAxisTileEntity) te).getElement().toString() + (((CrystalMasterAxisTileEntity) te).isVoid() ? " (VOID), " : ", ") + "Time: " + ((CrystalMasterAxisTileEntity) te).getTime()))));
    }
    if (te instanceof RatiatorTileEntity) {
        pass = false;
        playerIn.sendMessage(new TextComponentString("Out: " + ((RatiatorTileEntity) te).getOutput()));
    }
    return pass ? EnumActionResult.PASS : EnumActionResult.SUCCESS;
}
Also used : MagicUnit(com.Da_Technomancer.crossroads.API.magic.MagicUnit) CrystalMasterAxisTileEntity(com.Da_Technomancer.crossroads.tileentities.magic.CrystalMasterAxisTileEntity) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) BeamRenderTEBase(com.Da_Technomancer.crossroads.API.magic.BeamRenderTEBase) IFluidHandler(net.minecraftforge.fluids.capability.IFluidHandler) TextComponentString(net.minecraft.util.text.TextComponentString) CrystalMasterAxisTileEntity(com.Da_Technomancer.crossroads.tileentities.magic.CrystalMasterAxisTileEntity) RatiatorTileEntity(com.Da_Technomancer.crossroads.tileentities.RatiatorTileEntity) TileEntity(net.minecraft.tileentity.TileEntity) IAxleHandler(com.Da_Technomancer.crossroads.API.rotary.IAxleHandler) IFluidTankProperties(net.minecraftforge.fluids.capability.IFluidTankProperties) RatiatorTileEntity(com.Da_Technomancer.crossroads.tileentities.RatiatorTileEntity)

Example 22 with IAxleHandler

use of com.Da_Technomancer.crossroads.API.rotary.IAxleHandler in project Crossroads by Crossroads-Development.

the class Speedometer method onItemUse.

@Override
public EnumActionResult onItemUse(EntityPlayer playerIn, World worldIn, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ) {
    TileEntity te = worldIn.getTileEntity(pos);
    if (te != null && !worldIn.isRemote && te.hasCapability(Capabilities.AXLE_HANDLER_CAPABILITY, facing.getOpposite())) {
        IAxleHandler gear = te.getCapability(Capabilities.AXLE_HANDLER_CAPABILITY, facing.getOpposite());
        playerIn.sendMessage(new TextComponentString("Speed: " + MiscOp.betterRound(gear.getMotionData()[0], 3) + ", Energy: " + MiscOp.betterRound(gear.getMotionData()[1], 3)));
        return EnumActionResult.SUCCESS;
    }
    return EnumActionResult.PASS;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IAxleHandler(com.Da_Technomancer.crossroads.API.rotary.IAxleHandler) TextComponentString(net.minecraft.util.text.TextComponentString)

Example 23 with IAxleHandler

use of com.Da_Technomancer.crossroads.API.rotary.IAxleHandler in project Crossroads by Crossroads-Development.

the class GreaterThanAxisTileEntity method runAngleCalc.

private void runAngleCalc() {
    boolean syncSpin = false;
    boolean work = false;
    for (IAxleHandler axle : rotaryMembers) {
        if (axle.shouldManageAngle()) {
            syncSpin = Math.abs(axle.getMotionData()[0] - axle.getClientW()) >= CLIENT_SPEED_MARGIN * axle.getRotationRatio();
            work = true;
            break;
        }
    }
    if (!work) {
        return;
    }
    for (IAxleHandler axle : rotaryMembers) {
        if (axle.shouldManageAngle()) {
            float axleSpeed = ((float) axle.getMotionData()[0]);
            axle.setAngle(axle.getAngle() + (axleSpeed * 9F / (float) Math.PI));
            if (syncSpin) {
                axle.syncAngle();
            }
        }
    }
}
Also used : IAxleHandler(com.Da_Technomancer.crossroads.API.rotary.IAxleHandler)

Example 24 with IAxleHandler

use of com.Da_Technomancer.crossroads.API.rotary.IAxleHandler in project Crossroads by Crossroads-Development.

the class LessThanAxisTileEntity method runCalc.

private void runCalc() {
    TileEntity backTE = world.getTileEntity(pos.offset(facing.getOpposite()));
    double inBack = backTE != null && backTE.hasCapability(Capabilities.AXLE_HANDLER_CAPABILITY, facing) ? backTE.getCapability(Capabilities.AXLE_HANDLER_CAPABILITY, facing).getMotionData()[0] : 0;
    TileEntity topTE = world.getTileEntity(pos.offset(EnumFacing.UP));
    double inTop = topTE != null && topTE.hasCapability(Capabilities.AXLE_HANDLER_CAPABILITY, EnumFacing.DOWN) ? topTE.getCapability(Capabilities.AXLE_HANDLER_CAPABILITY, EnumFacing.DOWN).getMotionData()[0] : 0;
    if (facing.getAxisDirection() == AxisDirection.POSITIVE && world.getBlockState(pos.offset(facing.getOpposite())).getBlock() == ModBlocks.axle) {
        inBack *= -1D;
    }
    double baseSpeed = inBack < inTop ? inBack : 0;
    double sumIRot = 0;
    sumEnergy = 0;
    for (IAxleHandler gear : rotaryMembers) {
        sumIRot += gear.getPhysData()[1] * Math.pow(gear.getRotationRatio(), 2);
        sumEnergy += Math.signum(gear.getRotationRatio()) * gear.getMotionData()[1] * Math.pow(1.001D, -Math.abs(gear.getMotionData()[0]));
    }
    double cost = sumIRot * Math.pow(baseSpeed, 2) / 2D;
    TileEntity downTE = world.getTileEntity(pos.offset(EnumFacing.DOWN));
    double availableEnergy = Math.abs(sumEnergy) + Math.abs(downTE != null && downTE.hasCapability(Capabilities.AXLE_HANDLER_CAPABILITY, EnumFacing.UP) ? downTE.getCapability(Capabilities.AXLE_HANDLER_CAPABILITY, EnumFacing.UP).getMotionData()[1] : 0);
    if (availableEnergy - cost < 0) {
        baseSpeed = 0;
        cost = 0;
    }
    availableEnergy -= cost;
    for (IAxleHandler gear : rotaryMembers) {
        double newEnergy = 0;
        // set w
        gear.getMotionData()[0] = gear.getRotationRatio() * baseSpeed;
        // set energy
        newEnergy = Math.signum(gear.getMotionData()[0]) * Math.pow(gear.getMotionData()[0], 2) * gear.getPhysData()[1] / 2D;
        gear.getMotionData()[1] = newEnergy;
        sumEnergy += newEnergy;
        // set power
        gear.getMotionData()[2] = (newEnergy - gear.getMotionData()[3]) * 20;
        // set lastE
        gear.getMotionData()[3] = newEnergy;
        gear.markChanged();
    }
    if (downTE != null && downTE.hasCapability(Capabilities.AXLE_HANDLER_CAPABILITY, EnumFacing.UP)) {
        downTE.getCapability(Capabilities.AXLE_HANDLER_CAPABILITY, EnumFacing.UP).getMotionData()[1] = availableEnergy * MiscOp.posOrNeg(downTE.getCapability(Capabilities.AXLE_HANDLER_CAPABILITY, EnumFacing.UP).getMotionData()[1], 1);
    }
    runAngleCalc();
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IAxleHandler(com.Da_Technomancer.crossroads.API.rotary.IAxleHandler)

Example 25 with IAxleHandler

use of com.Da_Technomancer.crossroads.API.rotary.IAxleHandler in project Crossroads by Crossroads-Development.

the class CrystalMasterAxisTileEntity method runCalc.

private void runCalc() {
    double sumIRot = 0;
    sumEnergy = 0;
    for (IAxleHandler gear : rotaryMembers) {
        sumIRot += gear.getPhysData()[1] * Math.pow(gear.getRotationRatio(), 2);
    }
    if (sumIRot == 0 || sumIRot != sumIRot) {
        return;
    }
    sumEnergy = runLoss(rotaryMembers, currentElement == MagicElements.STABILITY ? (voi ? 1.5D : 1D) : 1.001D);
    sumEnergy += Math.signum(sumEnergy) * (currentElement == MagicElements.ENERGY ? (voi ? -10 : 10) : 0);
    sumEnergy += currentElement == MagicElements.CHARGE ? (voi ? -10 : 10) : 0;
    sumEnergy = currentElement == MagicElements.EQUALIBRIUM ? (voi ? ((7D * sumEnergy) - (3D * lastSumEnergy)) / 4D : (sumEnergy + (3D * lastSumEnergy)) / 4D) : sumEnergy;
    if (sumEnergy < 1 && sumEnergy > -1) {
        sumEnergy = 0;
    }
    lastSumEnergy = sumEnergy;
    for (IAxleHandler gear : rotaryMembers) {
        double newEnergy = 0;
        // set w
        gear.getMotionData()[0] = Math.signum(sumEnergy) * Math.signum(gear.getRotationRatio()) * Math.sqrt(Math.abs(sumEnergy) * 2D * Math.pow(gear.getRotationRatio(), 2) / sumIRot);
        // set energy
        newEnergy = Math.signum(gear.getMotionData()[0]) * Math.pow(gear.getMotionData()[0], 2) * gear.getPhysData()[1] / 2D;
        gear.getMotionData()[1] = newEnergy;
        // set power
        gear.getMotionData()[2] = (newEnergy - gear.getMotionData()[3]) * 20;
        // set lastE
        gear.getMotionData()[3] = newEnergy;
        gear.markChanged();
    }
}
Also used : IAxleHandler(com.Da_Technomancer.crossroads.API.rotary.IAxleHandler)

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