Search in sources :

Example 1 with IDirectionalTile

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

the class ItemIETool method onItemUseFirst.

//	@Override
//	public boolean doesContainerItemLeaveCraftingGrid(ItemStack stack)
//	{
//		return stack.getItemDamage()!=0;
//	}
@Override
public EnumActionResult onItemUseFirst(ItemStack stack, EntityPlayer player, World world, BlockPos pos, EnumFacing side, float hitX, float hitY, float hitZ, EnumHand hand) {
    TileEntity tileEntity = world.getTileEntity(pos);
    if (stack.getItemDamage() == 0) {
        if (FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT)
            return EnumActionResult.PASS;
        String[] permittedMultiblocks = null;
        String[] interdictedMultiblocks = null;
        if (ItemNBTHelper.hasKey(stack, "multiblockPermission")) {
            NBTTagList list = stack.getTagCompound().getTagList("multiblockPermission", 8);
            permittedMultiblocks = new String[list.tagCount()];
            for (int i = 0; i < permittedMultiblocks.length; i++) permittedMultiblocks[i] = list.getStringTagAt(i);
        }
        if (ItemNBTHelper.hasKey(stack, "multiblockInterdiction")) {
            NBTTagList list = stack.getTagCompound().getTagList("multiblockInterdiction", 8);
            interdictedMultiblocks = new String[list.tagCount()];
            for (int i = 0; i < interdictedMultiblocks.length; i++) interdictedMultiblocks[i] = list.getStringTagAt(i);
        }
        for (IMultiblock mb : MultiblockHandler.getMultiblocks()) if (mb.isBlockTrigger(world.getBlockState(pos))) {
            boolean b = permittedMultiblocks == null;
            if (permittedMultiblocks != null)
                for (String s : permittedMultiblocks) if (mb.getUniqueName().equalsIgnoreCase(s)) {
                    b = true;
                    continue;
                }
            if (!b)
                break;
            if (interdictedMultiblocks != null)
                for (String s : interdictedMultiblocks) if (mb.getUniqueName().equalsIgnoreCase(s)) {
                    b = false;
                    continue;
                }
            if (!b)
                break;
            if (MultiblockHandler.postMultiblockFormationEvent(player, mb, pos, stack).isCanceled())
                continue;
            if (mb.createStructure(world, pos, side, player))
                return EnumActionResult.SUCCESS;
        }
        TileEntity tile = world.getTileEntity(pos);
        if (!(tile instanceof IDirectionalTile) && !(tile instanceof IHammerInteraction) && !(tile instanceof IConfigurableSides))
            return RotationUtil.rotateBlock(world, pos, side) ? EnumActionResult.SUCCESS : EnumActionResult.PASS;
    } else if (stack.getItemDamage() == 1 && tileEntity instanceof IImmersiveConnectable && !world.isRemote) {
        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;
        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, "cutterDmg") + 1;
            if (nbtDamage < cutterMaxDamage)
                ItemNBTHelper.setInt(stack, "cutterDmg", nbtDamage);
            else {
                player.renderBrokenItemStack(stack);
                player.setItemStackToSlot(EntityEquipmentSlot.MAINHAND, null);
            }
        }
        return EnumActionResult.SUCCESS;
    } else if (stack.getItemDamage() == 2 && !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.addChatComponentMessage(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) NBTTagList(net.minecraft.nbt.NBTTagList) TargetingInfo(blusunrize.immersiveengineering.api.TargetingInfo) IMultiblock(blusunrize.immersiveengineering.api.MultiblockHandler.IMultiblock) 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)

Example 2 with IDirectionalTile

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

the class BlockITTileProvider method getActualState.

@Override
public IBlockState getActualState(IBlockState state, IBlockAccess world, BlockPos pos) {
    state = super.getActualState(state, world, pos);
    TileEntity tile = world.getTileEntity(pos);
    if (tile instanceof IAttachedIntegerProperies) {
        for (String s : ((IAttachedIntegerProperies) tile).getIntPropertyNames()) state = applyProperty(state, ((IAttachedIntegerProperies) tile).getIntProperty(s), ((IAttachedIntegerProperies) tile).getIntPropertyValue(s));
    }
    if (tile instanceof IDirectionalTile && (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;
        state = applyProperty(state, prop, ((IDirectionalTile) tile).getFacing());
    } else if (state.getPropertyKeys().contains(IEProperties.FACING_HORIZONTAL))
        state = state.withProperty(IEProperties.FACING_HORIZONTAL, getDefaultFacing());
    else if (state.getPropertyKeys().contains(IEProperties.FACING_ALL))
        state = state.withProperty(IEProperties.FACING_ALL, getDefaultFacing());
    if (tile instanceof IActiveState) {
        IProperty boolProp = ((IActiveState) tile).getBoolProperty(IActiveState.class);
        if (state.getPropertyKeys().contains(boolProp))
            state = applyProperty(state, boolProp, ((IActiveState) tile).getIsActive());
    }
    if (tile instanceof IDualState) {
        IProperty boolProp = ((IDualState) tile).getBoolProperty(IDualState.class);
        if (state.getPropertyKeys().contains(boolProp))
            state = applyProperty(state, boolProp, ((IDualState) tile).getIsSecondState());
    }
    if (tile instanceof TileEntityMultiblockPart)
        state = applyProperty(state, IEProperties.MULTIBLOCKSLAVE, ((TileEntityMultiblockPart) tile).isDummy());
    else if (tile instanceof IHasDummyBlocks)
        state = applyProperty(state, IEProperties.MULTIBLOCKSLAVE, ((IHasDummyBlocks) tile).isDummy());
    if (tile instanceof IMirrorAble)
        state = applyProperty(state, ((IMirrorAble) tile).getBoolProperty(IMirrorAble.class), ((IMirrorAble) tile).getIsMirrored());
    return state;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IProperty(net.minecraft.block.properties.IProperty) PropertyDirection(net.minecraft.block.properties.PropertyDirection) IAttachedIntegerProperies(blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IAttachedIntegerProperies) TileEntityMultiblockPart(blusunrize.immersiveengineering.common.blocks.TileEntityMultiblockPart) IMirrorAble(blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IMirrorAble) IDualState(blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IDualState) IActiveState(blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IActiveState) IHasDummyBlocks(blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IHasDummyBlocks) IDirectionalTile(blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IDirectionalTile)

Example 3 with IDirectionalTile

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

the class BlockITTileProvider method onBlockActivated.

@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, EnumFacing side, float hitX, float hitY, float hitZ) {
    ItemStack heldItem = player.getHeldItem(hand);
    TileEntity tile = world.getTileEntity(pos);
    if (tile instanceof IConfigurableSides && Utils.isHammer(heldItem) && !world.isRemote) {
        int iSide = player.isSneaking() ? side.getOpposite().ordinal() : side.ordinal();
        if (((IConfigurableSides) tile).toggleSide(iSide, player))
            return true;
    }
    if (tile instanceof IDirectionalTile && Utils.isHammer(heldItem) && ((IDirectionalTile) tile).canHammerRotate(side, hitX, hitY, hitZ, player) && !world.isRemote) {
        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 = player.isSneaking() ? f.rotateAround(side.getAxis()).getOpposite() : f.rotateAround(side.getAxis());
        else if (limit == 2 || limit == 5)
            f = player.isSneaking() ? f.rotateYCCW() : f.rotateY();
        ((IDirectionalTile) tile).setFacing(f);
        tile.markDirty();
        world.notifyBlockUpdate(pos, state, state, 3);
        world.addBlockEvent(tile.getPos(), tile.getBlockType(), 255, 0);
        return true;
    }
    if (tile instanceof IHammerInteraction && Utils.isHammer(heldItem) && !world.isRemote) {
        boolean b = ((IHammerInteraction) tile).hammerUseSide(side, player, hitX, hitY, hitZ);
        if (b)
            return b;
    }
    if (tile instanceof IPlayerInteraction) {
        boolean b = ((IPlayerInteraction) tile).interact(side, player, hand, heldItem, hitX, hitY, hitZ);
        if (b)
            return b;
    }
    if (tile instanceof IGuiTile && hand == EnumHand.MAIN_HAND && !player.isSneaking()) {
        TileEntity master = ((IGuiTile) tile).getGuiMaster();
        if (((IGuiTile) tile).canOpenGui(player)) {
            if (!world.isRemote && master != null)
                CommonProxy.openGuiForTile(player, (TileEntity & IGuiTile) master);
            return true;
        }
    }
    return false;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IHammerInteraction(blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IHammerInteraction) IGuiTile(blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IGuiTile) EnumFacing(net.minecraft.util.EnumFacing) IConfigurableSides(blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IConfigurableSides) IPlayerInteraction(blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IPlayerInteraction) ItemStack(net.minecraft.item.ItemStack) IDirectionalTile(blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IDirectionalTile)

Example 4 with IDirectionalTile

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

the class TileEntityIEBase method rotate.

@Override
public void rotate(Rotation rot) {
    if (rot != Rotation.NONE && this instanceof IDirectionalTile && ((IDirectionalTile) this).canRotate(EnumFacing.UP)) {
        EnumFacing f = ((IDirectionalTile) this).getFacing();
        switch(rot) {
            case CLOCKWISE_90:
                f = f.rotateY();
                break;
            case CLOCKWISE_180:
                f = f.getOpposite();
                break;
            case COUNTERCLOCKWISE_90:
                f = f.rotateYCCW();
                break;
        }
        ((IDirectionalTile) this).setFacing(f);
        this.markDirty();
        if (this.pos != null)
            this.markBlockForUpdate(this.pos, null);
    }
}
Also used : EnumFacing(net.minecraft.util.EnumFacing) IDirectionalTile(blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IDirectionalTile)

Example 5 with IDirectionalTile

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

the class BlockITTileProvider method onIEBlockPlacedBy.

@Override
public void onIEBlockPlacedBy(World world, BlockPos pos, IBlockState state, EnumFacing side, float hitX, float hitY, float hitZ, EntityLivingBase placer, ItemStack stack) {
    TileEntity tile = world.getTileEntity(pos);
    if (tile instanceof IDirectionalTile) {
        EnumFacing f = ((IDirectionalTile) tile).getFacingForPlacement(placer, pos, side, hitX, hitY, hitZ);
        ((IDirectionalTile) tile).setFacing(f);
        if (tile instanceof IAdvancedDirectionalTile)
            ((IAdvancedDirectionalTile) tile).onDirectionalPlacement(side, hitX, hitY, hitZ, placer);
    }
    if (tile instanceof IHasDummyBlocks) {
        ((IHasDummyBlocks) tile).placeDummies(pos, state, side, hitX, hitY, hitZ);
    }
    if (tile instanceof ITileDrop) {
        ((ITileDrop) tile).readOnPlacement(placer, stack);
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) EnumFacing(net.minecraft.util.EnumFacing) ITileDrop(blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.ITileDrop) IHasDummyBlocks(blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IHasDummyBlocks) IDirectionalTile(blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IDirectionalTile) IAdvancedDirectionalTile(blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IAdvancedDirectionalTile)

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