Search in sources :

Example 1 with TickTask

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)));
            }
        }
    }
}
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 2 with TickTask

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));
    }
}
Also used : TickTaskBridge(org.spongepowered.common.bridge.server.TickTaskBridge) TickTask(net.minecraft.server.TickTask) Inject(org.spongepowered.asm.mixin.injection.Inject)

Aggregations

TickTask (net.minecraft.server.TickTask)2 Entity (net.minecraft.world.entity.Entity)1 ItemEntity (net.minecraft.world.entity.item.ItemEntity)1 Item (net.minecraft.world.item.Item)1 ItemStack (net.minecraft.world.item.ItemStack)1 SubscribeEvent (net.minecraftforge.eventbus.api.SubscribeEvent)1 Inject (org.spongepowered.asm.mixin.injection.Inject)1 TickTaskBridge (org.spongepowered.common.bridge.server.TickTaskBridge)1