Search in sources :

Example 96 with BlockPos

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

the class TileEntityFloodlight method readCustomNBT.

@Override
public void readCustomNBT(NBTTagCompound nbt, boolean descPacket) {
    super.readCustomNBT(nbt, descPacket);
    active = nbt.getBoolean("active");
    energyStorage = nbt.getInteger("energy");
    redstoneControlInverted = nbt.getBoolean("redstoneControlInverted");
    facing = EnumFacing.getFront(nbt.getInteger("facing"));
    side = EnumFacing.getFront(nbt.getInteger("side"));
    rotY = nbt.getFloat("rotY");
    rotX = nbt.getFloat("rotX");
    int lightAmount = nbt.getInteger("lightAmount");
    fakeLights.clear();
    for (int i = 0; i < lightAmount; i++) {
        int[] icc = nbt.getIntArray("fakeLight_" + i);
        fakeLights.add(new BlockPos(icc[0], icc[1], icc[2]));
    }
    if (FMLCommonHandler.instance().getEffectiveSide() == Side.CLIENT && worldObj != null)
        this.markContainingBlockForUpdate(null);
    if (descPacket) {
        controllingComputers = nbt.getBoolean("computerControlled") ? 1 : 0;
        computerOn = nbt.getBoolean("computerOn");
    }
}
Also used : BlockPos(net.minecraft.util.math.BlockPos)

Example 97 with BlockPos

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

the class TileEntityFloodlight method updateFakeLights.

public void updateFakeLights(boolean deleteOld, boolean genNew) {
    Iterator<BlockPos> it = this.fakeLights.iterator();
    ArrayList<BlockPos> tempRemove = new ArrayList<BlockPos>();
    while (it.hasNext()) {
        BlockPos cc = it.next();
        TileEntity te = worldObj.getTileEntity(cc);
        if (te instanceof TileEntityFakeLight) {
            if (deleteOld)
                tempRemove.add(cc);
        } else
            it.remove();
    }
    if (genNew) {
        float angle = (float) (facing == EnumFacing.NORTH ? 180 : facing == EnumFacing.EAST ? 90 : facing == EnumFacing.WEST ? -90 : 0);
        float yRotation = rotY;
        double angleX = Math.toRadians(rotX);
        Vec3d[] rays = { /*Straight*/
        new Vec3d(0, 0, 1), /*U,D,L,R*/
        new Vec3d(0, 0, 1), new Vec3d(0, 0, 1), new Vec3d(0, 0, 1), new Vec3d(0, 0, 1), /*Intermediate*/
        new Vec3d(0, 0, 1), new Vec3d(0, 0, 1), new Vec3d(0, 0, 1), new Vec3d(0, 0, 1), /*Diagonal*/
        new Vec3d(0, 0, 1), new Vec3d(0, 0, 1), new Vec3d(0, 0, 1), new Vec3d(0, 0, 1) };
        Matrix4 mat = new Matrix4();
        if (side == EnumFacing.DOWN)
            mat.scale(1, -1, 1);
        else if (side != EnumFacing.UP) {
            angle = facing == EnumFacing.DOWN ? 180 : facing == EnumFacing.NORTH ? -90 : facing == EnumFacing.SOUTH ? 90 : angle;
            if (side.getAxis() == Axis.X) {
                mat.rotate(Math.PI / 2, -1, 0, 0);
                mat.rotate(Math.PI / 2, 0, 0, -side.getAxisDirection().getOffset());
            } else {
                mat.rotate(Math.PI / 2, -1, 0, 0);
                if (//I dunno why south is giving me so much trouble, but this works, so who cares
                side == EnumFacing.SOUTH) {
                    mat.rotate(Math.PI, 0, 0, 1);
                    if (facing.getAxis() == Axis.X)
                        angle = -angle;
                }
            }
        }
        double angleY = Math.toRadians(angle + yRotation);
        mat.rotate(angleY, 0, 1, 0);
        mat.rotate(-angleX, 1, 0, 0);
        rays[0] = mat.apply(rays[0]);
        mat.rotate(Math.PI / 8, 0, 1, 0);
        rays[1] = mat.apply(rays[1]);
        mat.rotate(-Math.PI / 16, 0, 1, 0);
        rays[5] = mat.apply(rays[5]);
        mat.rotate(-Math.PI / 8, 0, 1, 0);
        rays[6] = mat.apply(rays[6]);
        mat.rotate(-Math.PI / 16, 0, 1, 0);
        rays[2] = mat.apply(rays[2]);
        mat.rotate(Math.PI / 8, 0, 1, 0);
        mat.rotate(Math.PI / 8, 1, 0, 0);
        rays[3] = mat.apply(rays[3]);
        mat.rotate(-Math.PI / 16, 1, 0, 0);
        rays[7] = mat.apply(rays[7]);
        mat.rotate(-Math.PI / 8, 1, 0, 0);
        rays[8] = mat.apply(rays[8]);
        mat.rotate(-Math.PI / 16, 1, 0, 0);
        rays[4] = mat.apply(rays[4]);
        mat.rotate(Math.PI / 8, 1, 0, 0);
        mat.rotate(Math.PI / 16, 1, 0, 0);
        mat.rotate(Math.PI / 16, 0, 1, 0);
        rays[9] = mat.apply(rays[9]);
        mat.rotate(-Math.PI / 8, 0, 1, 0);
        rays[10] = mat.apply(rays[10]);
        mat.rotate(-Math.PI / 8, 1, 0, 0);
        rays[11] = mat.apply(rays[11]);
        mat.rotate(Math.PI / 8, 0, 1, 0);
        rays[12] = mat.apply(rays[12]);
        for (int ray = 0; ray < rays.length; ray++) {
            int offset = ray == 0 ? 0 : ray < 4 ? 3 : 1;
            placeLightAlongVector(rays[ray], offset, tempRemove);
        }
    }
    this.lightsToBeRemoved.addAll(tempRemove);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) TileEntityFakeLight(blusunrize.immersiveengineering.common.blocks.BlockFakeLight.TileEntityFakeLight) ArrayList(java.util.ArrayList) BlockPos(net.minecraft.util.math.BlockPos) Vec3d(net.minecraft.util.math.Vec3d) Matrix4(blusunrize.immersiveengineering.common.util.chickenbones.Matrix4)

Example 98 with BlockPos

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

the class TileEntityFloodlight method writeCustomNBT.

@Override
public void writeCustomNBT(NBTTagCompound nbt, boolean descPacket) {
    super.writeCustomNBT(nbt, descPacket);
    nbt.setBoolean("active", active);
    nbt.setInteger("energyStorage", energyStorage);
    nbt.setBoolean("redstoneControlInverted", redstoneControlInverted);
    nbt.setInteger("facing", facing.ordinal());
    nbt.setInteger("side", side.ordinal());
    nbt.setFloat("rotY", rotY);
    nbt.setFloat("rotX", rotX);
    nbt.setInteger("lightAmount", fakeLights.size());
    for (int i = 0; i < fakeLights.size(); i++) {
        BlockPos cc = fakeLights.get(i);
        nbt.setIntArray("fakeLight_" + i, new int[] { cc.getX(), cc.getY(), cc.getZ() });
    }
    if (descPacket) {
        nbt.setBoolean("computerControlled", controllingComputers > 0);
        nbt.setBoolean("computerOn", computerOn);
    }
}
Also used : BlockPos(net.minecraft.util.math.BlockPos)

Example 99 with BlockPos

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

the class TileEntityExcavator method update.

@Override
public void update() {
    super.update();
    if (isDummy())
        return;
    if (!worldObj.isRemote) {
        BlockPos wheelPos = this.getBlockPosForPos(31);
        TileEntity center = worldObj.getTileEntity(wheelPos);
        if (center instanceof TileEntityBucketWheel) {
            float rot = 0;
            int target = -1;
            TileEntityBucketWheel wheel = ((TileEntityBucketWheel) center);
            EnumFacing fRot = this.facing.rotateYCCW();
            if (wheel.facing == fRot) {
                if (active != wheel.active)
                    worldObj.addBlockEvent(wheel.getPos(), wheel.getBlockType(), 0, active ? 1 : 0);
                rot = wheel.rotation;
                if (rot % 45 > 40)
                    target = Math.round(rot / 360f * 8) % 8;
            }
            if (wheel.facing != fRot || wheel.mirrored != this.mirrored) {
                for (int h = -3; h <= 3; h++) for (int w = -3; w <= 3; w++) {
                    TileEntity te = worldObj.getTileEntity(wheelPos.add(0, h, 0).offset(facing, w));
                    if (te instanceof TileEntityBucketWheel) {
                        ((TileEntityBucketWheel) te).facing = fRot;
                        ((TileEntityBucketWheel) te).mirrored = this.mirrored;
                        te.markDirty();
                        ((TileEntityBucketWheel) te).markContainingBlockForUpdate(null);
                        worldObj.addBlockEvent(te.getPos(), te.getBlockType(), 255, 0);
                    }
                }
            }
            if (!isRSDisabled()) {
                ExcavatorHandler.MineralMix mineral = ExcavatorHandler.getRandomMineral(worldObj, wheelPos.getX() >> 4, wheelPos.getZ() >> 4);
                int consumed = IEConfig.Machines.excavator_consumption;
                int extracted = energyStorage.extractEnergy(consumed, true);
                if (extracted >= consumed) {
                    energyStorage.extractEnergy(consumed, false);
                    active = true;
                    if (target >= 0 && target < 8) {
                        int targetDown = (target + 4) % 8;
                        NBTTagCompound packet = new NBTTagCompound();
                        if (wheel.digStacks[targetDown] == null) {
                            ItemStack blocking = this.digBlocksInTheWay(wheel);
                            BlockPos lowGroundPos = wheelPos.add(0, -5, 0);
                            if (blocking != null) {
                                wheel.digStacks[targetDown] = blocking;
                                wheel.markDirty();
                                this.markContainingBlockForUpdate(null);
                            } else if (mineral != null && !worldObj.isAirBlock(lowGroundPos.offset(facing, -2)) && !worldObj.isAirBlock(lowGroundPos.offset(facing, 2)) && !worldObj.isAirBlock(lowGroundPos.offset(facing, -1)) && !worldObj.isAirBlock(lowGroundPos.offset(facing, 1)) && !worldObj.isAirBlock(lowGroundPos)) {
                                ItemStack ore = mineral.getRandomOre(worldObj.rand);
                                float configChance = worldObj.rand.nextFloat();
                                float failChance = worldObj.rand.nextFloat();
                                if (ore != null && configChance > IEConfig.Machines.excavator_fail_chance && failChance > mineral.failChance) {
                                    wheel.digStacks[targetDown] = ore;
                                    wheel.markDirty();
                                    this.markContainingBlockForUpdate(null);
                                }
                                ExcavatorHandler.depleteMinerals(worldObj, wheelPos.getX() >> 4, wheelPos.getZ() >> 4);
                            }
                            if (wheel.digStacks[targetDown] != null) {
                                packet.setInteger("fill", targetDown);
                                packet.setTag("fillStack", wheel.digStacks[targetDown].writeToNBT(new NBTTagCompound()));
                            }
                        }
                        if (wheel.digStacks[target] != null) {
                            this.doProcessOutput(wheel.digStacks[target].copy());
                            Block b = Block.getBlockFromItem(wheel.digStacks[target].getItem());
                            if (b != null && b != Blocks.AIR)
                                wheel.particleStack = wheel.digStacks[target].copy();
                            wheel.digStacks[target] = null;
                            wheel.markDirty();
                            this.markContainingBlockForUpdate(null);
                            packet.setInteger("empty", target);
                        }
                        if (!packet.hasNoTags())
                            ImmersiveEngineering.packetHandler.sendToAll(new MessageTileSync(wheel, packet));
                    }
                } else if (active)
                    active = false;
            } else if (active) {
                active = false;
            //					update = true;
            }
        //				if(update)
        //				{
        //					this.markDirty();
        //					worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
        //				}
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ExcavatorHandler(blusunrize.immersiveengineering.api.tool.ExcavatorHandler) EnumFacing(net.minecraft.util.EnumFacing) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) MessageTileSync(blusunrize.immersiveengineering.common.util.network.MessageTileSync)

Example 100 with BlockPos

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

the class TileEntityLightningrod method update.

@Override
public void update() {
    if (!worldObj.isRemote && formed && pos == 13) {
        if (energyStorage.getEnergyStored() > 0) {
            TileEntity tileEntity;
            for (EnumFacing f : EnumFacing.HORIZONTALS) {
                tileEntity = worldObj.getTileEntity(getPos().offset(f, 2));
                if (tileEntity instanceof IFluxReceiver) {
                    IFluxReceiver ifr = (IFluxReceiver) tileEntity;
                    int accepted = ifr.receiveEnergy(f.getOpposite(), energyStorage.getEnergyStored(), true);
                    int extracted = energyStorage.extractEnergy(accepted, false);
                    ifr.receiveEnergy(f.getOpposite(), extracted, false);
                }
            }
        }
        if (worldObj.getTotalWorldTime() % 256 == ((getPos().getX() ^ getPos().getZ()) & 255))
            fenceNet = null;
        if (fenceNet == null)
            fenceNet = this.getFenceNet();
        if (fenceNet != null && worldObj.getTotalWorldTime() % 128 == ((getPos().getX() ^ getPos().getZ()) & 127) && (worldObj.isThundering() || (worldObj.isRaining() && worldObj.rand.nextInt(10) == 0))) {
            int i = this.height + this.fenceNet.size();
            if (worldObj.rand.nextInt(4096 * worldObj.getHeight()) < i * (getPos().getY() + i)) {
                this.energyStorage.setEnergy(IEConfig.Machines.lightning_output);
                BlockPos pos = fenceNet.get(worldObj.rand.nextInt(fenceNet.size()));
                EntityLightningBolt entityLightningBolt = new EntityLightningBolt(worldObj, pos.getX(), pos.getY(), pos.getZ(), true);
                worldObj.addWeatherEffect(entityLightningBolt);
                worldObj.spawnEntityInWorld(entityLightningBolt);
            }
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) EnumFacing(net.minecraft.util.EnumFacing) IFluxReceiver(blusunrize.immersiveengineering.api.energy.immersiveflux.IFluxReceiver) BlockPos(net.minecraft.util.math.BlockPos) EntityLightningBolt(net.minecraft.entity.effect.EntityLightningBolt)

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