use of cpw.mods.fml.common.eventhandler.SubscribeEvent in project PneumaticCraft by MineMaarten.
the class TickHandlerPneumaticCraft method tickEnd.
@SubscribeEvent
public void tickEnd(TickEvent.WorldTickEvent event) {
if (event.phase == TickEvent.Phase.END) {
World world = event.world;
checkLightning(world);
DroneClaimManager.getInstance(world).update();
if (!event.world.isRemote && event.world.provider.dimensionId == 0 && event.world.getWorldTime() % (24000 / AmadronOfferPeriodicConfig.timesPerDay) == 1) {
AmadronOfferManager.getInstance().shufflePeriodicOffers();
}
if (!event.world.isRemote && event.world.getTotalWorldTime() % 100 == 0) {
//In case world are going to get their own thread: MinecraftServer.getServer().worldTickTimes.get(event.world.provider.dimensionId)
double tickTime = net.minecraft.util.MathHelper.average(MinecraftServer.getServer().tickTimeArray) * 1.0E-6D;
NetworkHandler.sendToDimension(new PacketServerTickTime(tickTime), event.world.provider.dimensionId);
if (event.world.getTotalWorldTime() % 600 == 0)
AmadronOfferManager.getInstance().tryRestockCustomOffers();
}
}
}
use of cpw.mods.fml.common.eventhandler.SubscribeEvent in project PneumaticCraft by MineMaarten.
the class DroneSpecialVariableHandler method onSpecialVariableRetrieving.
@SubscribeEvent
public void onSpecialVariableRetrieving(SpecialVariableRetrievalEvent.CoordinateVariable.Drone event) {
if (event.specialVarName.equalsIgnoreCase("owner")) {
EntityDrone drone = (EntityDrone) event.drone;
EntityPlayer player = drone.getOwner();
if (player != null)
event.coordinate = getPosForEntity(player);
} else if (event.specialVarName.equalsIgnoreCase("drone")) {
event.coordinate = getPosForEntity(event.drone);
} else if (event.specialVarName.toLowerCase().startsWith("player=")) {
EntityPlayer player = MinecraftServer.getServer().getConfigurationManager().func_152612_a(event.specialVarName.substring("player=".length()));
if (player != null)
event.coordinate = getPosForEntity(player);
}
}
use of cpw.mods.fml.common.eventhandler.SubscribeEvent in project PneumaticCraft by MineMaarten.
the class SemiBlockManager method onChunkSave.
@SubscribeEvent
public void onChunkSave(ChunkDataEvent.Save event) {
Map<ChunkPosition, ISemiBlock> map = semiBlocks.get(event.getChunk());
if (map != null && map.size() > 0) {
NBTTagList tagList = new NBTTagList();
for (Map.Entry<ChunkPosition, ISemiBlock> entry : map.entrySet()) {
NBTTagCompound t = new NBTTagCompound();
entry.getValue().writeToNBT(t);
t.setInteger("x", entry.getKey().chunkPosX);
t.setInteger("y", entry.getKey().chunkPosY);
t.setInteger("z", entry.getKey().chunkPosZ);
t.setString("type", getKeyForSemiBlock(entry.getValue()));
tagList.appendTag(t);
}
event.getData().setTag("SemiBlocks", tagList);
}
}
use of cpw.mods.fml.common.eventhandler.SubscribeEvent in project PneumaticCraft by MineMaarten.
the class SemiBlockManager method onClientTick.
@SubscribeEvent
public void onClientTick(TickEvent.ClientTickEvent event) {
if (this == getServerInstance())
getClientOldInstance().onClientTick(event);
else {
EntityPlayer player = PneumaticCraft.proxy.getPlayer();
if (player != null) {
for (ISemiBlock semiBlock : addingBlocks) {
Chunk chunk = semiBlock.getWorld().getChunkFromBlockCoords(semiBlock.getPos().chunkPosX, semiBlock.getPos().chunkPosZ);
getOrCreateMap(chunk).put(semiBlock.getPos(), semiBlock);
}
addingBlocks.clear();
Iterator<Map.Entry<Chunk, Map<ChunkPosition, ISemiBlock>>> iterator = semiBlocks.entrySet().iterator();
while (iterator.hasNext()) {
Map.Entry<Chunk, Map<ChunkPosition, ISemiBlock>> entry = iterator.next();
if (PneumaticCraftUtils.distBetween(player.posX, 0, player.posZ, entry.getKey().xPosition * 16 - 8, 0, entry.getKey().zPosition * 16 - 8) > SYNC_DISTANCE + 10) {
iterator.remove();
} else {
for (ISemiBlock semiBlock : entry.getValue().values()) {
if (!semiBlock.isInvalid())
semiBlock.update();
}
Iterator<ISemiBlock> it = entry.getValue().values().iterator();
while (it.hasNext()) {
if (it.next().isInvalid()) {
it.remove();
}
}
}
}
} else {
semiBlocks.clear();
}
}
}
use of cpw.mods.fml.common.eventhandler.SubscribeEvent in project PneumaticCraft by MineMaarten.
the class SemiBlockManager method onInteraction.
@SubscribeEvent
public void onInteraction(PlayerInteractEvent event) {
if (!event.world.isRemote && event.action == PlayerInteractEvent.Action.RIGHT_CLICK_BLOCK) {
ItemStack curItem = event.entityPlayer.getCurrentEquippedItem();
if (curItem != null && curItem.getItem() instanceof ISemiBlockItem) {
if (getSemiBlock(event.world, event.x, event.y, event.z) != null) {
if (event.entityPlayer.capabilities.isCreativeMode) {
setSemiBlock(event.world, event.x, event.y, event.z, null);
} else {
breakSemiBlock(event.world, event.x, event.y, event.z, event.entityPlayer);
}
event.setCanceled(true);
} else {
ISemiBlock newBlock = ((ISemiBlockItem) curItem.getItem()).getSemiBlock(event.world, event.x, event.y, event.z, curItem);
newBlock.initialize(event.world, new ChunkPosition(event.x, event.y, event.z));
if (newBlock.canPlace()) {
setSemiBlock(event.world, event.x, event.y, event.z, newBlock);
newBlock.onPlaced(event.entityPlayer, curItem);
event.world.playSoundEffect(event.x + 0.5, event.y + 0.5, event.z + 0.5, Block.soundTypeGlass.func_150496_b(), (Block.soundTypeGlass.getVolume() + 1.0F) / 2.0F, Block.soundTypeGlass.getPitch() * 0.8F);
if (!event.entityPlayer.capabilities.isCreativeMode) {
curItem.stackSize--;
if (curItem.stackSize <= 0)
event.entityPlayer.setCurrentItemOrArmor(0, null);
}
event.setCanceled(true);
}
}
}
}
}
Aggregations