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;
})));
}
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);
}
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());
}
}
}
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)));
}
}
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);
}
}
Aggregations