Search in sources :

Example 11 with SubscribeEvent

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();
        }
    }
}
Also used : PacketServerTickTime(pneumaticCraft.common.network.PacketServerTickTime) World(net.minecraft.world.World) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Example 12 with SubscribeEvent

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);
    }
}
Also used : EntityDrone(pneumaticCraft.common.entity.living.EntityDrone) EntityPlayer(net.minecraft.entity.player.EntityPlayer) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Example 13 with SubscribeEvent

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);
    }
}
Also used : NBTTagList(net.minecraft.nbt.NBTTagList) ChunkPosition(net.minecraft.world.ChunkPosition) NBTTagCompound(net.minecraft.nbt.NBTTagCompound) HashMap(java.util.HashMap) Map(java.util.Map) HashBiMap(com.google.common.collect.HashBiMap) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Example 14 with SubscribeEvent

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();
        }
    }
}
Also used : ChunkPosition(net.minecraft.world.ChunkPosition) EntityPlayer(net.minecraft.entity.player.EntityPlayer) Chunk(net.minecraft.world.chunk.Chunk) HashMap(java.util.HashMap) Map(java.util.Map) HashBiMap(com.google.common.collect.HashBiMap) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Example 15 with SubscribeEvent

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);
                }
            }
        }
    }
}
Also used : ChunkPosition(net.minecraft.world.ChunkPosition) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(cpw.mods.fml.common.eventhandler.SubscribeEvent)

Aggregations

SubscribeEvent (cpw.mods.fml.common.eventhandler.SubscribeEvent)109 EntityPlayer (net.minecraft.entity.player.EntityPlayer)45 ItemStack (net.minecraft.item.ItemStack)45 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)14 EntityLivingBase (net.minecraft.entity.EntityLivingBase)11 World (net.minecraft.world.World)11 Minecraft (net.minecraft.client.Minecraft)10 ChunkPosition (net.minecraft.world.ChunkPosition)9 EntityItem (net.minecraft.entity.item.EntityItem)8 ChatComponentText (net.minecraft.util.ChatComponentText)8 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)6 AffinityData (am2.playerextensions.AffinityData)5 SideOnly (cpw.mods.fml.relauncher.SideOnly)5 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)5 Map (java.util.Map)5 Block (net.minecraft.block.Block)5 EntityEnderman (net.minecraft.entity.monster.EntityEnderman)5 ChunkCoordIntPair (net.minecraft.world.ChunkCoordIntPair)5 ExtendedProperties (am2.playerextensions.ExtendedProperties)4