Search in sources :

Example 1 with DimensionBlockPos

use of blusunrize.immersiveengineering.api.DimensionBlockPos in project ImmersiveEngineering by BluSunrize.

the class ImmersiveNetHandler method onTEValidated.

public <T extends TileEntity & IImmersiveConnectable> void onTEValidated(T te) {
    Set<Connection> conns = getConnections(te.getWorld(), te.getPos());
    if (conns != null)
        for (Connection con : conns) addBlockData(te.getWorld(), con);
    resetCachedIndirectConnections(te.getWorld(), te.getPos());
    setProxy(new DimensionBlockPos(te), null);
}
Also used : DimensionBlockPos(blusunrize.immersiveengineering.api.DimensionBlockPos)

Example 2 with DimensionBlockPos

use of blusunrize.immersiveengineering.api.DimensionBlockPos in project ImmersiveEngineering by BluSunrize.

the class EventHandler method onWorldTick.

// @SubscribeEvent
// public void onEntityInteract(EntityInteractEvent event)
// {
// if(event.target instanceof EntityLivingBase && OreDictionary.itemMatches(new ItemStack(IEContent.itemRevolver,1,OreDictionary.WILDCARD_VALUE), event.entityPlayer.getCurrentEquippedItem(), false))
// event.setCanceled(true);
// }
@SubscribeEvent
public void onWorldTick(WorldTickEvent event) {
    if (event.phase == TickEvent.Phase.START && validateConnsNextTick && FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER) {
        boolean validateConnections = IEConfig.validateConnections;
        int invalidConnectionsDropped = 0;
        for (int dim : ImmersiveNetHandler.INSTANCE.getRelevantDimensions()) {
            if (!validateConnections) {
                continue;
            }
            World world = FMLCommonHandler.instance().getMinecraftServerInstance().getWorld(dim);
            if (world == null) {
                ImmersiveNetHandler.INSTANCE.directConnections.remove(dim);
                continue;
            }
            for (Connection con : ImmersiveNetHandler.INSTANCE.getAllConnections(world)) {
                if (!(world.getTileEntity(con.start) instanceof IImmersiveConnectable && world.getTileEntity(con.end) instanceof IImmersiveConnectable)) {
                    ImmersiveNetHandler.INSTANCE.removeConnection(world, con);
                    invalidConnectionsDropped++;
                }
            }
            IELogger.info("removed " + invalidConnectionsDropped + " invalid connections from world");
        }
        int invalidProxies = 0;
        Set<DimensionBlockPos> toRemove = new HashSet<>();
        for (Entry<DimensionBlockPos, IICProxy> e : ImmersiveNetHandler.INSTANCE.proxies.entrySet()) {
            if (!validateConnections) {
                continue;
            }
            DimensionBlockPos p = e.getKey();
            World w = FMLCommonHandler.instance().getMinecraftServerInstance().getWorld(p.dimension);
            if (w != null && w.isBlockLoaded(p))
                toRemove.add(p);
            if (validateConnections && w == null) {
                invalidProxies++;
                toRemove.add(p);
                continue;
            }
            if (validateConnections && !(w.getTileEntity(p) instanceof IImmersiveConnectable)) {
                invalidProxies++;
                toRemove.add(p);
            }
        }
        if (invalidProxies > 0)
            IELogger.info("Removed " + invalidProxies + " invalid connector proxies (used to transfer power through unloaded chunks)");
        validateConnsNextTick = false;
    }
    if (event.phase == TickEvent.Phase.END && FMLCommonHandler.instance().getEffectiveSide() == Side.SERVER) {
        int dim = event.world.provider.getDimension();
        for (Entry<Connection, Integer> e : ImmersiveNetHandler.INSTANCE.getTransferedRates(dim).entrySet()) if (e.getValue() > e.getKey().cableType.getTransferRate()) {
            if (event.world instanceof WorldServer) {
                BlockPos start = e.getKey().start;
                for (Vec3d vec : e.getKey().getSubVertices(event.world)) ((WorldServer) event.world).spawnParticle(EnumParticleTypes.FLAME, vec.x + start.getX(), vec.y + start.getY(), vec.z + start.getZ(), 0, 0, .02, 0, 1, new int[0]);
            }
            ImmersiveNetHandler.INSTANCE.removeConnection(event.world, e.getKey());
        }
        ImmersiveNetHandler.INSTANCE.getTransferedRates(dim).clear();
        if (!REMOVE_FROM_TICKING.isEmpty()) {
            event.world.tickableTileEntities.removeAll(REMOVE_FROM_TICKING);
            REMOVE_FROM_TICKING.removeIf((te) -> te.getWorld().provider.getDimension() == dim);
        }
    }
    if (event.phase == TickEvent.Phase.START) {
        if (!currentExplosions.isEmpty()) {
            Iterator<IEExplosion> itExplosion = currentExplosions.iterator();
            while (itExplosion.hasNext()) {
                IEExplosion ex = itExplosion.next();
                ex.doExplosionTick();
                if (ex.isExplosionFinished)
                    itExplosion.remove();
            }
        }
        while (!requestedBlockUpdates.isEmpty()) {
            Pair<Integer, BlockPos> curr = requestedBlockUpdates.poll();
            World w = DimensionManager.getWorld(curr.getLeft());
            if (w != null) {
                IBlockState state = w.getBlockState(curr.getRight());
                w.notifyBlockUpdate(curr.getRight(), state, state, 3);
            }
        }
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) IICProxy(blusunrize.immersiveengineering.api.energy.wires.IICProxy) Connection(blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler.Connection) IImmersiveConnectable(blusunrize.immersiveengineering.api.energy.wires.IImmersiveConnectable) DimensionBlockPos(blusunrize.immersiveengineering.api.DimensionBlockPos) WorldServer(net.minecraft.world.WorldServer) World(net.minecraft.world.World) Vec3d(net.minecraft.util.math.Vec3d) DimensionBlockPos(blusunrize.immersiveengineering.api.DimensionBlockPos) BlockPos(net.minecraft.util.math.BlockPos) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 3 with DimensionBlockPos

use of blusunrize.immersiveengineering.api.DimensionBlockPos in project ImmersiveEngineering by BluSunrize.

the class BlockIETileProvider method getDrops.

@Override
public void getDrops(NonNullList<ItemStack> drops, IBlockAccess world, BlockPos pos, IBlockState state, int fortune) // public List<ItemStack> getDrops(IBlockAccess world, BlockPos pos, IBlockState state, int fortune)
{
    TileEntity tile = world.getTileEntity(pos);
    DimensionBlockPos dpos = new DimensionBlockPos(pos, world instanceof World ? ((World) world).provider.getDimension() : 0);
    if (tile == null && tempTile.containsKey(dpos))
        tile = tempTile.get(dpos);
    if (tile != null && (!(tile instanceof ITileDrop) || !((ITileDrop) tile).preventInventoryDrop())) {
        if (tile instanceof IIEInventory && ((IIEInventory) tile).getDroppedItems() != null) {
            for (ItemStack s : ((IIEInventory) tile).getDroppedItems()) if (!s.isEmpty())
                drops.add(s);
        } else if (tile.hasCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null)) {
            IItemHandler h = tile.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null);
            if (h instanceof IEInventoryHandler)
                for (int i = 0; i < h.getSlots(); i++) if (!h.getStackInSlot(i).isEmpty()) {
                    drops.add(h.getStackInSlot(i));
                    ((IEInventoryHandler) h).setStackInSlot(i, ItemStack.EMPTY);
                }
        }
    }
    if (tile instanceof ITileDrop) {
        NonNullList<ItemStack> s = ((ITileDrop) tile).getTileDrops(harvesters.get(), state);
        drops.addAll(s);
    } else
        super.getDrops(drops, world, pos, state, fortune);
    tempTile.remove(dpos);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IEInventoryHandler(blusunrize.immersiveengineering.common.util.inventory.IEInventoryHandler) IItemHandler(net.minecraftforge.items.IItemHandler) DimensionBlockPos(blusunrize.immersiveengineering.api.DimensionBlockPos) IIEInventory(blusunrize.immersiveengineering.common.util.inventory.IIEInventory) World(net.minecraft.world.World) ItemStack(net.minecraft.item.ItemStack)

Example 4 with DimensionBlockPos

use of blusunrize.immersiveengineering.api.DimensionBlockPos in project ImmersiveEngineering by BluSunrize.

the class BlockIETileProvider method breakBlock.

@Override
public void breakBlock(World world, BlockPos pos, IBlockState state) {
    TileEntity tile = world.getTileEntity(pos);
    if (tile instanceof IHasDummyBlocks)
        ((IHasDummyBlocks) tile).breakDummies(pos, state);
    if (tile instanceof IImmersiveConnectable && !world.isRemote)
        ImmersiveNetHandler.INSTANCE.clearAllConnectionsFor(Utils.toCC(tile), world, world.getGameRules().getBoolean("doTileDrops"));
    tempTile.put(new DimensionBlockPos(pos, world.provider.getDimension()), tile);
    super.breakBlock(world, pos, state);
    world.removeTileEntity(pos);
}
Also used : TileEntity(net.minecraft.tileentity.TileEntity) IImmersiveConnectable(blusunrize.immersiveengineering.api.energy.wires.IImmersiveConnectable) DimensionBlockPos(blusunrize.immersiveengineering.api.DimensionBlockPos)

Aggregations

DimensionBlockPos (blusunrize.immersiveengineering.api.DimensionBlockPos)4 IImmersiveConnectable (blusunrize.immersiveengineering.api.energy.wires.IImmersiveConnectable)2 TileEntity (net.minecraft.tileentity.TileEntity)2 World (net.minecraft.world.World)2 IICProxy (blusunrize.immersiveengineering.api.energy.wires.IICProxy)1 Connection (blusunrize.immersiveengineering.api.energy.wires.ImmersiveNetHandler.Connection)1 IEInventoryHandler (blusunrize.immersiveengineering.common.util.inventory.IEInventoryHandler)1 IIEInventory (blusunrize.immersiveengineering.common.util.inventory.IIEInventory)1 IBlockState (net.minecraft.block.state.IBlockState)1 ItemStack (net.minecraft.item.ItemStack)1 BlockPos (net.minecraft.util.math.BlockPos)1 Vec3d (net.minecraft.util.math.Vec3d)1 WorldServer (net.minecraft.world.WorldServer)1 SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1 IItemHandler (net.minecraftforge.items.IItemHandler)1