Search in sources :

Example 71 with SubscribeEvent

use of net.minecraftforge.fml.common.eventhandler.SubscribeEvent in project Geolosys by oitsjustjose.

the class BlockSample method registerEvent.

@SubscribeEvent
public void registerEvent(BlockEvent.HarvestDropsEvent event) {
    if (!Config.getInstance().boringSamples || event.getHarvester() == null || event.getState() == null || event.getState().getBlock() != this) {
        return;
    }
    String resource = Types.Modded.byMetadata(event.getState().getBlock().getMetaFromState(event.getState())).getResource();
    event.getHarvester().sendStatusMessage(new TextComponentString("You break the sample to find " + resource), true);
    event.getDrops().clear();
}
Also used : TextComponentString(net.minecraft.util.text.TextComponentString) TextComponentString(net.minecraft.util.text.TextComponentString) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 72 with SubscribeEvent

use of net.minecraftforge.fml.common.eventhandler.SubscribeEvent in project Geolosys by oitsjustjose.

the class ForgeEventListener method registerEvent.

@SubscribeEvent
public void registerEvent(RightClickBlock event) {
    try {
        IBlockState state = event.getWorld().getBlockState(event.getPos());
        if (state.getBlock() == Geolosys.getInstance().ORE_SAMPLE || state.getBlock() == Geolosys.getInstance().ORE_SAMPLE_VANILLA) {
            if (event.getEntityPlayer().isSneaking() && event.getWorld().isRemote) {
                if (jmAPI.playerAccepts(Lib.MODID, DisplayType.Waypoint)) {
                    String name = new ItemStack(state.getBlock(), 1, state.getBlock().getMetaFromState(state)).getDisplayName();
                    String id = Lib.MODID + " - " + name + " - " + event.getWorld().getChunkFromBlockCoords(event.getPos()).getPos();
                    try {
                        jmAPI.show(new Waypoint(Lib.MODID, id, name, event.getWorld().provider.getDimension(), event.getPos()));
                    } catch (Throwable t) {
                        Geolosys.getInstance().LOGGER.info(t.getMessage());
                    }
                }
            }
        }
    } catch (NullPointerException ignored) {
    }
}
Also used : IBlockState(net.minecraft.block.state.IBlockState) Waypoint(journeymap.client.api.display.Waypoint) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 73 with SubscribeEvent

use of net.minecraftforge.fml.common.eventhandler.SubscribeEvent in project malmo by Microsoft.

the class RewardForDiscardingItemImplementation method onTossItem.

@SubscribeEvent
public void onTossItem(ItemTossEvent event) {
    if (event.getEntityItem() != null && event.getPlayer() instanceof EntityPlayerMP) {
        ItemStack stack = event.getEntityItem().getEntityItem();
        sendItemStackToClient((EntityPlayerMP) event.getPlayer(), MalmoMessageType.SERVER_DISCARDITEM, stack);
    }
}
Also used : EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 74 with SubscribeEvent

use of net.minecraftforge.fml.common.eventhandler.SubscribeEvent in project malmo by Microsoft.

the class ServerStateMachine method onCheckSpawn.

/**
 * Called by Forge - return ALLOW, DENY or DEFAULT to control spawning in our world.
 */
@SubscribeEvent
public void onCheckSpawn(CheckSpawn cs) {
    // Decide whether or not to allow spawning.
    // We shouldn't allow spawning unless it has been specifically turned on - whether
    // a mission is running or not. (Otherwise spawning may happen in between missions.)
    boolean allowSpawning = false;
    if (currentMissionInit() != null && currentMissionInit().getMission() != null) {
        // There is a mission running - does it allow spawning?
        ServerSection ss = currentMissionInit().getMission().getServerSection();
        ServerInitialConditions sic = (ss != null) ? ss.getServerInitialConditions() : null;
        if (sic != null)
            allowSpawning = (sic.isAllowSpawning() == Boolean.TRUE);
        if (allowSpawning && sic.getAllowedMobs() != null && !sic.getAllowedMobs().isEmpty()) {
            // Spawning is allowed, but restricted to our list.
            // Is this mob on our list?
            String mobName = EntityList.getEntityString(cs.getEntity());
            allowSpawning = false;
            for (EntityTypes mob : sic.getAllowedMobs()) {
                if (mob.value().equals(mobName)) {
                    allowSpawning = true;
                    break;
                }
            }
        }
    }
    if (allowSpawning)
        cs.setResult(Result.DEFAULT);
    else
        cs.setResult(Result.DENY);
}
Also used : EntityTypes(com.microsoft.Malmo.Schemas.EntityTypes) ServerSection(com.microsoft.Malmo.Schemas.ServerSection) TextComponentString(net.minecraft.util.text.TextComponentString) ServerInitialConditions(com.microsoft.Malmo.Schemas.ServerInitialConditions) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Example 75 with SubscribeEvent

use of net.minecraftforge.fml.common.eventhandler.SubscribeEvent in project malmo by Microsoft.

the class VideoHook method postRender.

/**
 * Called when the world has been rendered but not yet the GUI or player hand.
 *
 * @param event
 *            Contains information about the event (not used).
 */
@SubscribeEvent
public void postRender(RenderWorldLastEvent event) {
    // Check that the video producer and frame type match - eg if this is a colourmap frame, then
    // only the colourmap videoproducer needs to do anything.
    boolean colourmapFrame = TextureHelper.colourmapFrame;
    boolean colourmapVideoProducer = this.videoProducer.getVideoType() == VideoType.COLOUR_MAP;
    if (colourmapFrame != colourmapVideoProducer)
        return;
    EntityPlayerSP player = Minecraft.getMinecraft().player;
    float x = (float) (player.lastTickPosX + (player.posX - player.lastTickPosX) * event.getPartialTicks());
    float y = (float) (player.lastTickPosY + (player.posY - player.lastTickPosY) * event.getPartialTicks());
    float z = (float) (player.lastTickPosZ + (player.posZ - player.lastTickPosZ) * event.getPartialTicks());
    float yaw = player.prevRotationYaw + (player.rotationYaw - player.prevRotationYaw) * event.getPartialTicks();
    float pitch = player.prevRotationPitch + (player.rotationPitch - player.prevRotationPitch) * event.getPartialTicks();
    long time_before_ns = System.nanoTime();
    if (time_before_ns < retry_time_ns)
        return;
    boolean success = false;
    try {
        int size = this.videoProducer.getRequiredBufferSize();
        // Get buffer ready for writing to:
        this.buffer.clear();
        this.headerbuffer.clear();
        // Write the pos data:
        this.headerbuffer.putFloat(x);
        this.headerbuffer.putFloat(y);
        this.headerbuffer.putFloat(z);
        this.headerbuffer.putFloat(yaw);
        this.headerbuffer.putFloat(pitch);
        // Write the frame data:
        this.videoProducer.getFrame(this.missionInit, this.buffer);
        // The buffer gets flipped by getFrame(), but we need to flip our header buffer ourselves:
        this.headerbuffer.flip();
        ByteBuffer[] buffers = { this.headerbuffer, this.buffer };
        long time_after_render_ns = System.nanoTime();
        success = this.connection.sendTCPBytes(buffers, size + POS_HEADER_SIZE);
        long time_after_ns = System.nanoTime();
        float ms_send = (time_after_ns - time_after_render_ns) / 1000000.0f;
        float ms_render = (time_after_render_ns - time_before_ns) / 1000000.0f;
        if (success) {
            // Reset count of failed sends.
            this.failedTCPSendCount = 0;
            this.timeOfLastFrame = System.currentTimeMillis();
            if (this.timeOfFirstFrame == 0)
                this.timeOfFirstFrame = this.timeOfLastFrame;
            this.framesSent++;
        // System.out.format("Total: %.2fms; collecting took %.2fms; sending %d bytes took %.2fms\n", ms_send + ms_render, ms_render, size, ms_send);
        // System.out.println("Collect: " + ms_render + "; Send: " + ms_send);
        }
    } catch (Exception e) {
        System.out.format(e.getMessage());
    }
    if (!success) {
        System.out.format("Failed to send frame - will retry in %d seconds\n", RETRY_GAP_NS / 1000000000L);
        retry_time_ns = time_before_ns + RETRY_GAP_NS;
        this.failedTCPSendCount++;
    }
}
Also used : EntityPlayerSP(net.minecraft.client.entity.EntityPlayerSP) ByteBuffer(java.nio.ByteBuffer) LWJGLException(org.lwjgl.LWJGLException) InvocationTargetException(java.lang.reflect.InvocationTargetException) SubscribeEvent(net.minecraftforge.fml.common.eventhandler.SubscribeEvent)

Aggregations

SubscribeEvent (net.minecraftforge.fml.common.eventhandler.SubscribeEvent)1135 ItemStack (net.minecraft.item.ItemStack)316 EntityPlayer (net.minecraft.entity.player.EntityPlayer)314 World (net.minecraft.world.World)196 BlockPos (net.minecraft.util.math.BlockPos)179 SideOnly (net.minecraftforge.fml.relauncher.SideOnly)136 IBlockState (net.minecraft.block.state.IBlockState)120 ResourceLocation (net.minecraft.util.ResourceLocation)102 Entity (net.minecraft.entity.Entity)93 Block (net.minecraft.block.Block)86 EntityLivingBase (net.minecraft.entity.EntityLivingBase)84 Minecraft (net.minecraft.client.Minecraft)72 EntityPlayerMP (net.minecraft.entity.player.EntityPlayerMP)66 ModelResourceLocation (net.minecraft.client.renderer.block.model.ModelResourceLocation)64 NBTTagCompound (net.minecraft.nbt.NBTTagCompound)55 Item (net.minecraft.item.Item)53 EntityItem (net.minecraft.entity.item.EntityItem)48 TileEntity (net.minecraft.tileentity.TileEntity)46 TextComponentString (net.minecraft.util.text.TextComponentString)42 Random (java.util.Random)37