Search in sources :

Example 1 with SubscribeEvent

use of net.minecraftforge.eventbus.api.SubscribeEvent in project NetherEx by LogicTechCorp.

the class RenderEventHandler method onFOVChange.

@SubscribeEvent
public static void onFOVChange(FOVUpdateEvent event) {
    PlayerEntity player = event.getEntity();
    if (player.isPotionActive(NetherExEffects.FROZEN.get())) {
        float fov = 1.0F;
        if (player.abilities.isFlying) {
            fov *= 1.1F;
        }
        if (player.isHandActive() && player.getActiveItemStack().getItem() instanceof BowItem) {
            float useCount = (float) player.getItemInUseMaxCount() / 20.0F;
            if (useCount > 1.0F) {
                useCount = 1.0F;
            } else {
                useCount = useCount * useCount;
            }
            fov *= 1.0F - useCount * 0.15F;
        }
        event.setNewfov(fov);
    }
}
Also used : BowItem(net.minecraft.item.BowItem) PlayerEntity(net.minecraft.entity.player.PlayerEntity) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 2 with SubscribeEvent

use of net.minecraftforge.eventbus.api.SubscribeEvent in project NetherEx by LogicTechCorp.

the class PlayerHandler method onPlayerTick.

@SubscribeEvent
public static void onPlayerTick(TickEvent.PlayerTickEvent event) {
    TickEvent.Phase phase = event.phase;
    World world = event.player.getEntityWorld();
    PlayerEntity player = event.player;
    if (phase == TickEvent.Phase.END) {
        if (!world.isRemote) {
            IInventory inventory = player.inventory;
            int mirrorCount = 0;
            for (int i = 0; i < inventory.getSizeInventory(); i++) {
                ItemStack stack = inventory.getStackInSlot(i);
                if (stack.getItem() == NetherExItems.DULL_MIRROR.get()) {
                    mirrorCount++;
                    if (mirrorCount > 1) {
                        ItemEntity item = new ItemEntity(world, player.getPosX(), player.getPosY() + 0.5F, player.getPosZ(), stack);
                        item.setPickupDelay(50);
                        world.addEntity(item);
                        inventory.setInventorySlotContents(i, ItemStack.EMPTY);
                        break;
                    }
                }
            }
        }
    }
}
Also used : IInventory(net.minecraft.inventory.IInventory) ItemEntity(net.minecraft.entity.item.ItemEntity) World(net.minecraft.world.World) ItemStack(net.minecraft.item.ItemStack) TickEvent(net.minecraftforge.event.TickEvent) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 3 with SubscribeEvent

use of net.minecraftforge.eventbus.api.SubscribeEvent in project NetherEx by LogicTechCorp.

the class PlayerHandler method onPlayerLeftClick.

@SubscribeEvent
public static void onPlayerLeftClick(PlayerInteractEvent.LeftClickBlock event) {
    World world = event.getWorld();
    Direction direction = event.getFace();
    BlockPos pos = event.getPos();
    PlayerEntity player = event.getPlayer();
    if (direction != null) {
        BlockPos offsetPos = pos.offset(direction);
        Block offsetBlock = world.getBlockState(offsetPos).getBlock();
        if (offsetBlock == NetherExBlocks.BLUE_FIRE.get()) {
            world.playEvent(player, 1009, offsetPos, 0);
            world.setBlockState(offsetPos, Blocks.AIR.getDefaultState());
            event.setCanceled(true);
        }
    }
}
Also used : Block(net.minecraft.block.Block) BlockPos(net.minecraft.util.math.BlockPos) World(net.minecraft.world.World) Direction(net.minecraft.util.Direction) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 4 with SubscribeEvent

use of net.minecraftforge.eventbus.api.SubscribeEvent in project NetherEx by LogicTechCorp.

the class PlayerHandler method onPlayerClone.

@SubscribeEvent
public static void onPlayerClone(PlayerEvent.Clone event) {
    PlayerEntity oldPlayer = event.getOriginal();
    PlayerEntity newPlayer = event.getPlayer();
    IInventory oldInventory = oldPlayer.inventory;
    IInventory newInventory = newPlayer.inventory;
    if (event.isWasDeath()) {
        ItemStack mirrorStack = ItemStack.EMPTY;
        for (int i = 0; i < oldInventory.getSizeInventory(); i++) {
            ItemStack stack = oldInventory.getStackInSlot(i);
            if (stack.getItem() == NetherExItems.DULL_MIRROR.get()) {
                NBTHelper.ensureTagExists(stack);
                if (stack.getTag().contains("SpawnPoint") && (stack.getDamage() < (stack.getMaxDamage() - 1))) {
                    stack.damageItem(1, newPlayer, entity -> {
                    });
                }
                newInventory.setInventorySlotContents(i, stack);
                mirrorStack = stack;
                break;
            }
        }
        if (!mirrorStack.isEmpty()) {
            if (mirrorStack.getDamage() < mirrorStack.getMaxDamage() - 1) {
                CompoundNBT compound = NBTHelper.ensureTagExists(mirrorStack);
                if (compound.contains("SpawnDimension") && compound.contains("SpawnPoint")) {
                    DimensionType spawnDimension = DimensionType.byName(new ResourceLocation(compound.getString("SpawnDimension")));
                    BlockPos spawnPoint = NBTUtil.readBlockPos(compound.getCompound("SpawnPoint"));
                    if (spawnDimension != null) {
                        newPlayer.setSpawnDimenion(spawnDimension);
                        newPlayer.setSpawnPoint(spawnPoint, true, false, spawnDimension);
                    }
                }
            }
        }
    }
}
Also used : IInventory(net.minecraft.inventory.IInventory) DimensionType(net.minecraft.world.dimension.DimensionType) CompoundNBT(net.minecraft.nbt.CompoundNBT) ResourceLocation(net.minecraft.util.ResourceLocation) BlockPos(net.minecraft.util.math.BlockPos) ItemStack(net.minecraft.item.ItemStack) PlayerEntity(net.minecraft.entity.player.PlayerEntity) ServerPlayerEntity(net.minecraft.entity.player.ServerPlayerEntity) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 5 with SubscribeEvent

use of net.minecraftforge.eventbus.api.SubscribeEvent in project Overloaded by CJ-MC-Mods.

the class ItemRailGun method onMouseEvent.

@SubscribeEvent
public void onMouseEvent(InputEvent.MouseScrollEvent event) {
    ClientPlayerEntity player = Minecraft.getInstance().player;
    if (event.getScrollDelta() != 0 && player != null && player.isShiftKeyDown()) {
        ItemStack stack = player.getMainHandItem();
        if (player.isShiftKeyDown() && !stack.isEmpty() && stack.getItem() == this) {
            int powerDelta = Long.signum(Math.round(event.getScrollDelta())) * OverloadedConfig.INSTANCE.railGun.stepEnergy;
            if (InputMappings.isKeyDown(Minecraft.getInstance().getWindow().getWindow(), ((ClientProxy) Overloaded.proxy).railGun100x.getKey().getValue())) {
                powerDelta *= 100;
            }
            Overloaded.proxy.networkWrapper.sendToServer(new RailGunSettingsMessage(powerDelta));
            event.setCanceled(true);
        }
    }
}
Also used : RailGunSettingsMessage(com.cjm721.overloaded.network.packets.RailGunSettingsMessage) ClientPlayerEntity(net.minecraft.client.entity.player.ClientPlayerEntity) ItemStack(net.minecraft.item.ItemStack) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Aggregations

SubscribeEvent (net.minecraftforge.eventbus.api.SubscribeEvent)64 PlayerEntity (net.minecraft.entity.player.PlayerEntity)18 ItemStack (net.minecraft.item.ItemStack)17 ServerPlayerEntity (net.minecraft.entity.player.ServerPlayerEntity)11 ResourceLocation (net.minecraft.util.ResourceLocation)10 World (net.minecraft.world.World)8 BlockPos (net.minecraft.util.math.BlockPos)7 CompoundNBT (net.minecraft.nbt.CompoundNBT)6 StringTextComponent (net.minecraft.util.text.StringTextComponent)5 Minecraft (net.minecraft.client.Minecraft)4 BlockItem (net.minecraft.item.BlockItem)4 IAgriJournalItem (com.infinityraider.agricraft.api.v1.content.items.IAgriJournalItem)3 MinecraftServer (net.minecraft.server.MinecraftServer)3 ITextComponent (net.minecraft.util.text.ITextComponent)3 OnlyIn (net.minecraftforge.api.distmarker.OnlyIn)3 Sets (com.google.common.collect.Sets)2 AgriCraft (com.infinityraider.agricraft.AgriCraft)2 AgriApi (com.infinityraider.agricraft.api.v1.AgriApi)2 IAgriClipperItem (com.infinityraider.agricraft.api.v1.content.items.IAgriClipperItem)2 IAgriRakeItem (com.infinityraider.agricraft.api.v1.content.items.IAgriRakeItem)2