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