Search in sources :

Example 21 with Entity

use of net.minecraft.world.entity.Entity 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 22 with Entity

use of net.minecraft.world.entity.Entity in project MinecraftForge by MinecraftForge.

the class GravityAttributeTest method worldTick.

@SubscribeEvent
public void worldTick(TickEvent.WorldTickEvent event) {
    if (!event.world.isClientSide) {
        if (ticks++ > 60) {
            ticks = 0;
            Level w = event.world;
            List<LivingEntity> list;
            if (w.isClientSide) {
                ClientLevel cw = (ClientLevel) w;
                list = new ArrayList<>(100);
                for (Entity e : cw.entitiesForRendering()) {
                    if (e.isAlive() && e instanceof LivingEntity)
                        list.add((LivingEntity) e);
                }
            } else {
                ServerLevel sw = (ServerLevel) w;
                Stream<LivingEntity> s = StreamSupport.stream(sw.getEntities().getAll().spliterator(), false).filter(Entity::isAlive).filter(e -> e instanceof LivingEntity).map(e -> (LivingEntity) e);
                list = s.collect(Collectors.toList());
            }
            for (LivingEntity liv : list) {
                AttributeInstance grav = liv.getAttribute(ForgeMod.ENTITY_GRAVITY.get());
                boolean inPlains = liv.level.getBiome(liv.blockPosition()).getBiomeCategory() == BiomeCategory.PLAINS;
                if (inPlains && !grav.hasModifier(REDUCED_GRAVITY)) {
                    logger.info("Granted low gravity to Entity: {}", liv);
                    grav.addTransientModifier(REDUCED_GRAVITY);
                } else if (!inPlains && grav.hasModifier(REDUCED_GRAVITY)) {
                    logger.info("Removed low gravity from Entity: {}", liv);
                    grav.removeModifier(REDUCED_GRAVITY);
                }
            }
        }
    }
}
Also used : LivingEntity(net.minecraft.world.entity.LivingEntity) LivingEntity(net.minecraft.world.entity.LivingEntity) CreativeModeTab(net.minecraft.world.item.CreativeModeTab) Item(net.minecraft.world.item.Item) ForgeMod(net.minecraftforge.common.ForgeMod) ClientLevel(net.minecraft.client.multiplayer.ClientLevel) Multimap(com.google.common.collect.Multimap) ServerLevel(net.minecraft.server.level.ServerLevel) ArrayList(java.util.ArrayList) FMLJavaModLoadingContext(net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext) AttributeInstance(net.minecraft.world.entity.ai.attributes.AttributeInstance) AttributeModifier(net.minecraft.world.entity.ai.attributes.AttributeModifier) RegistryEvent(net.minecraftforge.event.RegistryEvent) StreamSupport(java.util.stream.StreamSupport) Mod(net.minecraftforge.fml.common.Mod) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent) Properties(net.minecraft.world.item.Item.Properties) BiomeCategory(net.minecraft.world.level.biome.Biome.BiomeCategory) UUID(java.util.UUID) TickEvent(net.minecraftforge.event.TickEvent) Collectors(java.util.stream.Collectors) Attribute(net.minecraft.world.entity.ai.attributes.Attribute) List(java.util.List) MinecraftForge(net.minecraftforge.common.MinecraftForge) Stream(java.util.stream.Stream) Logger(org.apache.logging.log4j.Logger) Entity(net.minecraft.world.entity.Entity) Operation(net.minecraft.world.entity.ai.attributes.AttributeModifier.Operation) EquipmentSlot(net.minecraft.world.entity.EquipmentSlot) Level(net.minecraft.world.level.Level) LogManager(org.apache.logging.log4j.LogManager) Rarity(net.minecraft.world.item.Rarity) LivingEntity(net.minecraft.world.entity.LivingEntity) Entity(net.minecraft.world.entity.Entity) ServerLevel(net.minecraft.server.level.ServerLevel) ClientLevel(net.minecraft.client.multiplayer.ClientLevel) AttributeInstance(net.minecraft.world.entity.ai.attributes.AttributeInstance) ClientLevel(net.minecraft.client.multiplayer.ClientLevel) ServerLevel(net.minecraft.server.level.ServerLevel) Level(net.minecraft.world.level.Level) SubscribeEvent(net.minecraftforge.eventbus.api.SubscribeEvent)

Aggregations

Entity (net.minecraft.world.entity.Entity)22 CraftEntity (org.bukkit.craftbukkit.v1_17_R1.entity.CraftEntity)9 CraftEntity (org.bukkit.craftbukkit.v1_18_R1.entity.CraftEntity)9 FakeEntity (com.denizenscript.denizen.utilities.entity.FakeEntity)8 LivingEntity (org.bukkit.entity.LivingEntity)8 EntityAttachmentHelper (com.denizenscript.denizen.utilities.entity.EntityAttachmentHelper)6 SynchedEntityData (net.minecraft.network.syncher.SynchedEntityData)4 LivingEntity (net.minecraft.world.entity.LivingEntity)4 Vector (org.bukkit.util.Vector)4 EquipmentSlot (net.minecraft.world.entity.EquipmentSlot)3 ItemStack (net.minecraft.world.item.ItemStack)3 PlayerTag (com.denizenscript.denizen.objects.PlayerTag)2 FakeEquipCommand (com.denizenscript.denizen.scripts.commands.entity.FakeEquipCommand)2 DisguiseCommand (com.denizenscript.denizen.scripts.commands.player.DisguiseCommand)2 Pair (com.mojang.datafixers.util.Pair)2 BlockPos (net.minecraft.core.BlockPos)2 NonNullList (net.minecraft.core.NonNullList)2 SectionPos (net.minecraft.core.SectionPos)2 ResourceLocation (net.minecraft.resources.ResourceLocation)2 DamageSource (net.minecraft.world.damagesource.DamageSource)2