Search in sources :

Example 51 with TileEntity

use of net.minecraft.tileentity.TileEntity in project LogisticsPipes by RS485.

the class TEControl method validate.

public static void validate(final TileEntity tile) {
    final World world = tile.getWorldObj();
    if (world == null) {
        return;
    }
    if (!MainProxy.isServer(world)) {
        return;
    }
    if (tile.getClass().getName().startsWith("net.minecraft.tileentity")) {
        return;
    }
    final DoubleCoordinates pos = new DoubleCoordinates(tile);
    if (pos.getXInt() == 0 && pos.getYInt() <= 0 && pos.getZInt() == 0) {
        return;
    }
    if (SimpleServiceLocator.pipeInformationManager.isPipe(tile, false, ConnectionPipeType.UNDEFINED) || SimpleServiceLocator.specialtileconnection.isType(tile)) {
        ((ILPTEInformation) tile).setObject(new LPTileEntityObject());
        ((ILPTEInformation) tile).getObject().initialised = LPTickHandler.getWorldInfo(world).getWorldTick();
        if (((ILPTEInformation) tile).getObject().initialised < 5) {
            return;
        }
        QueuedTasks.queueTask(() -> {
            if (!SimpleServiceLocator.pipeInformationManager.isPipe(tile, true, ConnectionPipeType.UNDEFINED)) {
                return null;
            }
            for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
                DoubleCoordinates newPos = CoordinateUtils.sum(pos, dir);
                if (!newPos.blockExists(world)) {
                    continue;
                }
                TileEntity nextTile = newPos.getTileEntity(world);
                if (nextTile != null && ((ILPTEInformation) nextTile).getObject() != null) {
                    if (SimpleServiceLocator.pipeInformationManager.isItemPipe(nextTile)) {
                        SimpleServiceLocator.pipeInformationManager.getInformationProviderFor(nextTile).refreshTileCacheOnSide(dir.getOpposite());
                    }
                    if (SimpleServiceLocator.pipeInformationManager.isItemPipe(tile)) {
                        SimpleServiceLocator.pipeInformationManager.getInformationProviderFor(tile).refreshTileCacheOnSide(dir);
                        SimpleServiceLocator.pipeInformationManager.getInformationProviderFor(tile).refreshTileCacheOnSide(dir.getOpposite());
                    }
                    for (ITileEntityChangeListener listener : new ArrayList<>(((ILPTEInformation) nextTile).getObject().changeListeners)) {
                        listener.pipeAdded(pos, dir.getOpposite());
                    }
                }
            }
            return null;
        });
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ILPTEInformation(logisticspipes.asm.te.ILPTEInformation) LPTileEntityObject(logisticspipes.asm.te.LPTileEntityObject) ITileEntityChangeListener(logisticspipes.asm.te.ITileEntityChangeListener) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) ArrayList(java.util.ArrayList) World(net.minecraft.world.World) DoubleCoordinates(network.rs485.logisticspipes.world.DoubleCoordinates)

Example 52 with TileEntity

use of net.minecraft.tileentity.TileEntity in project LogisticsPipes by RS485.

the class TEControl method invalidate.

public static void invalidate(final TileEntity tile) {
    final World world = tile.getWorldObj();
    if (world == null) {
        return;
    }
    if (!MainProxy.isServer(world)) {
        return;
    }
    if (tile instanceof LogisticsTileGenericPipe && ((LogisticsTileGenericPipe) tile).isRoutingPipe()) {
        return;
    }
    if (((ILPTEInformation) tile).getObject() != null) {
        QueuedTasks.queueTask(() -> {
            DoubleCoordinates pos = new DoubleCoordinates(tile);
            for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
                DoubleCoordinates newPos = CoordinateUtils.sum(pos, dir);
                if (!newPos.blockExists(world)) {
                    continue;
                }
                TileEntity nextTile = newPos.getTileEntity(world);
                if (nextTile != null && ((ILPTEInformation) nextTile).getObject() != null) {
                    if (SimpleServiceLocator.pipeInformationManager.isItemPipe(nextTile)) {
                        SimpleServiceLocator.pipeInformationManager.getInformationProviderFor(nextTile).refreshTileCacheOnSide(dir.getOpposite());
                    }
                }
            }
            for (ITileEntityChangeListener listener : new ArrayList<>(((ILPTEInformation) tile).getObject().changeListeners)) {
                listener.pipeRemoved(pos);
            }
            return null;
        });
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) ILPTEInformation(logisticspipes.asm.te.ILPTEInformation) ITileEntityChangeListener(logisticspipes.asm.te.ITileEntityChangeListener) LogisticsTileGenericPipe(logisticspipes.pipes.basic.LogisticsTileGenericPipe) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) ArrayList(java.util.ArrayList) World(net.minecraft.world.World) DoubleCoordinates(network.rs485.logisticspipes.world.DoubleCoordinates)

Example 53 with TileEntity

use of net.minecraft.tileentity.TileEntity in project SimplyJetpacks by Tonius.

the class ItemJetpackFueller method onUsingTick.

@Override
public void onUsingTick(ItemStack itemStack, EntityPlayer player, int count) {
    MovingObjectPosition blockPos = BlockHelper.getCurrentMovingObjectPosition(player, true);
    if (blockPos == null || blockPos.sideHit < 0) {
        player.setItemInUse(null, 1);
    } else {
        player.setItemInUse(itemStack, this.getMaxItemUseDuration(itemStack));
        if (player.worldObj.isRemote) {
            return;
        }
        ItemStack chestplate = player.getCurrentArmor(2);
        if (chestplate == null || !(chestplate.getItem() instanceof ItemPack)) {
            return;
        }
        ItemPack packItem = (ItemPack) chestplate.getItem();
        PackBase pack = packItem.getPack(chestplate);
        if (pack == null) {
            return;
        }
        FuelType fuelType = pack.fuelType;
        ForgeDirection pullSide = ForgeDirection.values()[blockPos.sideHit];
        player.worldObj.getBlock(blockPos.blockX, blockPos.blockY, blockPos.blockZ);
        TileEntity tile = player.worldObj.getTileEntity(blockPos.blockX, blockPos.blockY, blockPos.blockZ);
        int toPull = Math.min(pack.fuelPerTickIn, packItem.getMaxFuelStored(chestplate) - packItem.getFuelStored(chestplate));
        int pulled = 0;
        if (fuelType == FuelType.ENERGY && tile instanceof IEnergyProvider) {
            IEnergyProvider energyTile = (IEnergyProvider) tile;
            pulled = energyTile.extractEnergy(pullSide, toPull, false);
        } else if (fuelType == FuelType.FLUID) {
            if (tile instanceof IFluidHandler) {
                IFluidHandler fluidTile = (IFluidHandler) tile;
                FluidStack fluid = fluidTile.drain(pullSide, toPull, false);
                if (fluid == null || !fluid.getFluid().getName().equals(pack.fuelFluid)) {
                    return;
                }
                fluid = fluidTile.drain(pullSide, toPull, true);
                pulled = fluid.amount;
            }
        }
        if (pulled > 0) {
            packItem.addFuel(chestplate, pulled, false);
        }
    }
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) MovingObjectPosition(net.minecraft.util.MovingObjectPosition) IEnergyProvider(cofh.api.energy.IEnergyProvider) FluidStack(net.minecraftforge.fluids.FluidStack) PackBase(tonius.simplyjetpacks.item.meta.PackBase) ForgeDirection(net.minecraftforge.common.util.ForgeDirection) ItemStack(net.minecraft.item.ItemStack) FuelType(tonius.simplyjetpacks.setup.FuelType) IFluidHandler(net.minecraftforge.fluids.IFluidHandler)

Example 54 with TileEntity

use of net.minecraft.tileentity.TileEntity in project SimplyJetpacks by Tonius.

the class ItemMysteriousPotato method onItemUse.

@Override
public boolean onItemUse(ItemStack itemStack, EntityPlayer player, World world, int x, int y, int z, int meta, float hitX, float hitY, float hitZ) {
    if (!world.isRemote) {
        TileEntity tile = world.getTileEntity(x, y, z);
        if (tile instanceof TileEntityMobSpawner) {
            NBTTagCompound tag = new NBTTagCompound();
            tile.writeToNBT(tag);
            tag.setString("EntityId", "Zombie");
            NBTTagList spawnPotentials = new NBTTagList();
            NBTTagCompound zombieSpawn = new NBTTagCompound();
            zombieSpawn.setString("Type", "Zombie");
            zombieSpawn.setInteger("Weight", 1);
            NBTTagCompound zombieSpawnProperties = new NBTTagCompound();
            zombieSpawnProperties.setString("id", "Zombie");
            NBTTagList equipment = new NBTTagList();
            equipment.appendTag(new NBTTagCompound());
            equipment.appendTag(new NBTTagCompound());
            equipment.appendTag(new NBTTagCompound());
            equipment.appendTag(ModItems.jetpackPotato.writeToNBT(new NBTTagCompound()));
            zombieSpawnProperties.setTag("Equipment", equipment);
            NBTTagList dropChances = new NBTTagList();
            for (int i = 0; i <= 4; i++) {
                dropChances.appendTag(new NBTTagFloat(0.0F));
            }
            zombieSpawnProperties.setTag("DropChances", dropChances);
            zombieSpawn.setTag("Properties", zombieSpawnProperties);
            spawnPotentials.appendTag(zombieSpawn);
            tag.setTag("SpawnPotentials", spawnPotentials);
            tag.setShort("SpawnCount", (short) 2);
            tag.setShort("SpawnRange", (short) 8);
            tag.setShort("Delay", (short) -1);
            tag.setShort("MinSpawnDelay", (short) 30);
            tag.setShort("MaxSpawnDelay", (short) 60);
            tag.setShort("MaxNearbyEntities", (short) 10);
            tag.setShort("RequiredPlayerRange", (short) 96);
            tile.readFromNBT(tag);
        }
    }
    return true;
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) NBTTagList(net.minecraft.nbt.NBTTagList) NBTTagFloat(net.minecraft.nbt.NBTTagFloat) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) TileEntityMobSpawner(net.minecraft.tileentity.TileEntityMobSpawner)

Example 55 with TileEntity

use of net.minecraft.tileentity.TileEntity in project PneumaticCraft by MineMaarten.

the class BlockTrackUpgradeHandler method update.

@Override
public void update(EntityPlayer player, int rangeUpgrades) {
    ticksExisted++;
    SearchUpgradeHandler searchHandler = HUDHandler.instance().getSpecificRenderer(SearchUpgradeHandler.class);
    if (ticksExisted % updateInterval == 0) {
        int timeTaken = (int) accTime / updateInterval;
        updateInterval = updateInterval * timeTaken / MAX_TIME;
        if (updateInterval <= 1)
            updateInterval = 2;
        accTime = 0;
        ticksExisted = 0;
    }
    accTime -= System.currentTimeMillis();
    int blockTrackRange = BLOCK_TRACKING_RANGE + Math.min(rangeUpgrades, 5) * PneumaticValues.RANGE_UPGRADE_HELMET_RANGE_INCREASE;
    int baseX = (int) Math.floor(player.posX) - blockTrackRange;
    int baseY = (int) Math.floor(player.posY) - blockTrackRange + blockTrackRange * (ticksExisted % updateInterval) / (updateInterval / 2);
    int maxY = (int) Math.floor(player.posY) - blockTrackRange + blockTrackRange * (ticksExisted % updateInterval + 1) / (updateInterval / 2);
    baseY = MathHelper.clamp_int(baseY, 0, 255);
    maxY = MathHelper.clamp_int(maxY, 0, 255);
    int baseZ = (int) Math.floor(player.posZ) - blockTrackRange;
    IBlockAccess chunkCache = new ChunkCache(player.worldObj, baseX, baseY, baseZ, baseX + 2 * blockTrackRange, maxY, baseZ + 2 * blockTrackRange, 0);
    for (int i = baseX; i <= baseX + 2 * blockTrackRange; i++) {
        for (int j = baseY; j < maxY; j++) {
            for (int k = baseZ; k <= baseZ + 2 * blockTrackRange; k++) {
                if (player.getDistance(i, j, k) > blockTrackRange)
                    continue;
                TileEntity te = chunkCache.getTileEntity(i, j, k);
                if (MinecraftForge.EVENT_BUS.post(new BlockTrackEvent(player.worldObj, i, j, k, te)))
                    continue;
                if (searchHandler != null && te instanceof IInventory) {
                    searchHandler.checkInventoryForItems(te);
                }
                List<IBlockTrackEntry> entries = BlockTrackEntryList.instance.getEntriesForCoordinate(chunkCache, i, j, k, te);
                if (entries.isEmpty())
                    continue;
                boolean inList = false;
                for (int l = 0; l < blockTargets.size(); l++) {
                    if (blockTargets.get(l).isSameTarget(player.worldObj, i, j, k)) {
                        inList = true;
                        // cancel lost targets
                        blockTargets.get(l).ticksExisted = Math.abs(blockTargets.get(l).ticksExisted);
                        blockTargets.get(l).setTileEntity(te);
                        break;
                    }
                }
                if (!inList) {
                    boolean sentUpdate = false;
                    for (IBlockTrackEntry entry : entries) {
                        if (entry.shouldBeUpdatedFromServer(te)) {
                            if (!sentUpdate) {
                                NetworkHandler.sendToServer(new PacketDescriptionPacketRequest(i, j, k));
                                sentUpdate = true;
                            }
                        }
                    }
                    addBlockTarget(new RenderBlockTarget(player.worldObj, player, i, j, k, te, this));
                    for (IBlockTrackEntry entry : entries) {
                        if (countBlockTrackersOfType(entry) == entry.spamThreshold() + 1) {
                            HUDHandler.instance().addMessage(new ArmorMessage(I18n.format("blockTracker.message.stopSpam", I18n.format(entry.getEntryName())), new ArrayList<String>(), 60, 0x7700AA00));
                        }
                    }
                }
            }
        }
    }
    accTime += System.currentTimeMillis();
    for (int i = 0; i < blockTargets.size(); i++) {
        RenderBlockTarget blockTarget = blockTargets.get(i);
        boolean wasNegative = blockTarget.ticksExisted < 0;
        blockTarget.ticksExisted += CommonHUDHandler.getHandlerForPlayer(player).getSpeedFromUpgrades();
        if (blockTarget.ticksExisted >= 0 && wasNegative)
            blockTarget.ticksExisted = -1;
        blockTarget.update();
        if (blockTarget.getDistanceToEntity(player) > blockTrackRange + 5 || !blockTarget.isTargetStillValid()) {
            if (blockTarget.ticksExisted > 0) {
                blockTarget.ticksExisted = -60;
            } else if (blockTarget.ticksExisted == -1) {
                removeBlockTarget(i);
                i--;
            }
        }
    }
    List<String> textList = new ArrayList<String>();
    RenderBlockTarget focusedTarget = null;
    for (RenderBlockTarget blockTarget : blockTargets) {
        if (blockTarget.isInitialized() && blockTarget.isPlayerLooking()) {
            focusedTarget = blockTarget;
            break;
        }
    }
    if (focusedTarget != null) {
        blockTrackInfo.setTitle(focusedTarget.stat.getTitle());
        textList.addAll(focusedTarget.textList);
    } else {
        blockTrackInfo.setTitle("Current tracked blocks:");
        if (blockTypeCount == null || ticksExisted % 40 == 0) {
            blockTypeCount = new int[BlockTrackEntryList.instance.trackList.size()];
            for (RenderBlockTarget target : blockTargets) {
                for (IBlockTrackEntry validEntry : target.getApplicableEntries()) {
                    blockTypeCount[BlockTrackEntryList.instance.trackList.indexOf(validEntry)]++;
                }
            }
        }
        for (int i = 0; i < blockTypeCount.length; i++) {
            if (blockTypeCount[i] > 0) {
                textList.add(blockTypeCount[i] + " " + I18n.format(BlockTrackEntryList.instance.trackList.get(i).getEntryName()));
            }
        }
        if (textList.size() == 0)
            textList.add("Tracking no blocks currently.");
    }
    blockTrackInfo.setText(textList);
}
Also used : IInventory(net.minecraft.inventory.IInventory) ChunkCache(net.minecraft.world.ChunkCache) ArrayList(java.util.ArrayList) IBlockAccess(net.minecraft.world.IBlockAccess) TileEntity(net.minecraft.tileentity.TileEntity) IBlockTrackEntry(pneumaticCraft.api.client.pneumaticHelmet.IBlockTrackEntry) PacketDescriptionPacketRequest(pneumaticCraft.common.network.PacketDescriptionPacketRequest) BlockTrackEvent(pneumaticCraft.api.client.pneumaticHelmet.BlockTrackEvent)

Aggregations

TileEntity (net.minecraft.tileentity.TileEntity)822 ItemStack (net.minecraft.item.ItemStack)149 BlockPos (net.minecraft.util.math.BlockPos)130 Block (net.minecraft.block.Block)83 ForgeDirection (net.minecraftforge.common.util.ForgeDirection)76 EnumFacing (net.minecraft.util.EnumFacing)62 ArrayList (java.util.ArrayList)61 IBlockState (net.minecraft.block.state.IBlockState)61 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)57 IInventory (net.minecraft.inventory.IInventory)49 DoubleCoordinates (network.rs485.logisticspipes.world.DoubleCoordinates)44 World (net.minecraft.world.World)43 EntityItem (net.minecraft.entity.item.EntityItem)39 LogisticsTileGenericPipe (logisticspipes.pipes.basic.LogisticsTileGenericPipe)35 FluidStack (net.minecraftforge.fluids.FluidStack)29 EntityPlayer (net.minecraft.entity.player.EntityPlayer)28 HashMap (java.util.HashMap)25 IFluidHandler (net.minecraftforge.fluids.IFluidHandler)23 AMVector3 (am2.api.math.AMVector3)21 Entity (net.minecraft.entity.Entity)21