use of net.minecraft.server.TickTask 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.server.TickTask in project SpongeCommon by SpongePowered.
the class MinecraftServerMixin_Tracker method tracker$associatePhaseContextWithWrappedTask.
@Inject(method = "wrapRunnable(Ljava/lang/Runnable;)Lnet/minecraft/server/TickTask;", at = @At("RETURN"))
private void tracker$associatePhaseContextWithWrappedTask(final Runnable runnable, final CallbackInfoReturnable<TickTask> cir) {
final TickTask returnValue = cir.getReturnValue();
if (!PhaseTracker.SERVER.onSidedThread()) {
final PhaseContext<@NonNull ?> phaseContext = PhaseTracker.getInstance().getPhaseContext();
if (phaseContext.isEmpty()) {
return;
}
phaseContext.foldContextForThread(((TickTaskBridge) returnValue));
}
}
Aggregations