Search in sources :

Example 1 with WireType

use of blusunrize.immersiveengineering.api.energy.wires.WireType in project ImmersiveEngineering by BluSunrize.

the class TileEntityTransformer method removeCable.

@Override
public void removeCable(Connection connection) {
    WireType type = connection != null ? connection.cableType : null;
    if (type == null) {
        limitType = null;
        secondCable = null;
    }
    if (type == limitType)
        this.limitType = null;
    if (type == secondCable)
        this.secondCable = null;
    this.markContainingBlockForUpdate(null);
}
Also used : WireType(blusunrize.immersiveengineering.api.energy.wires.WireType)

Example 2 with WireType

use of blusunrize.immersiveengineering.api.energy.wires.WireType in project ImmersiveEngineering by BluSunrize.

the class ItemWireCoil method onItemUseFirst.

@Override
public EnumActionResult onItemUseFirst(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, EnumHand hand) {
    if (!world.isRemote) {
        TileEntity tileEntity = world.getTileEntity(pos);
        if (tileEntity instanceof IImmersiveConnectable && ((IImmersiveConnectable) tileEntity).canConnect()) {
            TargetingInfo target = new TargetingInfo(side, hitX, hitY, hitZ);
            WireType wire = getWireType(stack);
            BlockPos masterPos = ((IImmersiveConnectable) tileEntity).getConnectionMaster(wire, target);
            tileEntity = world.getTileEntity(masterPos);
            if (!(tileEntity instanceof IImmersiveConnectable) || !((IImmersiveConnectable) tileEntity).canConnect())
                return EnumActionResult.PASS;
            if (!((IImmersiveConnectable) tileEntity).canConnectCable(wire, target)) {
                player.addChatMessage(new TextComponentTranslation(Lib.CHAT_WARN + "wrongCable"));
                return EnumActionResult.FAIL;
            }
            if (!ItemNBTHelper.hasKey(stack, "linkingPos")) {
                ItemNBTHelper.setIntArray(stack, "linkingPos", new int[] { world.provider.getDimension(), masterPos.getX(), masterPos.getY(), masterPos.getZ() });
                NBTTagCompound targetNbt = new NBTTagCompound();
                target.writeToNBT(targetNbt);
                ItemNBTHelper.setTagCompound(stack, "targettingInfo", targetNbt);
            } else {
                WireType type = getWireType(stack);
                int[] array = ItemNBTHelper.getIntArray(stack, "linkingPos");
                BlockPos linkPos = new BlockPos(array[1], array[2], array[3]);
                TileEntity tileEntityLinkingPos = world.getTileEntity(linkPos);
                int distanceSq = (int) Math.ceil(linkPos.distanceSq(masterPos));
                if (array[0] != world.provider.getDimension())
                    player.addChatMessage(new TextComponentTranslation(Lib.CHAT_WARN + "wrongDimension"));
                else if (linkPos.equals(masterPos))
                    player.addChatMessage(new TextComponentTranslation(Lib.CHAT_WARN + "sameConnection"));
                else if (distanceSq > (type.getMaxLength() * type.getMaxLength()))
                    player.addChatMessage(new TextComponentTranslation(Lib.CHAT_WARN + "tooFar"));
                else {
                    TargetingInfo targetLink = TargetingInfo.readFromNBT(ItemNBTHelper.getTagCompound(stack, "targettingInfo"));
                    if (!(tileEntityLinkingPos instanceof IImmersiveConnectable) || !((IImmersiveConnectable) tileEntityLinkingPos).canConnectCable(wire, targetLink))
                        player.addChatMessage(new TextComponentTranslation(Lib.CHAT_WARN + "invalidPoint"));
                    else {
                        IImmersiveConnectable nodeHere = (IImmersiveConnectable) tileEntity;
                        IImmersiveConnectable nodeLink = (IImmersiveConnectable) tileEntityLinkingPos;
                        boolean connectionExists = false;
                        Set<Connection> outputs = ImmersiveNetHandler.INSTANCE.getConnections(world, Utils.toCC(nodeHere));
                        if (outputs != null)
                            for (Connection con : outputs) {
                                if (con.end.equals(Utils.toCC(nodeLink)))
                                    connectionExists = true;
                            }
                        if (connectionExists)
                            player.addChatMessage(new TextComponentTranslation(Lib.CHAT_WARN + "connectionExists"));
                        else {
                            Vec3d rtOff0 = nodeHere.getRaytraceOffset(nodeLink).addVector(masterPos.getX(), masterPos.getY(), masterPos.getZ());
                            Vec3d rtOff1 = nodeLink.getRaytraceOffset(nodeHere).addVector(linkPos.getX(), linkPos.getY(), linkPos.getZ());
                            Set<BlockPos> ignore = new HashSet<>();
                            ignore.addAll(nodeHere.getIgnored(nodeLink));
                            ignore.addAll(nodeLink.getIgnored(nodeHere));
                            boolean canSee = Utils.rayTraceForFirst(rtOff0, rtOff1, world, ignore) == null;
                            if (canSee) {
                                ImmersiveNetHandler.INSTANCE.addConnection(world, Utils.toCC(nodeHere), Utils.toCC(nodeLink), (int) Math.sqrt(distanceSq), type);
                                nodeHere.connectCable(type, target, nodeLink);
                                nodeLink.connectCable(type, targetLink, nodeHere);
                                IESaveData.setDirty(world.provider.getDimension());
                                player.addStat(IEAchievements.connectWire);
                                if (!player.capabilities.isCreativeMode)
                                    stack.stackSize--;
                                ((TileEntity) nodeHere).markDirty();
                                world.addBlockEvent(masterPos, ((TileEntity) nodeHere).getBlockType(), -1, 0);
                                IBlockState state = world.getBlockState(masterPos);
                                world.notifyBlockUpdate(masterPos, state, state, 3);
                                ((TileEntity) nodeLink).markDirty();
                                world.addBlockEvent(linkPos, ((TileEntity) nodeLink).getBlockType(), -1, 0);
                                state = world.getBlockState(linkPos);
                                world.notifyBlockUpdate(linkPos, state, state, 3);
                            } else
                                player.addChatMessage(new TextComponentTranslation(Lib.CHAT_WARN + "cantSee"));
                        }
                    }
                }
                ItemNBTHelper.remove(stack, "linkingPos");
                ItemNBTHelper.remove(stack, "targettingInfo");
            }
            return EnumActionResult.SUCCESS;
        }
    }
    return EnumActionResult.PASS;
}
Also used : TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) IBlockState(net.minecraft.block.state.IBlockState) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) Connection(blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler.Connection) IImmersiveConnectable(blusunrize.immersiveengineering.api.energy.wires.IImmersiveConnectable) WireType(blusunrize.immersiveengineering.api.energy.wires.WireType) Vec3d(net.minecraft.util.math.Vec3d) TileEntity(net.minecraft.tileentity.TileEntity) TargetingInfo(blusunrize.immersiveengineering.api.TargetingInfo) BlockPos(net.minecraft.util.math.BlockPos) HashSet(java.util.HashSet)

Example 3 with WireType

use of blusunrize.immersiveengineering.api.energy.wires.WireType in project ImmersiveEngineering by BluSunrize.

the class TileEntityTransformer method getIsMirrored.

@Override
public boolean getIsMirrored() {
    if (onPost)
        return false;
    if (dummy != 0) {
        TileEntity master = worldObj.getTileEntity(pos.down(dummy));
        return master instanceof TileEntityTransformer && ((TileEntityTransformer) master).getIsMirrored();
    } else {
        if (limitType == null && secondCable == null)
            return true;
        WireType higher = this instanceof TileEntityTransformerHV ? WireType.STEEL : WireType.ELECTRUM;
        boolean b = (limitType != null && higher.equals(limitType)) || (secondCable != null && !higher.equals(secondCable));
        return b;
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) WireType(blusunrize.immersiveengineering.api.energy.wires.WireType)

Example 4 with WireType

use of blusunrize.immersiveengineering.api.energy.wires.WireType in project ImmersiveEngineering by BluSunrize.

the class TileEntityBreakerSwitch method removeCable.

@Override
public void removeCable(Connection connection) {
    WireType type = connection != null ? connection.cableType : null;
    if (type == null)
        wires = 0;
    else
        wires--;
    if (wires <= 0)
        limitType = null;
    onConnectionChange();
}
Also used : WireType(blusunrize.immersiveengineering.api.energy.wires.WireType)

Aggregations

WireType (blusunrize.immersiveengineering.api.energy.wires.WireType)4 TileEntity (net.minecraft.tileentity.TileEntity)2 TargetingInfo (blusunrize.immersiveengineering.api.TargetingInfo)1 IImmersiveConnectable (blusunrize.immersiveengineering.api.energy.wires.IImmersiveConnectable)1 Connection (blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler.Connection)1 HashSet (java.util.HashSet)1 IBlockState (net.minecraft.block.state.IBlockState)1 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)1 BlockPos (net.minecraft.util.math.BlockPos)1 Vec3d (net.minecraft.util.math.Vec3d)1 TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)1