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);
}
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);
}
}
}
}
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);
}
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);
}
Aggregations