Search in sources :

Example 11 with IMixinWorldServer

use of org.spongepowered.common.interfaces.world.IMixinWorldServer in project SpongeCommon by SpongePowered.

the class ExplosionState method spawnEntityOrCapture.

@Override
public boolean spawnEntityOrCapture(ExplosionContext context, Entity entity, int chunkX, int chunkZ) {
    return context.getBlockPosition().map(blockPos -> {
        // TODO - this needs to be guaranteed. can't be bothered to figure out why it isn't
        final Multimap<BlockPos, net.minecraft.entity.Entity> blockPosEntityMultimap = context.getBlockEntitySpawnSupplier().get();
        final Multimap<BlockPos, EntityItem> blockPosEntityItemMultimap = context.getBlockItemDropSupplier().get();
        if (entity instanceof EntityItem) {
            blockPosEntityItemMultimap.put(blockPos, (EntityItem) entity);
        } else {
            blockPosEntityMultimap.put(blockPos, (net.minecraft.entity.Entity) entity);
        }
        return true;
    }).orElseGet(() -> {
        final ArrayList<Entity> entities = new ArrayList<>(1);
        entities.add(entity);
        final SpawnEntityEvent event = SpongeEventFactory.createSpawnEntityEvent(Sponge.getCauseStackManager().getCurrentCause(), entities);
        SpongeImpl.postEvent(event);
        if (!event.isCancelled() && event.getEntities().size() > 0) {
            for (Entity item : event.getEntities()) {
                ((IMixinWorldServer) item.getWorld()).forceSpawnEntity(item);
            }
            return true;
        }
        return false;
    });
}
Also used : SpongeImpl(org.spongepowered.common.SpongeImpl) EventContextKeys(org.spongepowered.api.event.cause.EventContextKeys) ChangeBlockEvent(org.spongepowered.api.event.block.ChangeBlockEvent) IMixinWorldServer(org.spongepowered.common.interfaces.world.IMixinWorldServer) Multimap(com.google.common.collect.Multimap) ArrayList(java.util.ArrayList) Lists(com.google.common.collect.Lists) TrackingUtil(org.spongepowered.common.event.tracking.TrackingUtil) ImmutableList(com.google.common.collect.ImmutableList) CauseStackManager(org.spongepowered.api.event.CauseStackManager) Transaction(org.spongepowered.api.data.Transaction) EntityItem(net.minecraft.entity.item.EntityItem) IPhaseState(org.spongepowered.common.event.tracking.IPhaseState) Location(org.spongepowered.api.world.Location) User(org.spongepowered.api.entity.living.player.User) Iterator(java.util.Iterator) IMixinLocation(org.spongepowered.common.interfaces.world.IMixinLocation) SpongeEventFactory(org.spongepowered.api.event.SpongeEventFactory) Sponge(org.spongepowered.api.Sponge) BlockPos(net.minecraft.util.math.BlockPos) SpawnEntityEvent(org.spongepowered.api.event.entity.SpawnEntityEvent) InternalSpawnTypes(org.spongepowered.common.registry.type.event.InternalSpawnTypes) Entity(org.spongepowered.api.entity.Entity) BlockChange(org.spongepowered.common.world.BlockChange) EntityUtil(org.spongepowered.common.entity.EntityUtil) TrackingUtil.iterateChangeBlockEvents(org.spongepowered.common.event.tracking.TrackingUtil.iterateChangeBlockEvents) List(java.util.List) Explosion(org.spongepowered.api.world.explosion.Explosion) PhaseContext(org.spongepowered.common.event.tracking.PhaseContext) Vector3i(com.flowpowered.math.vector.Vector3i) BlockChangeFlags(org.spongepowered.api.world.BlockChangeFlags) World(org.spongepowered.api.world.World) VecHelper(org.spongepowered.common.util.VecHelper) ExplosionEvent(org.spongepowered.api.event.world.ExplosionEvent) BlockSnapshot(org.spongepowered.api.block.BlockSnapshot) Multimap(com.google.common.collect.Multimap) Entity(org.spongepowered.api.entity.Entity) ArrayList(java.util.ArrayList) IMixinWorldServer(org.spongepowered.common.interfaces.world.IMixinWorldServer) SpawnEntityEvent(org.spongepowered.api.event.entity.SpawnEntityEvent) EntityItem(net.minecraft.entity.item.EntityItem)

Example 12 with IMixinWorldServer

use of org.spongepowered.common.interfaces.world.IMixinWorldServer in project SpongeCommon by SpongePowered.

the class GeneralGenerationPhaseState method spawnEntityOrCapture.

@Override
public boolean spawnEntityOrCapture(G context, Entity entity, int chunkX, int chunkZ) {
    final ArrayList<Entity> entities = new ArrayList<>(1);
    entities.add(entity);
    try (CauseStackManager.StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame()) {
        frame.pushCause(entity.getLocation().getExtent());
        frame.addContext(EventContextKeys.SPAWN_TYPE, SpawnTypes.WORLD_SPAWNER);
        final SpawnEntityEvent event = SpongeEventFactory.createSpawnEntityEventSpawner(frame.getCurrentCause(), entities);
        SpongeImpl.postEvent(event);
        if (!event.isCancelled() && event.getEntities().size() > 0) {
            for (Entity item : event.getEntities()) {
                ((IMixinWorldServer) item.getWorld()).forceSpawnEntity(item);
            }
            return true;
        }
        return false;
    }
}
Also used : Entity(org.spongepowered.api.entity.Entity) CauseStackManager(org.spongepowered.api.event.CauseStackManager) ArrayList(java.util.ArrayList) IMixinWorldServer(org.spongepowered.common.interfaces.world.IMixinWorldServer) SpawnEntityEvent(org.spongepowered.api.event.entity.SpawnEntityEvent)

Example 13 with IMixinWorldServer

use of org.spongepowered.common.interfaces.world.IMixinWorldServer in project SpongeCommon by SpongePowered.

the class CloseWindowState method unwind.

@Override
public void unwind(BasicPacketContext context) {
    final EntityPlayerMP player = context.getSource(EntityPlayerMP.class).get();
    final Container container = context.getOpenContainer();
    ItemStackSnapshot lastCursor = context.getCursor();
    ItemStackSnapshot newCursor = ItemStackUtil.snapshotOf(player.inventory.getItemStack());
    if (lastCursor != null) {
        Sponge.getCauseStackManager().pushCause(player);
        InteractInventoryEvent.Close event = SpongeCommonEventFactory.callInteractInventoryCloseEvent(container, player, lastCursor, newCursor, true);
        if (event.isCancelled()) {
            Sponge.getCauseStackManager().popCause();
            return;
        }
        Sponge.getCauseStackManager().popCause();
    }
    try (CauseStackManager.StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame()) {
        Sponge.getCauseStackManager().pushCause(player);
        // Non-merged
        Sponge.getCauseStackManager().addContext(EventContextKeys.SPAWN_TYPE, SpawnTypes.PLACEMENT);
        // items
        context.getCapturedItemsSupplier().acceptAndClearIfNotEmpty(items -> {
            final List<Entity> entities = items.stream().map(EntityUtil::fromNative).collect(Collectors.toList());
            if (!entities.isEmpty()) {
                DropItemEvent.Custom drop = SpongeEventFactory.createDropItemEventCustom(Sponge.getCauseStackManager().getCurrentCause(), entities);
                SpongeImpl.postEvent(drop);
                if (!drop.isCancelled()) {
                    for (Entity droppedItem : drop.getEntities()) {
                        droppedItem.setCreator(player.getUniqueID());
                        ((IMixinWorldServer) player.getServerWorld()).forceSpawnEntity(droppedItem);
                    }
                }
            }
        });
        // Pre-merged items
        context.getCapturedItemStackSupplier().acceptAndClearIfNotEmpty(stacks -> {
            final List<EntityItem> items = stacks.stream().map(drop -> drop.create(player.getServerWorld())).collect(Collectors.toList());
            final List<Entity> entities = items.stream().map(EntityUtil::fromNative).collect(Collectors.toList());
            if (!entities.isEmpty()) {
                DropItemEvent.Custom drop = SpongeEventFactory.createDropItemEventCustom(Sponge.getCauseStackManager().getCurrentCause(), entities);
                SpongeImpl.postEvent(drop);
                if (!drop.isCancelled()) {
                    for (Entity droppedItem : drop.getEntities()) {
                        droppedItem.setCreator(player.getUniqueID());
                        ((IMixinWorldServer) player.getServerWorld()).forceSpawnEntity(droppedItem);
                    }
                }
            }
        });
    }
    context.getCapturedBlockSupplier().acceptAndClearIfNotEmpty(blocks -> TrackingUtil.processBlockCaptures(blocks, this, context));
}
Also used : EntityItem(net.minecraft.entity.item.EntityItem) SpongeImpl(org.spongepowered.common.SpongeImpl) Packet(net.minecraft.network.Packet) EventContextKeys(org.spongepowered.api.event.cause.EventContextKeys) SpongeEventFactory(org.spongepowered.api.event.SpongeEventFactory) Sponge(org.spongepowered.api.Sponge) InteractInventoryEvent(org.spongepowered.api.event.item.inventory.InteractInventoryEvent) ItemStackSnapshot(org.spongepowered.api.item.inventory.ItemStackSnapshot) IMixinWorldServer(org.spongepowered.common.interfaces.world.IMixinWorldServer) DropItemEvent(org.spongepowered.api.event.item.inventory.DropItemEvent) SpongeCommonEventFactory(org.spongepowered.common.event.SpongeCommonEventFactory) Entity(org.spongepowered.api.entity.Entity) ItemStackUtil(org.spongepowered.common.item.inventory.util.ItemStackUtil) Collectors(java.util.stream.Collectors) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) EntityUtil(org.spongepowered.common.entity.EntityUtil) SpawnTypes(org.spongepowered.api.event.cause.entity.spawn.SpawnTypes) List(java.util.List) TrackingUtil(org.spongepowered.common.event.tracking.TrackingUtil) CauseStackManager(org.spongepowered.api.event.CauseStackManager) Container(net.minecraft.inventory.Container) Entity(org.spongepowered.api.entity.Entity) DropItemEvent(org.spongepowered.api.event.item.inventory.DropItemEvent) InteractInventoryEvent(org.spongepowered.api.event.item.inventory.InteractInventoryEvent) IMixinWorldServer(org.spongepowered.common.interfaces.world.IMixinWorldServer) Container(net.minecraft.inventory.Container) CauseStackManager(org.spongepowered.api.event.CauseStackManager) ItemStackSnapshot(org.spongepowered.api.item.inventory.ItemStackSnapshot) EntityPlayerMP(net.minecraft.entity.player.EntityPlayerMP) EntityItem(net.minecraft.entity.item.EntityItem)

Example 14 with IMixinWorldServer

use of org.spongepowered.common.interfaces.world.IMixinWorldServer in project SpongeCommon by SpongePowered.

the class MixinChunkProviderServer method onConstruct.

@Inject(method = "<init>", at = @At("RETURN"))
private void onConstruct(WorldServer worldObjIn, IChunkLoader chunkLoaderIn, IChunkGenerator chunkGeneratorIn, CallbackInfo ci) {
    this.EMPTY_CHUNK = new SpongeEmptyChunk(worldObjIn, 0, 0);
    SpongeConfig<? extends GeneralConfigBase> spongeConfig = SpongeHooks.getActiveConfig(worldObjIn);
    ((IMixinWorldServer) worldObjIn).setActiveConfig(spongeConfig);
    this.denyChunkRequests = spongeConfig.getConfig().getWorld().getDenyChunkRequests();
    this.chunkUnloadDelay = spongeConfig.getConfig().getWorld().getChunkUnloadDelay() * 1000;
    this.maxChunkUnloads = spongeConfig.getConfig().getWorld().getMaxChunkUnloads();
}
Also used : IMixinWorldServer(org.spongepowered.common.interfaces.world.IMixinWorldServer) SpongeEmptyChunk(org.spongepowered.common.world.SpongeEmptyChunk) Inject(org.spongepowered.asm.mixin.injection.Inject)

Example 15 with IMixinWorldServer

use of org.spongepowered.common.interfaces.world.IMixinWorldServer in project SpongeCommon by SpongePowered.

the class MixinBlock_BlockCapturing method initializeBlockCapturingState.

@Override
public void initializeBlockCapturingState(World worldIn) {
    SpongeConfig<? extends GeneralConfigBase> activeConfig = ((IMixinWorldServer) worldIn).getActiveConfig();
    BlockCapturingCategory blockCapturing = activeConfig.getConfig().getBlockCapturing();
    String[] ids = this.getId().split(":");
    String modId = ids[0];
    String name = ids[1];
    BlockCapturingModCategory modCapturing = blockCapturing.getModMappings().get(modId);
    if (modCapturing == null && blockCapturing.autoPopulateData()) {
        modCapturing = new BlockCapturingModCategory();
        blockCapturing.getModMappings().put(modId.toLowerCase(), modCapturing);
        modCapturing.getBlockMap().put(name.toLowerCase(), false);
        if (blockCapturing.autoPopulateData()) {
            activeConfig.save();
        }
        return;
    } else if (modCapturing != null) {
        if (!modCapturing.isEnabled()) {
            this.processTickChangesImmediately = false;
            return;
        }
        Boolean processImmediately = modCapturing.getBlockMap().get(name.toLowerCase());
        if (processImmediately != null) {
            this.processTickChangesImmediately = processImmediately;
        }
    }
    if (blockCapturing.autoPopulateData()) {
        activeConfig.save();
    }
}
Also used : BlockCapturingCategory(org.spongepowered.common.config.category.BlockCapturingCategory) IMixinWorldServer(org.spongepowered.common.interfaces.world.IMixinWorldServer) BlockCapturingModCategory(org.spongepowered.common.config.category.BlockCapturingModCategory)

Aggregations

IMixinWorldServer (org.spongepowered.common.interfaces.world.IMixinWorldServer)61 WorldServer (net.minecraft.world.WorldServer)25 BlockPos (net.minecraft.util.math.BlockPos)19 ArrayList (java.util.ArrayList)17 Entity (org.spongepowered.api.entity.Entity)15 World (org.spongepowered.api.world.World)15 IBlockState (net.minecraft.block.state.IBlockState)13 SpawnEntityEvent (org.spongepowered.api.event.entity.SpawnEntityEvent)13 CauseStackManager (org.spongepowered.api.event.CauseStackManager)11 Overwrite (org.spongepowered.asm.mixin.Overwrite)11 BlockSnapshot (org.spongepowered.api.block.BlockSnapshot)9 IMixinEntity (org.spongepowered.common.interfaces.entity.IMixinEntity)9 EntityItem (net.minecraft.entity.item.EntityItem)8 User (org.spongepowered.api.entity.living.player.User)8 LocatableBlock (org.spongepowered.api.world.LocatableBlock)8 PhaseTracker (org.spongepowered.common.event.tracking.PhaseTracker)7 Entity (net.minecraft.entity.Entity)6 EntityPlayer (net.minecraft.entity.player.EntityPlayer)6 Chunk (net.minecraft.world.chunk.Chunk)6 IMixinChunk (org.spongepowered.common.interfaces.IMixinChunk)6