use of net.minecraftforge.fml.common.eventhandler.SubscribeEvent in project malmo by Microsoft.
the class CommandForWheeledRobotNavigationImplementation method onRenderTick.
/** Called for each screen redraw - approximately three times as often as the other tick events,
* under normal conditions.<br>
* This is where we want to update our yaw/pitch, in order to get smooth panning etc
* (which is how Minecraft itself does it).
* The speed of the render ticks is not guaranteed, and can vary from machine to machine, so
* we try to account for this in the calculations.
* @param ev the RenderTickEvent object for this tick
*/
@SubscribeEvent
public void onRenderTick(TickEvent.RenderTickEvent ev) {
if (ev.phase == Phase.START) {
if (this.isOverriding()) {
EntityPlayerSP player = Minecraft.getMinecraft().thePlayer;
if (player != null) {
updateYawAndPitch();
player.rotationPitch = this.mCameraPitch;
player.rotationYaw = this.mYaw;
}
}
}
}
use of net.minecraftforge.fml.common.eventhandler.SubscribeEvent in project MinecraftForge by MinecraftForge.
the class UniversalBucket method onFillBucket.
// low priority so other mods can handle their stuff first
@SubscribeEvent(priority = EventPriority.LOW)
public void onFillBucket(FillBucketEvent event) {
if (event.getResult() != Event.Result.DEFAULT) {
// event was already handled
return;
}
// not for us to handle
ItemStack emptyBucket = event.getEmptyBucket();
if (emptyBucket.isEmpty() || !emptyBucket.isItemEqual(getEmpty()) || (isNbtSensitive() && ItemStack.areItemStackTagsEqual(emptyBucket, getEmpty()))) {
return;
}
// needs to target a block
RayTraceResult target = event.getTarget();
if (target == null || target.typeOfHit != RayTraceResult.Type.BLOCK) {
return;
}
World world = event.getWorld();
BlockPos pos = target.getBlockPos();
ItemStack singleBucket = emptyBucket.copy();
singleBucket.setCount(1);
FluidActionResult filledResult = FluidUtil.tryPickUpFluid(singleBucket, event.getEntityPlayer(), world, pos, target.sideHit);
if (filledResult.isSuccess()) {
event.setResult(Event.Result.ALLOW);
event.setFilledBucket(filledResult.getResult());
} else {
// cancel event, otherwise the vanilla minecraft ItemBucket would
// convert it into a water/lava bucket depending on the blocks material
event.setCanceled(true);
}
}
use of net.minecraftforge.fml.common.eventhandler.SubscribeEvent in project MinecraftForge by MinecraftForge.
the class DynBucketTest method onBucketFill.
@SubscribeEvent
public void onBucketFill(FillBucketEvent event) {
RayTraceResult target = event.getTarget();
if (target != null) {
IBlockState state = event.getWorld().getBlockState(target.getBlockPos());
if (state.getBlock() instanceof IFluidBlock) {
Fluid fluid = ((IFluidBlock) state.getBlock()).getFluid();
FluidStack fs = new FluidStack(fluid, Fluid.BUCKET_VOLUME);
ItemStack bucket = event.getEmptyBucket();
IFluidHandlerItem fluidHandler = FluidUtil.getFluidHandler(bucket);
if (fluidHandler != null) {
int fillAmount = fluidHandler.fill(fs, true);
if (fillAmount > 0) {
ItemStack filledBucket = fluidHandler.getContainer();
event.setFilledBucket(filledBucket);
event.setResult(Result.ALLOW);
}
}
}
}
}
use of net.minecraftforge.fml.common.eventhandler.SubscribeEvent in project MinecraftForge by MinecraftForge.
the class LootTablesDebug method lootLoad.
@SubscribeEvent
public void lootLoad(LootTableLoadEvent event) {
if (!event.getName().equals(LootTableList.CHESTS_SPAWN_BONUS_CHEST))
return;
// Remove axes and replace with chestpeice, First vanilla entry is always called "main"
//Note: This CAN NPE if another mod removes things
LootPool main = event.getTable().getPool("main");
main.removeEntry("minecraft:wooden_axe");
main.removeEntry("minecraft:stone_axe");
main.addEntry(new LootEntryItem(Items.DIAMOND_CHESTPLATE, 1, 0, new LootFunction[0], new LootCondition[0], MODID + ":diamond_chestplate"));
// Get rid of all building mats. Which is pool #3, index starts at 0, but 0 is named "main"
event.getTable().removePool("pool3");
}
use of net.minecraftforge.fml.common.eventhandler.SubscribeEvent in project MinecraftForge by MinecraftForge.
the class PlayerInteractEventTest method rightClickBlock.
@SubscribeEvent
public void rightClickBlock(PlayerInteractEvent.RightClickBlock evt) {
if (!ENABLE)
return;
logger.info("HIT VEC: {}", evt.getHitVec());
// Shift right clicking dropper with an item in hand should still open the dropper contrary to normal mechanics
// The item in hand is used as well (not specifying anything would not use the item)
TileEntity te = evt.getWorld().getTileEntity(evt.getPos());
if (te instanceof TileEntityDropper) {
evt.setUseBlock(Event.Result.ALLOW);
evt.setUseItem(Event.Result.ALLOW);
}
// Same as above, except the item should no longer be used
if (te instanceof TileEntityChest) {
evt.setUseBlock(Event.Result.ALLOW);
// could be left out as well
evt.setUseItem(Event.Result.DENY);
}
// If you dual wield flints and steels and right click a chest nothing should happen
if (evt.getItemStack() != null && evt.getItemStack().getItem() == Items.FLINT_AND_STEEL)
evt.setUseBlock(Event.Result.DENY);
// Opening a TE will also place a painting on the TE if possible
if (evt.getHand() == EnumHand.MAIN_HAND && evt.getItemStack() != null && evt.getItemStack().getItem() == Items.PAINTING) {
evt.setUseItem(Event.Result.ALLOW);
}
// Sword in main hand, spawn egg in offhand -> nothing should happen
if (evt.getItemStack() != null && evt.getItemStack().getItem() == Items.SPAWN_EGG) {
evt.setCanceled(true);
}
}
Aggregations