Search in sources :

Example 71 with BlockPos

use of net.minecraft.util.math.BlockPos in project ImmersiveEngineering by BluSunrize.

the class TileEntitySheetmetalTank method update.

@Override
public void update() {
    if (pos == 4 && !worldObj.isRemote && worldObj.isBlockIndirectlyGettingPowered(getPos()) > 0)
        for (int i = 0; i < 6; i++) if (i != 1 && tank.getFluidAmount() > 0) {
            EnumFacing f = EnumFacing.getFront(i);
            int outSize = Math.min(144, tank.getFluidAmount());
            FluidStack out = new FluidStack(tank.getFluid().getFluid(), outSize);
            BlockPos outputPos = getPos().offset(f);
            IFluidHandler output = FluidUtil.getFluidHandler(worldObj, outputPos, f.getOpposite());
            if (output != null) {
                int accepted = output.fill(out, false);
                if (accepted > 0) {
                    int drained = output.fill(Utils.copyFluidStackWithAmount(out, Math.min(out.amount, accepted), false), true);
                    this.tank.drain(drained, true);
                    this.markContainingBlockForUpdate(null);
                    updateComparatorValuesPart2();
                }
            }
        }
}
Also used : FluidStack(net.minecraftforge.fluids.FluidStack) EnumFacing(net.minecraft.util.EnumFacing) BlockPos(net.minecraft.util.math.BlockPos) IFluidHandler(net.minecraftforge.fluids.capability.IFluidHandler) IComparatorOverride(blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IComparatorOverride)

Example 72 with BlockPos

use of net.minecraft.util.math.BlockPos in project ImmersiveEngineering by BluSunrize.

the class TileEntityRazorWire method isStacked.

private boolean isStacked() {
    BlockPos down = getPos().down();
    TileEntity te = worldObj.getTileEntity(down);
    if (te instanceof TileEntityRazorWire)
        return ((TileEntityRazorWire) te).isOnGround();
    return false;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) BlockPos(net.minecraft.util.math.BlockPos)

Example 73 with BlockPos

use of net.minecraft.util.math.BlockPos in project ImmersiveEngineering by BluSunrize.

the class TileEntityRazorWire method outputEnergy.

@Override
public int outputEnergy(int amount, boolean simulate, int energyType) {
    if (amount > 0) {
        if (!simulate) {
            int maxReach = amount / 8;
            int widthP = 0;
            boolean connectP = true;
            int widthN = 0;
            boolean connectN = true;
            EnumFacing dir = facing.rotateY();
            if (dir.getAxisDirection() == AxisDirection.NEGATIVE)
                dir = dir.getOpposite();
            for (int i = 1; i <= maxReach; i++) {
                BlockPos posP = getPos().offset(dir, i);
                if (connectP && worldObj.isBlockLoaded(posP) && worldObj.getTileEntity(posP) instanceof TileEntityRazorWire)
                    widthP++;
                else
                    connectP = false;
                BlockPos posN = getPos().offset(dir, -i);
                if (connectN && worldObj.isBlockLoaded(posN) && worldObj.getTileEntity(posN) instanceof TileEntityRazorWire)
                    widthN++;
                else
                    connectN = false;
            }
            AxisAlignedBB aabb = new AxisAlignedBB(getPos().add(facing.getAxis() == Axis.Z ? -widthN : 0, 0, facing.getAxis() == Axis.X ? -widthN : 0), getPos().add(facing.getAxis() == Axis.Z ? 1 + widthP : 1, 1, facing.getAxis() == Axis.X ? 1 + widthP : 1));
            List<EntityLivingBase> entities = worldObj.getEntitiesWithinAABB(EntityLivingBase.class, aabb);
            for (EntityLivingBase ent : entities) ent.attackEntityFrom(IEDamageSources.razorShock, 2);
        }
        return 64;
    }
    return 0;
}
Also used : AxisAlignedBB(net.minecraft.util.math.AxisAlignedBB) EnumFacing(net.minecraft.util.EnumFacing) EntityLivingBase(net.minecraft.entity.EntityLivingBase) BlockPos(net.minecraft.util.math.BlockPos)

Example 74 with BlockPos

use of net.minecraft.util.math.BlockPos in project ImmersiveEngineering by BluSunrize.

the class TileEntityRazorWire method renderWall.

private boolean renderWall(boolean left) {
    EnumFacing dir = left ? facing.rotateY() : facing.rotateYCCW();
    BlockPos neighbourPos = getPos().offset(dir, -1);
    if (!worldObj.isBlockLoaded(neighbourPos))
        return true;
    if (worldObj.getTileEntity(neighbourPos) instanceof TileEntityRazorWire)
        return false;
    IBlockState neighbour = worldObj.getBlockState(neighbourPos);
    return !neighbour.isSideSolid(worldObj, neighbourPos, dir);
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) EnumFacing(net.minecraft.util.EnumFacing) BlockPos(net.minecraft.util.math.BlockPos)

Example 75 with BlockPos

use of net.minecraft.util.math.BlockPos 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)

Aggregations

BlockPos (net.minecraft.util.math.BlockPos)864 IBlockState (net.minecraft.block.state.IBlockState)220 TileEntity (net.minecraft.tileentity.TileEntity)135 Block (net.minecraft.block.Block)103 EnumFacing (net.minecraft.util.EnumFacing)95 ItemStack (net.minecraft.item.ItemStack)81 World (net.minecraft.world.World)77 EntityPlayer (net.minecraft.entity.player.EntityPlayer)54 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)46 Vec3d (net.minecraft.util.math.Vec3d)44 NotNull (org.jetbrains.annotations.NotNull)44 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)38 AxisAlignedBB (net.minecraft.util.math.AxisAlignedBB)31 Entity (net.minecraft.entity.Entity)30 PhysicsWrapperEntity (ValkyrienWarfareBase.PhysicsManagement.PhysicsWrapperEntity)29 Nullable (org.jetbrains.annotations.Nullable)26 ArrayList (java.util.ArrayList)23 EntityLivingBase (net.minecraft.entity.EntityLivingBase)23 WorldServer (net.minecraft.world.WorldServer)23 TextComponentString (net.minecraft.util.text.TextComponentString)22