Search in sources :

Example 66 with BlockPos

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

the class TileEntityArcFurnace method update.

@Override
public void update() {
    super.update();
    if (!worldObj.isRemote && !isDummy() && !isRSDisabled() && energyStorage.getEnergyStored() > 0) {
        if (this.tickedProcesses > 0)
            for (int i = 23; i < 26; i++) if (this.inventory[i].attemptDamageItem(1, worldObj.rand)) {
                this.inventory[i] = null;
            //						updateClient = true;
            //						update = true;
            }
        if (this.processQueue.size() < this.getProcessQueueMaxLength()) {
            Set<Integer> usedInvSlots = new HashSet<Integer>();
            //			final int[] usedInvSlots = new int[8];
            for (MultiblockProcess<ArcFurnaceRecipe> process : processQueue) if (process instanceof MultiblockProcessInMachine)
                for (int i : ((MultiblockProcessInMachine<ArcFurnaceRecipe>) process).inputSlots) usedInvSlots.add(i);
            //			Integer[] preferredSlots = new Integer[]{0,1,2,3,4,5,6,7};
            //			Arrays.sort(preferredSlots, 0,8, new Comparator<Integer>(){
            //				@Override
            //				public int compare(Integer arg0, Integer arg1)
            //				{
            //					return Integer.compare(usedInvSlots[arg0],usedInvSlots[arg1]);
            //				}});
            ItemStack[] additives = new ItemStack[4];
            for (int i = 0; i < 4; i++) additives[i] = (inventory[12 + i] != null ? inventory[12 + i].copy() : null);
            for (int slot = 0; slot < 12; slot++) if (!usedInvSlots.contains(slot)) {
                ItemStack stack = this.getInventory()[slot];
                //				}
                if (stack != null && stack.stackSize > 0) {
                    ArcFurnaceRecipe recipe = ArcFurnaceRecipe.findRecipe(stack, additives);
                    if (recipe != null) {
                        MultiblockProcessArcFurnace process = new MultiblockProcessArcFurnace(recipe, slot, 12, 13, 14, 15);
                        if (this.addProcessToQueue(process, true)) {
                            this.addProcessToQueue(process, false);
                            usedInvSlots.add(slot);
                        //							update = true;
                        }
                    }
                }
            }
        }
        if (worldObj.getTotalWorldTime() % 8 == 0) {
            BlockPos outputPos = this.getBlockPosForPos(2).offset(facing, -1);
            TileEntity outputTile = this.worldObj.getTileEntity(outputPos);
            if (outputTile != null)
                for (int j = 16; j < 22; j++) if (inventory[j] != null) {
                    ItemStack stack = Utils.copyStackWithAmount(inventory[j], 1);
                    stack = Utils.insertStackIntoInventory(outputTile, stack, facing.getOpposite());
                    if (stack == null)
                        if ((--this.inventory[j].stackSize) <= 0)
                            this.inventory[j] = null;
                }
            outputPos = this.getBlockPosForPos(22).offset(facing);
            outputTile = this.worldObj.getTileEntity(outputPos);
            if (outputTile != null)
                if (inventory[22] != null) {
                    int out = Math.min(inventory[22].stackSize, 16);
                    ItemStack stack = Utils.copyStackWithAmount(inventory[22], out);
                    stack = Utils.insertStackIntoInventory(outputTile, stack, facing);
                    if (stack != null)
                        out -= stack.stackSize;
                    if ((this.inventory[22].stackSize -= out) <= 0)
                        this.inventory[22] = null;
                }
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ArcFurnaceRecipe(blusunrize.immersiveengineering.api.crafting.ArcFurnaceRecipe) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) HashSet(java.util.HashSet)

Example 67 with BlockPos

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

the class TileEntityArcFurnace method doProcessOutput.

@Override
public void doProcessOutput(ItemStack output) {
    BlockPos pos = getPos().add(0, -1, 0).offset(facing, -2);
    TileEntity inventoryTile = this.worldObj.getTileEntity(pos);
    if (inventoryTile != null)
        output = Utils.insertStackIntoInventory(inventoryTile, output, facing.getOpposite());
    if (output != null)
        Utils.dropStackAtPos(worldObj, pos, output, facing);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) BlockPos(net.minecraft.util.math.BlockPos)

Example 68 with BlockPos

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

the class BlockConnector method onBlockPlaced.

@Override
public IBlockState onBlockPlaced(World world, BlockPos pos, EnumFacing facing, float hitX, float hitY, float hitZ, int meta, EntityLivingBase placer) {
    IBlockState ret = super.onBlockPlaced(world, pos, facing, hitX, hitY, hitZ, meta, placer);
    if (meta == BlockTypes_Connector.TRANSFORMER.getMeta()) {
        BlockPos pos2 = pos.offset(facing, -1);
        IBlockState placedAgainst = world.getBlockState(pos2);
        Block block = placedAgainst.getBlock();
        if (block instanceof IPostBlock && ((IPostBlock) block).canConnectTransformer(world, pos2))
            ret = ret.withProperty(IEProperties.BOOLEANS[1], true);
        TileEntity tile = world.getTileEntity(pos2);
        if (tile instanceof IPostBlock && ((IPostBlock) tile).canConnectTransformer(world, pos2))
            ret = ret.withProperty(IEProperties.BOOLEANS[1], true);
    }
    return ret;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IBlockState(net.minecraft.block.state.IBlockState) IPostBlock(blusunrize.immersiveengineering.api.IPostBlock) Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) IPostBlock(blusunrize.immersiveengineering.api.IPostBlock)

Example 69 with BlockPos

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

the class TileEntitySilo method disassemble.

@Override
public void disassemble() {
    super.invalidate();
    if (formed && !worldObj.isRemote) {
        BlockPos startPos = this.getPos().add(-offset[0], -offset[1], -offset[2]);
        if (!(offset[0] == 0 && offset[1] == 0 && offset[2] == 0) && !(worldObj.getTileEntity(startPos) instanceof TileEntitySilo))
            return;
        for (int yy = 0; yy <= 6; yy++) for (int xx = -1; xx <= 1; xx++) for (int zz = -1; zz <= 1; zz++) {
            ItemStack s = null;
            TileEntity te = worldObj.getTileEntity(startPos.add(xx, yy, zz));
            if (te instanceof TileEntitySilo) {
                s = ((TileEntitySilo) te).getOriginalBlock();
                ((TileEntitySilo) te).formed = false;
            }
            if (startPos.add(xx, yy, zz).equals(getPos()))
                s = this.getOriginalBlock();
            if (s != null && Block.getBlockFromItem(s.getItem()) != null) {
                if (startPos.add(xx, yy, zz).equals(getPos()))
                    worldObj.spawnEntityInWorld(new EntityItem(worldObj, getPos().getX() + .5, getPos().getY() + .5, getPos().getZ() + .5, s));
                else {
                    if (Block.getBlockFromItem(s.getItem()) == IEContent.blockMetalMultiblock)
                        worldObj.setBlockToAir(startPos.add(xx, yy, zz));
                    worldObj.setBlockState(startPos.add(xx, yy, zz), Block.getBlockFromItem(s.getItem()).getStateFromMeta(s.getItemDamage()));
                }
            }
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) EntityItem(net.minecraft.entity.item.EntityItem) IComparatorOverride(blusunrize.immersiveengineering.common.blocks.IEBlockInterfaces.IComparatorOverride)

Example 70 with BlockPos

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

the class TileEntitySqueezer method doProcessOutput.

@Override
public void doProcessOutput(ItemStack output) {
    BlockPos pos = getPos().offset(facing, 2);
    TileEntity inventoryTile = this.worldObj.getTileEntity(pos);
    if (inventoryTile != null)
        output = Utils.insertStackIntoInventory(inventoryTile, output, facing.getOpposite());
    if (output != null)
        Utils.dropStackAtPos(worldObj, pos, output, facing);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) BlockPos(net.minecraft.util.math.BlockPos)

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