Search in sources :

Example 6 with IDirectionalTile

use of blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IDirectionalTile in project Immersive-Tech by FerroO2000.

the class BlockITTileProvider method rotateBlock.

@Override
public boolean rotateBlock(World world, BlockPos pos, EnumFacing axis) {
    TileEntity tile = world.getTileEntity(pos);
    if (tile instanceof IDirectionalTile) {
        if (!((IDirectionalTile) tile).canRotate(axis))
            return false;
        IBlockState state = world.getBlockState(pos);
        if (state.getPropertyKeys().contains(IEProperties.FACING_ALL) || state.getPropertyKeys().contains(IEProperties.FACING_HORIZONTAL)) {
            PropertyDirection prop = state.getPropertyKeys().contains(IEProperties.FACING_HORIZONTAL) ? IEProperties.FACING_HORIZONTAL : IEProperties.FACING_ALL;
            EnumFacing f = ((IDirectionalTile) tile).getFacing();
            int limit = ((IDirectionalTile) tile).getFacingLimitation();
            if (limit == 0)
                f = EnumFacing.VALUES[(f.ordinal() + 1) % EnumFacing.VALUES.length];
            else if (limit == 1)
                f = axis.getAxisDirection() == AxisDirection.POSITIVE ? f.rotateAround(axis.getAxis()).getOpposite() : f.rotateAround(axis.getAxis());
            else if (limit == 2 || limit == 5)
                f = axis.getAxisDirection() == AxisDirection.POSITIVE ? f.rotateY() : f.rotateYCCW();
            if (f != ((IDirectionalTile) tile).getFacing()) {
                EnumFacing old = ((IDirectionalTile) tile).getFacing();
                ((IDirectionalTile) tile).setFacing(f);
                ((IDirectionalTile) tile).afterRotation(old, f);
                state = applyProperty(state, prop, ((IDirectionalTile) tile).getFacing());
                world.setBlockState(pos, state.cycleProperty(prop));
            }
        }
    }
    return false;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IBlockState(net.minecraft.block.state.IBlockState) PropertyDirection(net.minecraft.block.properties.PropertyDirection) EnumFacing(net.minecraft.util.EnumFacing) IDirectionalTile(blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IDirectionalTile)

Example 7 with IDirectionalTile

use of blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IDirectionalTile in project ImmersiveEngineering by BluSunrize.

the class ItemIETool method onItemUse.

@Nonnull
@Override
public EnumActionResult onItemUse(EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
    ItemStack stack = player.getHeldItem(hand);
    TileEntity tileEntity = world.getTileEntity(pos);
    if (stack.getMetadata() == HAMMER_META) {
        if (!(tileEntity instanceof IDirectionalTile) && !(tileEntity instanceof IHammerInteraction) && !(tileEntity instanceof IConfigurableSides))
            return RotationUtil.rotateBlock(world, pos, side) ? EnumActionResult.SUCCESS : EnumActionResult.PASS;
    } else if (stack.getMetadata() == CUTTER_META && tileEntity instanceof IImmersiveConnectable) {
        TargetingInfo target = new TargetingInfo(side, hitX, hitY, hitZ);
        BlockPos masterPos = ((IImmersiveConnectable) tileEntity).getConnectionMaster(null, target);
        tileEntity = world.getTileEntity(masterPos);
        if (!(tileEntity instanceof IImmersiveConnectable))
            return EnumActionResult.PASS;
        if (!world.isRemote) {
            IImmersiveConnectable nodeHere = (IImmersiveConnectable) tileEntity;
            boolean cut = ImmersiveNetHandler.INSTANCE.clearAllConnectionsFor(Utils.toCC(nodeHere), world, target);
            IESaveData.setDirty(world.provider.getDimension());
            if (cut) {
                int nbtDamage = ItemNBTHelper.getInt(stack, Lib.NBT_DAMAGE) + 1;
                if (nbtDamage < cutterDurabiliy)
                    ItemNBTHelper.setInt(stack, Lib.NBT_DAMAGE, nbtDamage);
                else {
                    player.renderBrokenItemStack(stack);
                    player.setItemStackToSlot(EntityEquipmentSlot.MAINHAND, ItemStack.EMPTY);
                }
            }
        }
        return EnumActionResult.SUCCESS;
    } else if (stack.getMetadata() == VOLTMETER_META && !world.isRemote) {
        if (!player.isSneaking() && (tileEntity instanceof IFluxReceiver || tileEntity instanceof IFluxProvider)) {
            int max = 0;
            int stored = 0;
            if (tileEntity instanceof IFluxReceiver) {
                max = ((IFluxReceiver) tileEntity).getMaxEnergyStored(side);
                stored = ((IFluxReceiver) tileEntity).getEnergyStored(side);
            } else {
                max = ((IFluxProvider) tileEntity).getMaxEnergyStored(side);
                stored = ((IFluxProvider) tileEntity).getEnergyStored(side);
            }
            if (max > 0)
                ChatUtils.sendServerNoSpamMessages(player, new TextComponentTranslation(Lib.CHAT_INFO + "energyStorage", stored, max));
            return EnumActionResult.SUCCESS;
        }
        if (player.isSneaking() && tileEntity instanceof IImmersiveConnectable) {
            if (!ItemNBTHelper.hasKey(stack, "linkingPos"))
                ItemNBTHelper.setIntArray(stack, "linkingPos", new int[] { world.provider.getDimension(), pos.getX(), pos.getY(), pos.getZ() });
            else {
                int[] array = ItemNBTHelper.getIntArray(stack, "linkingPos");
                BlockPos linkPos = new BlockPos(array[1], array[2], array[3]);
                TileEntity tileEntityLinkingPos = world.getTileEntity(linkPos);
                if (array[0] == world.provider.getDimension()) {
                    IImmersiveConnectable nodeHere = (IImmersiveConnectable) tileEntity;
                    IImmersiveConnectable nodeLink = (IImmersiveConnectable) tileEntityLinkingPos;
                    if (nodeLink != null) {
                        Set<AbstractConnection> connections = ImmersiveNetHandler.INSTANCE.getIndirectEnergyConnections(Utils.toCC(nodeLink), world, true);
                        for (AbstractConnection con : connections) if (Utils.toCC(nodeHere).equals(con.end))
                            player.sendMessage(new TextComponentTranslation(Lib.CHAT_INFO + "averageLoss", Utils.formatDouble(con.getAverageLossRate() * 100, "###.000")));
                    }
                }
                ItemNBTHelper.remove(stack, "linkingPos");
            }
            return EnumActionResult.SUCCESS;
        }
    }
    return EnumActionResult.PASS;
}
Also used : IHammerInteraction(blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IHammerInteraction) TextComponentTranslation(net.minecraft.util.text.TextComponentTranslation) IImmersiveConnectable(blusunrize.immersiveengineering.api.energy.wires.IImmersiveConnectable) IFluxProvider(blusunrize.immersiveengineering.api.energy.immersiveflux.IFluxProvider) IDirectionalTile(blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IDirectionalTile) TileEntity(net.minecraft.tileentity.TileEntity) TargetingInfo(blusunrize.immersiveengineering.api.TargetingInfo) IFluxReceiver(blusunrize.immersiveengineering.api.energy.immersiveflux.IFluxReceiver) AbstractConnection(blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler.AbstractConnection) IConfigurableSides(blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IConfigurableSides) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) Nonnull(javax.annotation.Nonnull)

Aggregations

IDirectionalTile (blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IDirectionalTile)7 TileEntity (net.minecraft.tileentity.TileEntity)6 EnumFacing (net.minecraft.util.EnumFacing)4 IConfigurableSides (blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IConfigurableSides)3 IHammerInteraction (blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IHammerInteraction)3 TargetingInfo (blusunrize.immersiveengineering.api.TargetingInfo)2 IFluxProvider (blusunrize.immersiveengineering.api.energy.immersiveflux.IFluxProvider)2 IFluxReceiver (blusunrize.immersiveengineering.api.energy.immersiveflux.IFluxReceiver)2 IImmersiveConnectable (blusunrize.immersiveengineering.api.energy.wires.IImmersiveConnectable)2 AbstractConnection (blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler.AbstractConnection)2 IHasDummyBlocks (blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IHasDummyBlocks)2 PropertyDirection (net.minecraft.block.properties.PropertyDirection)2 ItemStack (net.minecraft.item.ItemStack)2 BlockPos (net.minecraft.util.math.BlockPos)2 TextComponentTranslation (net.minecraft.util.text.TextComponentTranslation)2 IMultiblock (blusunrize.immersiveengineering.api.MultiblockHandler.IMultiblock)1 IActiveState (blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IActiveState)1 IAdvancedDirectionalTile (blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IAdvancedDirectionalTile)1 IAttachedIntegerProperies (blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IAttachedIntegerProperies)1 IDualState (blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IDualState)1