use of net.minecraft.world.WorldServer in project SpongeCommon by SpongePowered.
the class DeathPhase method unwind.
@Override
public void unwind(BasicEntityContext context) {
final Entity dyingEntity = context.getSource(Entity.class).orElseThrow(TrackingUtil.throwWithContext("Dying entity not found!", context));
final DamageSource damageSource = context.getDamageSource();
try (StackFrame frame = Sponge.getCauseStackManager().pushCauseFrame()) {
Sponge.getCauseStackManager().pushCause(damageSource);
Sponge.getCauseStackManager().pushCause(dyingEntity);
final boolean isPlayer = dyingEntity instanceof EntityPlayer;
final EntityPlayer entityPlayer = isPlayer ? (EntityPlayer) dyingEntity : null;
final Optional<User> notifier = context.getNotifier();
final Optional<User> owner = context.getOwner();
final User entityCreator = notifier.orElseGet(() -> owner.orElse(null));
context.getCapturedEntitySupplier().acceptAndClearIfNotEmpty(entities -> {
// Separate experience orbs from other entity drops
final List<Entity> experience = entities.stream().filter(entity -> entity instanceof ExperienceOrb).collect(Collectors.toList());
if (!experience.isEmpty()) {
Sponge.getCauseStackManager().addContext(EventContextKeys.SPAWN_TYPE, InternalSpawnTypes.EXPERIENCE);
final SpawnEntityEvent spawnEntityEvent = SpongeEventFactory.createSpawnEntityEvent(Sponge.getCauseStackManager().getCurrentCause(), experience);
SpongeImpl.postEvent(spawnEntityEvent);
if (!spawnEntityEvent.isCancelled()) {
for (Entity entity : spawnEntityEvent.getEntities()) {
EntityUtil.getMixinWorld(entity).forceSpawnEntity(entity);
}
}
}
// Now process other entities, this is separate from item drops specifically
final List<Entity> other = entities.stream().filter(entity -> !(entity instanceof ExperienceOrb)).collect(Collectors.toList());
if (!other.isEmpty()) {
Sponge.getCauseStackManager().addContext(EventContextKeys.SPAWN_TYPE, InternalSpawnTypes.ENTITY_DEATH);
final SpawnEntityEvent spawnEntityEvent = SpongeEventFactory.createSpawnEntityEvent(Sponge.getCauseStackManager().getCurrentCause(), experience);
SpongeImpl.postEvent(spawnEntityEvent);
if (!spawnEntityEvent.isCancelled()) {
for (Entity entity : spawnEntityEvent.getEntities()) {
EntityUtil.getMixinWorld(entity).forceSpawnEntity(entity);
}
}
}
});
Sponge.getCauseStackManager().addContext(EventContextKeys.SPAWN_TYPE, InternalSpawnTypes.DROPPED_ITEM);
// This allows mods such as Draconic Evolution to add items to the drop list
if (context.getCapturedEntityItemDropSupplier().isEmpty() && context.getCapturedEntityDropSupplier().isEmpty()) {
final ArrayList<Entity> entities = new ArrayList<>();
final DropItemEvent.Destruct destruct = SpongeEventFactory.createDropItemEventDestruct(frame.getCurrentCause(), entities);
SpongeImpl.postEvent(destruct);
if (!destruct.isCancelled()) {
for (Entity entity : destruct.getEntities()) {
EntityUtil.getMixinWorld(entity).forceSpawnEntity(entity);
}
}
return;
}
context.getCapturedEntityItemDropSupplier().acceptAndRemoveIfPresent(dyingEntity.getUniqueId(), items -> {
final ArrayList<Entity> entities = new ArrayList<>();
for (EntityItem item : items) {
entities.add(EntityUtil.fromNative(item));
}
if (isPlayer) {
// Forge and Vanilla always clear items on player death BEFORE drops occur
// This will also provide the highest compatibility with mods such as Tinkers Construct
entityPlayer.inventory.clear();
}
final DropItemEvent.Destruct destruct = SpongeEventFactory.createDropItemEventDestruct(Sponge.getCauseStackManager().getCurrentCause(), entities);
SpongeImpl.postEvent(destruct);
if (!destruct.isCancelled()) {
for (Entity entity : destruct.getEntities()) {
EntityUtil.getMixinWorld(entity).forceSpawnEntity(entity);
}
}
// Note: If cancelled, the items do not spawn in the world and are NOT copied back to player inventory.
// This avoids many issues with mods such as Tinkers Construct's soulbound items.
});
// Note that this is only used if and when item pre-merging is enabled. Which is never enabled in forge.
context.getCapturedEntityDropSupplier().acceptAndRemoveIfPresent(dyingEntity.getUniqueId(), itemStacks -> {
final List<ItemDropData> items = new ArrayList<>();
items.addAll(itemStacks);
if (!items.isEmpty()) {
final net.minecraft.entity.Entity minecraftEntity = EntityUtil.toNative(dyingEntity);
final List<Entity> itemEntities = items.stream().map(data -> data.create((WorldServer) minecraftEntity.world)).map(EntityUtil::fromNative).collect(Collectors.toList());
if (isPlayer) {
// Forge and Vanilla always clear items on player death BEFORE drops occur
// This will also provide the highest compatibility with mods such as Tinkers Construct
entityPlayer.inventory.clear();
}
final DropItemEvent.Destruct destruct = SpongeEventFactory.createDropItemEventDestruct(Sponge.getCauseStackManager().getCurrentCause(), itemEntities);
SpongeImpl.postEvent(destruct);
if (!destruct.isCancelled()) {
for (Entity entity : destruct.getEntities()) {
if (entityCreator != null) {
EntityUtil.toMixin(entity).setCreator(entityCreator.getUniqueId());
}
EntityUtil.getMixinWorld(entity).forceSpawnEntity(entity);
}
}
// Note: If cancelled, the items do not spawn in the world and are NOT copied back to player inventory.
// This avoids many issues with mods such as Tinkers Construct's soulbound items.
}
});
}
}
use of net.minecraft.world.WorldServer in project SpongeCommon by SpongePowered.
the class MixinWorldServer method createWorldGenerator.
@Override
public SpongeWorldGenerator createWorldGenerator(String settings) {
final WorldServer worldServer = (WorldServer) (Object) this;
final WorldType worldType = worldServer.getWorldType();
final IChunkGenerator chunkGenerator;
final BiomeProvider biomeProvider;
if (worldType instanceof SpongeWorldType) {
chunkGenerator = ((SpongeWorldType) worldType).getChunkGenerator(worldServer, settings);
biomeProvider = ((SpongeWorldType) worldType).getBiomeProvider(worldServer);
} else {
final IChunkGenerator currentGenerator = this.getChunkProvider().chunkGenerator;
if (currentGenerator != null) {
chunkGenerator = currentGenerator;
} else {
final WorldProvider worldProvider = worldServer.provider;
((IMixinWorldProvider) worldProvider).setGeneratorSettings(settings);
chunkGenerator = worldProvider.createChunkGenerator();
}
biomeProvider = worldServer.provider.biomeProvider;
}
return new SpongeWorldGenerator(worldServer, (BiomeGenerator) biomeProvider, SpongeGenerationPopulator.of(worldServer, chunkGenerator));
}
use of net.minecraft.world.WorldServer in project SpongeCommon by SpongePowered.
the class EntityActivationRange method activateEntities.
/**
* Find what entities are in range of the players in the world and set
* active if in range.
*
* @param world The world to perform activation checks in
*/
public static void activateEntities(World world) {
if (((IMixinWorld) world).isFake()) {
return;
}
for (EntityPlayer player : world.playerEntities) {
int maxRange = 0;
for (Integer range : maxActivationRanges.values()) {
if (range > maxRange) {
maxRange = range;
}
}
maxRange = Math.min((((org.spongepowered.api.world.World) world).getViewDistance() << 4) - 8, maxRange);
((IModData_Activation) player).setActivatedTick(SpongeImpl.getServer().getTickCounter());
growBb(maxBB, player.getEntityBoundingBox(), maxRange, 256, maxRange);
int i = MathHelper.floor(maxBB.minX / 16.0D);
int j = MathHelper.floor(maxBB.maxX / 16.0D);
int k = MathHelper.floor(maxBB.minZ / 16.0D);
int l = MathHelper.floor(maxBB.maxZ / 16.0D);
for (int i1 = i; i1 <= j; ++i1) {
for (int j1 = k; j1 <= l; ++j1) {
WorldServer worldserver = (WorldServer) world;
Chunk chunk = ((IMixinChunkProviderServer) worldserver.getChunkProvider()).getLoadedChunkWithoutMarkingActive(i1, j1);
if (chunk != null) {
activateChunkEntities(player, chunk);
}
}
}
}
}
use of net.minecraft.world.WorldServer in project SpongeCommon by SpongePowered.
the class MixinChunk_Tracker method addTrackedBlockPosition.
@Override
public void addTrackedBlockPosition(Block block, BlockPos pos, User user, PlayerTracker.Type trackerType) {
if (this.world.isRemote) {
return;
}
if (PhaseTracker.getInstance().getCurrentState().ignoresBlockTracking()) {
// Don't track chunk gen
return;
}
// Don't track fake players
if (user instanceof EntityPlayerMP && SpongeImplHooks.isFakePlayer((EntityPlayerMP) user)) {
return;
}
if (!SpongeHooks.getActiveConfig((WorldServer) this.world).getConfig().getBlockTracking().getBlockBlacklist().contains(((BlockType) block).getId())) {
SpongeHooks.logBlockTrack(this.world, block, pos, user, true);
} else {
SpongeHooks.logBlockTrack(this.world, block, pos, user, false);
}
final IMixinWorldInfo worldInfo = (IMixinWorldInfo) this.world.getWorldInfo();
final int indexForUniqueId = worldInfo.getIndexForUniqueId(user.getUniqueId());
if (pos.getY() <= 255) {
short blockPos = blockPosToShort(pos);
final PlayerTracker playerTracker = this.trackedShortBlockPositions.get(blockPos);
if (playerTracker != null) {
if (trackerType == PlayerTracker.Type.OWNER) {
playerTracker.ownerIndex = indexForUniqueId;
playerTracker.notifierIndex = indexForUniqueId;
} else {
playerTracker.notifierIndex = indexForUniqueId;
}
} else {
this.trackedShortBlockPositions.put(blockPos, new PlayerTracker(indexForUniqueId, trackerType));
}
} else {
int blockPos = blockPosToInt(pos);
final PlayerTracker playerTracker = this.trackedIntBlockPositions.get(blockPos);
if (playerTracker != null) {
if (trackerType == PlayerTracker.Type.OWNER) {
playerTracker.ownerIndex = indexForUniqueId;
} else {
playerTracker.notifierIndex = indexForUniqueId;
}
} else {
this.trackedIntBlockPositions.put(blockPos, new PlayerTracker(indexForUniqueId, trackerType));
}
}
}
use of net.minecraft.world.WorldServer in project SpongeCommon by SpongePowered.
the class MixinWorldServer method createSnapshot.
@Override
public BlockSnapshot createSnapshot(int x, int y, int z) {
BlockPos pos = new BlockPos(x, y, z);
IBlockState currentState = this.getBlockState(pos);
return this.createSpongeBlockSnapshot(currentState, currentState.getActualState((WorldServer) (Object) this, pos), pos, // it DOES tell the client about the block change.
BlockChangeFlags.PHYSICS_OBSERVER);
}
Aggregations