Search in sources :

Example 16 with SubscribeEvent

use of net.minecraftforge.eventbus.api.SubscribeEvent in project MinecraftForge by MinecraftForge.

the class FakePlayerTest method registerCommands.

@SubscribeEvent
public void registerCommands(RegisterCommandsEvent event) {
    event.getDispatcher().register(Commands.literal("fakeplayer").then(Commands.literal("attack").then(Commands.argument("target", EntityArgument.entity()).executes(context -> {
        FakePlayerFactory.getMinecraft(context.getSource().getLevel()).attack(EntityArgument.getEntity(context, "target"));
        return 1;
    }))).then(Commands.literal("opencontainer").executes(context -> {
        ServerPlayer fakePlayer = FakePlayerFactory.getMinecraft(context.getSource().getLevel());
        InteractionHand hand = InteractionHand.MAIN_HAND;
        ItemStack stack = Items.WRITABLE_BOOK.getDefaultInstance();
        fakePlayer.setItemInHand(hand, stack);
        fakePlayer.openItemGui(stack, hand);
        return 1;
    })));
}
Also used : ServerPlayer(net.minecraft.server.level.ServerPlayer) InteractionHand(net.minecraft.world.InteractionHand) ItemStack(net.minecraft.world.item.ItemStack) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 17 with SubscribeEvent

use of net.minecraftforge.eventbus.api.SubscribeEvent in project AgriCraft by AgriCraft.

the class ModelAndTextureHandler method onModelLoadEvent.

// Used to add the models used in seed rendering
@SubscribeEvent
@SuppressWarnings("unused")
public void onModelLoadEvent(ModelRegistryEvent event) {
    // Jsons
    AgriCore.getPlants().getAllElements().stream().map(AgriPlant::getSeedModel).map(this::toResourceLocation).forEach(ModelLoader::addSpecialModel);
    // no plant instance
    ModelLoader.addSpecialModel(NoPlant.getInstance().getSeedModel());
    // seed bag models
    ModelLoader.addSpecialModel(new ResourceLocation(AgriCraft.instance.getModId(), "item/agri_seed_bag_empty"));
    ModelLoader.addSpecialModel(new ResourceLocation(AgriCraft.instance.getModId(), "item/agri_seed_bag_partial"));
    ModelLoader.addSpecialModel(new ResourceLocation(AgriCraft.instance.getModId(), "item/agri_seed_bag_full"));
    // channel valve hand Wheel
    ModelLoader.addSpecialModel(TileEntityIrrigationChannelRenderer.MODEL_HANDWHEEL);
}
Also used : ModelLoader(net.minecraftforge.client.model.ModelLoader) ResourceLocation(net.minecraft.util.ResourceLocation) ModelResourceLocation(net.minecraft.client.renderer.model.ModelResourceLocation) AgriPlant(com.agricraft.agricore.plant.AgriPlant) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 18 with SubscribeEvent

use of net.minecraftforge.eventbus.api.SubscribeEvent in project AgriCraft by AgriCraft.

the class BlockUpdateHandler method onChunkUnloaded.

@SubscribeEvent
@SuppressWarnings("unused")
public void onChunkUnloaded(ChunkEvent.Unload event) {
    if (event.getWorld() instanceof ServerWorld) {
        ServerWorld world = (ServerWorld) event.getWorld();
        RegistryKey<World> dimension = world.getDimensionKey();
        if (listeners.containsKey(dimension)) {
            listeners.computeIfPresent(dimension, (dim, chunkMap) -> {
                if (chunkMap.containsKey(event.getChunk().getPos())) {
                    chunkMap.remove(event.getChunk().getPos()).forEach((pos, set) -> set.forEach(listener -> listener.onChunkUnloaded(world, pos)));
                }
                return chunkMap;
            });
            listeners.get(dimension).remove(event.getChunk().getPos());
        }
    }
}
Also used : ServerWorld(net.minecraft.world.server.ServerWorld) ServerWorld(net.minecraft.world.server.ServerWorld) BlockEvent(net.minecraftforge.event.world.BlockEvent) WorldEvent(net.minecraftforge.event.world.WorldEvent) ChunkEvent(net.minecraftforge.event.world.ChunkEvent) World(net.minecraft.world.World) ChunkPos(net.minecraft.util.math.ChunkPos) Set(java.util.Set) BlockPos(net.minecraft.util.math.BlockPos) Maps(com.google.common.collect.Maps) Sets(com.google.common.collect.Sets) RegistryKey(net.minecraft.util.RegistryKey) Map(java.util.Map) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent) ServerWorld(net.minecraft.world.server.ServerWorld) World(net.minecraft.world.World) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 19 with SubscribeEvent

use of net.minecraftforge.eventbus.api.SubscribeEvent in project AgriCraft by AgriCraft.

the class ItemToolTipHandler method addTrowelTooltip.

/**
 * Adds tooltips to items that are trowels (implementing ITrowel).
 */
@SubscribeEvent
@SuppressWarnings("unused")
public void addTrowelTooltip(ItemTooltipEvent event) {
    ItemStack stack = event.getItemStack();
    if (!stack.isEmpty() && stack.getItem() instanceof IAgriTrowelItem) {
        event.getToolTip().add(AgriToolTips.TROWEL);
        IAgriTrowelItem trowel = (IAgriTrowelItem) stack.getItem();
        trowel.getGenome(stack).map(genome -> {
            event.getToolTip().add(AgriToolTips.getPlantTooltip(genome.getPlant()));
            trowel.getGrowthStage(stack).ifPresent(stage -> event.getToolTip().add(AgriToolTips.getGrowthTooltip(stage)));
            return genome.getStats();
        }).ifPresent(stats -> stats.addTooltips(text -> event.getToolTip().add(text)));
    }
}
Also used : OnlyIn(net.minecraftforge.api.distmarker.OnlyIn) Item(net.minecraft.item.Item) CompoundNBT(net.minecraft.nbt.CompoundNBT) IAgriClipperItem(com.infinityraider.agricraft.api.v1.content.items.IAgriClipperItem) MessageFormat(java.text.MessageFormat) ModuleKeyboard(com.infinityraider.infinitylib.modules.keyboard.ModuleKeyboard) ITextComponent(net.minecraft.util.text.ITextComponent) Dist(net.minecraftforge.api.distmarker.Dist) ItemStack(net.minecraft.item.ItemStack) AgriToolTips(com.infinityraider.agricraft.reference.AgriToolTips) Minecraft(net.minecraft.client.Minecraft) BlockTags(net.minecraft.tags.BlockTags) IAgriJournalItem(com.infinityraider.agricraft.api.v1.content.items.IAgriJournalItem) IAgriTrowelItem(com.infinityraider.agricraft.api.v1.content.items.IAgriTrowelItem) StringTextComponent(net.minecraft.util.text.StringTextComponent) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent) CapabilityGeneInspector(com.infinityraider.agricraft.capability.CapabilityGeneInspector) AgriCraft(com.infinityraider.agricraft.AgriCraft) AgriApi(com.infinityraider.agricraft.api.v1.AgriApi) ItemTags(net.minecraft.tags.ItemTags) Collection(java.util.Collection) TextFormatting(net.minecraft.util.text.TextFormatting) BlockItem(net.minecraft.item.BlockItem) IAgriRakeItem(com.infinityraider.agricraft.api.v1.content.items.IAgriRakeItem) ItemTooltipEvent(net.minecraftforge.event.entity.player.ItemTooltipEvent) ResourceLocation(net.minecraft.util.ResourceLocation) ItemSeedBag(com.infinityraider.agricraft.content.tools.ItemSeedBag) ItemStack(net.minecraft.item.ItemStack) IAgriTrowelItem(com.infinityraider.agricraft.api.v1.content.items.IAgriTrowelItem) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 20 with SubscribeEvent

use of net.minecraftforge.eventbus.api.SubscribeEvent in project AgriCraft by AgriCraft.

the class ItemToolTipHandler method addJournalTooltip.

/**
 * Adds tooltips to items that are journals (implementing ITrowel).
 */
@SubscribeEvent
@SuppressWarnings("unused")
public void addJournalTooltip(ItemTooltipEvent event) {
    ItemStack stack = event.getItemStack();
    if (!stack.isEmpty() && stack.getItem() instanceof IAgriJournalItem) {
        IAgriJournalItem journal = (IAgriJournalItem) stack.getItem();
        int count = journal.getDiscoveredSeeds(stack).size();
        event.getToolTip().add(new StringTextComponent("" + count + " ").appendSibling(AgriToolTips.JOURNAL_SEEDS));
        event.getToolTip().add(AgriToolTips.JOURNAL_USE_1);
        event.getToolTip().add(AgriToolTips.JOURNAL_USE_2);
    }
}
Also used : StringTextComponent(net.minecraft.util.text.StringTextComponent) ItemStack(net.minecraft.item.ItemStack) IAgriJournalItem(com.infinityraider.agricraft.api.v1.content.items.IAgriJournalItem) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Aggregations

SubscribeEvent (net.minecraftforge.eventbus.api.SubscribeEvent)87 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 Player (net.minecraft.world.entity.player.Player)8 BlockPos (net.minecraft.util.math.BlockPos)7 Entity (net.minecraft.world.entity.Entity)7 ItemStack (net.minecraft.world.item.ItemStack)7 CompoundNBT (net.minecraft.nbt.CompoundNBT)6 Minecraft (net.minecraft.client.Minecraft)5 BlockPos (net.minecraft.core.BlockPos)5 ServerPlayer (net.minecraft.server.level.ServerPlayer)5 StringTextComponent (net.minecraft.util.text.StringTextComponent)5 Item (net.minecraft.world.item.Item)5 BlockItem (net.minecraft.item.BlockItem)4 ResourceLocation (net.minecraft.resources.ResourceLocation)4 BlockState (net.minecraft.world.level.block.state.BlockState)4 OnlyIn (net.minecraftforge.api.distmarker.OnlyIn)4