Search in sources :

Example 46 with SubscribeEvent

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

the class ForgeInternalHandler method onEntityJoinWorld.

@SubscribeEvent(priority = EventPriority.HIGHEST)
public void onEntityJoinWorld(EntityJoinWorldEvent event) {
    Entity entity = event.getEntity();
    if (entity.getClass().equals(ItemEntity.class)) {
        ItemStack stack = ((ItemEntity) entity).getItem();
        Item item = stack.getItem();
        if (item.hasCustomEntity(stack)) {
            Entity newEntity = item.createEntity(event.getWorld(), entity, stack);
            if (newEntity != null) {
                entity.discard();
                event.setCanceled(true);
                var executor = LogicalSidedProvider.WORKQUEUE.get(event.getWorld().isClientSide ? LogicalSide.CLIENT : LogicalSide.SERVER);
                executor.tell(new TickTask(0, () -> event.getWorld().addFreshEntity(newEntity)));
            }
        }
    }
}
Also used : Entity(net.minecraft.world.entity.Entity) ItemEntity(net.minecraft.world.entity.item.ItemEntity) Item(net.minecraft.world.item.Item) ItemEntity(net.minecraft.world.entity.item.ItemEntity) ItemStack(net.minecraft.world.item.ItemStack) TickTask(net.minecraft.server.TickTask) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 47 with SubscribeEvent

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

the class ForgeInternalHandler method onResourceReload.

@SubscribeEvent
public void onResourceReload(AddReloadListenerEvent event) {
    INSTANCE = new LootModifierManager();
    event.addListener(INSTANCE);
}
Also used : LootModifierManager(net.minecraftforge.common.loot.LootModifierManager) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 48 with SubscribeEvent

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

the class ModelDataManager method onChunkUnload.

@SubscribeEvent
public static void onChunkUnload(ChunkEvent.Unload event) {
    if (!event.getChunk().getWorldForge().isClientSide())
        return;
    ChunkPos chunk = event.getChunk().getPos();
    needModelDataRefresh.remove(chunk);
    modelDataCache.remove(chunk);
}
Also used : ChunkPos(net.minecraft.world.level.ChunkPos) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 49 with SubscribeEvent

use of net.minecraftforge.eventbus.api.SubscribeEvent in project Geolosys by oitsjustjose.

the class PlutonRegistry method onBiomesLoaded.

@SubscribeEvent
public void onBiomesLoaded(BiomeLoadingEvent evt) {
    BiomeGenerationSettingsBuilder settings = evt.getGeneration();
    // Removes vanilla ores
    if (CommonConfig.REMOVE_VANILLA_ORES.get()) {
        for (GenerationStage.Decoration deco : decorations) {
            FeatureUtils.destroyFeature(settings.getFeatures(deco), OreRemover.filterFeatures(settings.getFeatures(deco)));
        }
    }
    DepositFeature o = new DepositFeature(NoFeatureConfig.CODEC);
    settings.withFeature(GenerationStage.Decoration.UNDERGROUND_ORES, o.withConfiguration(NoFeatureConfig.NO_FEATURE_CONFIG));
}
Also used : GenerationStage(net.minecraft.world.gen.GenerationStage) DepositFeature(com.oitsjustjose.geolosys.common.world.feature.DepositFeature) BiomeGenerationSettingsBuilder(net.minecraftforge.common.world.BiomeGenerationSettingsBuilder) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Example 50 with SubscribeEvent

use of net.minecraftforge.eventbus.api.SubscribeEvent in project Geolosys by oitsjustjose.

the class ManualGifting method onPlayerJoin.

@SubscribeEvent
public void onPlayerJoin(PlayerEvent.PlayerLoggedInEvent event) {
    if (!CommonConfig.GIVE_MANUAL_TO_NEW.get()) {
        return;
    }
    PlayerEntity player = event.getPlayer();
    IDepositCapability geolosysCap = event.getEntity().getEntityWorld().getCapability(GeolosysAPI.GEOLOSYS_WORLD_CAPABILITY).orElse(null);
    if (geolosysCap == null) {
        return;
    }
    if (!geolosysCap.hasPlayerReceivedManual(player.getUniqueID())) {
        ItemHandlerHelper.giveItemToPlayer(player, PatchouliAPI.get().getBookStack(new ResourceLocation(Constants.MODID, "field_manual")));
        geolosysCap.setPlayerReceivedManual(player.getUniqueID());
    }
}
Also used : ResourceLocation(net.minecraft.util.ResourceLocation) IDepositCapability(com.oitsjustjose.geolosys.common.world.capability.IDepositCapability) PlayerEntity(net.minecraft.entity.player.PlayerEntity) 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