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