use of net.minecraft.world.WorldServer in project MorePlanets by SteveKunG.
the class PacketSimpleMP method handleServerSide.
@Override
public void handleServerSide(EntityPlayer player) {
EntityPlayerMP playerMP = PlayerUtil.getPlayerBaseServerFromPlayer(player, false);
World world = player.world;
TileEntity tile;
BlockPos pos;
String type;
switch(this.type) {
case S_FIRE_EXTINGUISH:
pos = (BlockPos) this.data.get(0);
world.playSound(null, pos, SoundEvents.BLOCK_FIRE_EXTINGUISH, SoundCategory.BLOCKS, 0.5F, 2.6F + (world.rand.nextFloat() - world.rand.nextFloat()) * 0.8F);
world.setBlockToAir(pos);
break;
case S_RESPAWN_PLAYER_NETHER:
if (world instanceof WorldServer) {
WorldServer worldOld = (WorldServer) world;
WorldServer worldNew = WorldDimensionHelper.getStartWorld(worldOld);
BlockPos spawnPos = worldNew.getTopSolidOrLiquidBlock(worldNew.getSpawnPoint());
TeleportUtil.setWarpDimension(playerMP, worldNew, spawnPos.getX(), spawnPos.getY(), spawnPos.getZ(), WorldUtil.getProviderForNameServer(WorldTickEventHandler.startedDimensionData.planetToBack).getDimension(), true);
player.respawnPlayer();
player.closeScreen();
}
break;
case S_BLACK_HOLE_STORAGE_OPTION:
tile = world.getTileEntity((BlockPos) this.data.get(0));
type = (String) this.data.get(1);
if (tile instanceof TileEntityBlackHoleStorage) {
TileEntityBlackHoleStorage storage = (TileEntityBlackHoleStorage) tile;
switch(type) {
case "disable":
storage.disableBlackHole = !storage.disableBlackHole;
break;
case "collect_mode":
storage.modeInt++;
storage.modeInt %= 3;
switch(storage.modeInt) {
case 0:
storage.collectMode = "item";
break;
case 1:
storage.collectMode = "xp";
break;
case 2:
storage.collectMode = "item_and_xp";
break;
}
break;
case "use_hopper":
storage.useHopper = !storage.useHopper;
break;
}
}
break;
case S_SHIELD_VISIBLE:
tile = world.getTileEntity((BlockPos) this.data.get(0));
if (tile instanceof TileEntityShieldGenerator) {
TileEntityShieldGenerator shield = (TileEntityShieldGenerator) tile;
shield.setBubbleVisible((boolean) this.data.get(1));
}
break;
case S_ENABLE_SHIELD:
tile = world.getTileEntity((BlockPos) this.data.get(0));
if (tile instanceof TileEntityShieldGenerator) {
TileEntityShieldGenerator shield = (TileEntityShieldGenerator) tile;
shield.enableShield = !shield.enableShield;
}
break;
case S_ENABLE_SHIELD_DAMAGE:
tile = world.getTileEntity((BlockPos) this.data.get(0));
if (tile instanceof TileEntityShieldGenerator) {
TileEntityShieldGenerator shield = (TileEntityShieldGenerator) tile;
shield.enableDamage = !shield.enableDamage;
}
break;
case S_SHIELD_GENERATOR_OPTION:
tile = world.getTileEntity((BlockPos) this.data.get(0));
int value = (int) this.data.get(1);
type = (String) this.data.get(2);
if (tile instanceof TileEntityShieldGenerator) {
TileEntityShieldGenerator shield = (TileEntityShieldGenerator) tile;
switch(type) {
case "damage":
shield.shieldDamage = value;
break;
case "size":
shield.maxShieldSize = value;
break;
}
}
break;
case S_SWITCH_SHIELD_GENERATOR_GUI:
tile = player.world.getTileEntity((BlockPos) this.data.get(0));
boolean isConfig = (boolean) this.data.get(1);
if (tile instanceof TileEntityShieldGenerator) {
TileEntityShieldGenerator shield = (TileEntityShieldGenerator) tile;
PacketSimpleMP.openShieldGeneratorConfig(playerMP, shield, isConfig);
}
break;
default:
break;
}
}
use of net.minecraft.world.WorldServer in project MorePlanets by SteveKunG.
the class WorldTickEventHandler method onServerTick.
@SubscribeEvent
public void onServerTick(ServerTickEvent event) {
MinecraftServer server = FMLCommonHandler.instance().getMinecraftServerInstance();
if (server == null) {
return;
}
if (event.phase == Phase.START) {
if (WorldTickEventHandler.startedDimensionData == null) {
World world = FMLCommonHandler.instance().getMinecraftServerInstance().getWorld(0);
WorldTickEventHandler.startedDimensionData = (WorldDataStartedDimension) world.getMapStorage().getOrLoadData(WorldDataStartedDimension.class, WorldDataStartedDimension.saveDataID);
if (WorldTickEventHandler.startedDimensionData == null) {
WorldTickEventHandler.startedDimensionData = new WorldDataStartedDimension(WorldDataStartedDimension.saveDataID);
world.getMapStorage().setData(WorldDataStartedDimension.saveDataID, WorldTickEventHandler.startedDimensionData);
}
}
}
if (event.phase == Phase.END) {
World world = FMLCommonHandler.instance().getMinecraftServerInstance().getWorld(ConfigManagerMP.idDimensionDiona);
if (world.provider instanceof WorldProviderDiona) {
if (world instanceof WorldServer) {
WorldServer worldServer = (WorldServer) world;
for (Iterator<Chunk> iterator = world.getPersistentChunkIterable(worldServer.getPlayerChunkMap().getChunkIterator()); iterator.hasNext(); world.profiler.endSection()) {
Chunk chunk = iterator.next();
int j = chunk.x * 16;
int k = chunk.z * 16;
if (world.rand.nextInt(75000) == 0) {
this.updateLCG = this.updateLCG * 3 + 1013904223;
int l = this.updateLCG >> 2;
BlockPos blockpos = this.adjustPosToNearbyEntity(world, new BlockPos(j + (l & 15), 0, k + (l >> 8 & 15)));
if (this.canBeamStrike(world, blockpos)) {
EntityAlienBeam beam = new EntityAlienBeam(world);
beam.setLocationAndAngles(blockpos.getX(), blockpos.getY(), blockpos.getZ(), 0.0F, 0.0F);
world.spawnEntity(beam);
}
}
}
}
}
world = FMLCommonHandler.instance().getMinecraftServerInstance().getWorld(ConfigManagerMP.idDimensionNibiru);
if (world.provider instanceof WorldProviderNibiru) {
if (world instanceof WorldServer) {
WorldServer worldServer = (WorldServer) world;
for (Iterator<Chunk> iterator = world.getPersistentChunkIterable(worldServer.getPlayerChunkMap().getChunkIterator()); iterator.hasNext(); world.profiler.endSection()) {
Chunk chunk = iterator.next();
int j = chunk.x * 16;
int k = chunk.z * 16;
boolean flag = world.isRaining();
boolean flag1 = world.isThundering();
if (world.provider.canDoLightning(chunk) && flag && flag1 && world.rand.nextInt(1000) == 0) {
this.updateLCG = this.updateLCG * 3 + 1013904223;
int l = this.updateLCG >> 2;
BlockPos blockpos = this.adjustPosToNearbyEntity(world, new BlockPos(j + (l & 15), 0, k + (l >> 8 & 15)));
if (world.isRainingAt(blockpos)) {
world.spawnEntity(new EntityNibiruLightningBolt(world, blockpos.getX(), blockpos.getY(), blockpos.getZ(), true));
}
}
if (world.rand.nextInt(16) == 0) {
this.updateLCG = this.updateLCG * 3 + 1013904223;
int j2 = this.updateLCG >> 2;
BlockPos blockpos1 = world.getPrecipitationHeight(new BlockPos(j + (j2 & 15), 0, k + (j2 >> 8 & 15)));
BlockPos blockpos2 = blockpos1.down();
if (world.canBlockFreezeNoWater(blockpos2)) {
world.setBlockState(blockpos2, NibiruBlocks.INFECTED_ICE.getDefaultState());
}
if (flag && world.canSnowAt(blockpos1, true)) {
world.setBlockState(blockpos1, NibiruBlocks.INFECTED_SNOW_LAYER.getDefaultState());
}
if (flag && world.getBiome(blockpos2).canRain()) {
world.getBlockState(blockpos2).getBlock().fillWithRain(world, blockpos2);
}
}
if (world.getBiome(new BlockPos(j, 0, k)) == MPBiomes.INFECTED_DESERT || world.getBiome(new BlockPos(j, 0, k)) == MPBiomes.INFECTED_EXTREME_HILLS) {
if (world.rand.nextInt(250000) == 0) {
this.updateLCG = this.updateLCG * 3 + 1013904223;
int l = this.updateLCG >> 2;
BlockPos blockpos = this.adjustPosToNearbyEntity(world, new BlockPos(j + (l & 15), 0, k + (l >> 8 & 15)));
world.spawnEntity(new EntityNibiruLightningBolt(world, blockpos.getX(), blockpos.getY(), blockpos.getZ(), false));
}
}
}
}
}
}
}
use of net.minecraft.world.WorldServer in project MorePlanets by SteveKunG.
the class EntitySpaceFishHook method handleHookRetraction.
@Override
public int handleHookRetraction() {
if (!this.world.isRemote && this.angler != null) {
int i = 0;
if (this.caughtEntity != null) {
this.bringInHookedEntity();
this.world.setEntityState(this, (byte) 31);
i = this.caughtEntity instanceof EntityItem ? 3 : 5;
} else if (this.ticksCatchable > 0) {
LootContext.Builder lootcontext$builder = new LootContext.Builder((WorldServer) this.world);
lootcontext$builder.withLuck(this.luck + this.angler.getLuck());
double x = MathHelper.floor(this.posX);
double y = MathHelper.floor(this.getEntityBoundingBox().minY) + 1.0F;
double z = MathHelper.floor(this.posZ);
Block block = this.world.getBlockState(new BlockPos(x, y - 1, z)).getBlock();
ResourceLocation resource = block instanceof IFishableLiquidBlock ? ((IFishableLiquidBlock) block).getLootTable() : this.world.provider instanceof IGalacticraftWorldProvider ? MPLootTables.SPACE_FISHING : LootTableList.GAMEPLAY_FISHING;
List<ItemStack> result = this.world.getLootTableManager().getLootTableFromLocation(resource).generateLootForPools(this.rand, lootcontext$builder.build());
for (ItemStack itemstack : result) {
EntityItem entityitem = new EntityItem(this.world, this.posX, this.posY, this.posZ, itemstack);
double d0 = this.angler.posX - this.posX;
double d1 = this.angler.posY - this.posY;
double d2 = this.angler.posZ - this.posZ;
double d3 = MathHelper.sqrt(d0 * d0 + d1 * d1 + d2 * d2);
entityitem.motionX = d0 * 0.1D;
entityitem.motionY = d1 * 0.1D + MathHelper.sqrt(d3) * 0.08D;
entityitem.motionZ = d2 * 0.1D;
this.world.spawnEntity(entityitem);
this.angler.world.spawnEntity(new EntityXPOrb(this.angler.world, this.angler.posX, this.angler.posY + 0.5D, this.angler.posZ + 0.5D, this.rand.nextInt(6) + 1));
Item item = itemstack.getItem();
if (item == Items.FISH || item == Items.COOKED_FISH) {
this.angler.addStat(StatList.FISH_CAUGHT, 1);
}
}
i = 1;
}
if (this.inGround) {
i = 2;
}
this.setDead();
return i;
} else {
return 0;
}
}
use of net.minecraft.world.WorldServer in project SpongeCommon by SpongePowered.
the class EntityUtil method changeWorld.
public static boolean changeWorld(net.minecraft.entity.Entity entity, Location<World> location, int currentDim, int targetDim) {
final MinecraftServer mcServer = SpongeImpl.getServer();
final WorldServer fromWorld = mcServer.getWorld(currentDim);
final WorldServer toWorld = mcServer.getWorld(targetDim);
if (entity instanceof EntityPlayer) {
fromWorld.getEntityTracker().removePlayerFromTrackers((EntityPlayerMP) entity);
fromWorld.getPlayerChunkMap().removePlayer((EntityPlayerMP) entity);
mcServer.getPlayerList().getPlayers().remove(entity);
} else {
fromWorld.getEntityTracker().untrack(entity);
}
entity.dismountRidingEntity();
entity.world.removeEntityDangerously(entity);
entity.isDead = false;
entity.dimension = targetDim;
entity.setPositionAndRotation(location.getX(), location.getY(), location.getZ(), 0, 0);
while (!toWorld.getCollisionBoxes(entity, entity.getEntityBoundingBox()).isEmpty() && entity.posY < 256.0D) {
entity.setPosition(entity.posX, entity.posY + 1.0D, entity.posZ);
}
toWorld.getChunkProvider().loadChunk((int) entity.posX >> 4, (int) entity.posZ >> 4);
if (entity instanceof EntityPlayerMP && ((EntityPlayerMP) entity).connection != null) {
EntityPlayerMP entityPlayerMP = (EntityPlayerMP) entity;
// Support vanilla clients going into custom dimensions
final int toDimensionId = WorldManager.getClientDimensionId(entityPlayerMP, toWorld);
if (((IMixinEntityPlayerMP) entityPlayerMP).usesCustomClient()) {
WorldManager.sendDimensionRegistration(entityPlayerMP, toWorld.provider);
} else {
// Force vanilla client to refresh its chunk cache if same dimension type
if (fromWorld != toWorld && fromWorld.provider.getDimensionType() == toWorld.provider.getDimensionType()) {
entityPlayerMP.connection.sendPacket(new SPacketRespawn(toDimensionId >= 0 ? -1 : 0, toWorld.getDifficulty(), toWorld.getWorldInfo().getTerrainType(), entityPlayerMP.interactionManager.getGameType()));
}
}
// Prevent 'lastMoveLocation' from being set to the previous world.
((IMixinNetHandlerPlayServer) entityPlayerMP.connection).setLastMoveLocation(null);
entityPlayerMP.connection.sendPacket(new SPacketRespawn(toDimensionId, toWorld.getDifficulty(), toWorld.getWorldInfo().getTerrainType(), entityPlayerMP.interactionManager.getGameType()));
entity.setWorld(toWorld);
entityPlayerMP.connection.setPlayerLocation(entityPlayerMP.posX, entityPlayerMP.posY, entityPlayerMP.posZ, entityPlayerMP.rotationYaw, entityPlayerMP.rotationPitch);
entityPlayerMP.setSneaking(false);
mcServer.getPlayerList().updateTimeAndWeatherForPlayer(entityPlayerMP, toWorld);
toWorld.getPlayerChunkMap().addPlayer(entityPlayerMP);
toWorld.spawnEntity(entityPlayerMP);
mcServer.getPlayerList().getPlayers().add(entityPlayerMP);
entityPlayerMP.interactionManager.setWorld(toWorld);
entityPlayerMP.addSelfToInternalCraftingInventory();
((IMixinEntityPlayerMP) entityPlayerMP).refreshXpHealthAndFood();
for (Object effect : entityPlayerMP.getActivePotionEffects()) {
entityPlayerMP.connection.sendPacket(new SPacketEntityEffect(entityPlayerMP.getEntityId(), (PotionEffect) effect));
}
entityPlayerMP.sendPlayerAbilities();
} else {
entity.setWorld(toWorld);
toWorld.spawnEntity(entity);
}
fromWorld.resetUpdateEntityTick();
toWorld.resetUpdateEntityTick();
return true;
}
use of net.minecraft.world.WorldServer in project SpongeCommon by SpongePowered.
the class EntityUtil method teleportPlayerToDimension.
/**
* A relative copy paste of {@link EntityPlayerMP#changeDimension(int)} where instead we direct all processing
* to the appropriate areas for throwing events and capturing world changes during the transfer.
*
* @param mixinEntityPlayerMP The player being teleported
* @param suggestedDimensionId The suggested dimension
* @return The player object, not re-created
*/
@Nullable
public static Entity teleportPlayerToDimension(EntityPlayerMP entityPlayerMP, int suggestedDimensionId) {
// Fire teleport event here to support Forge's EntityTravelDimensionEvent
// This also prevents sending client wrong data if event is cancelled
WorldServer toWorld = SpongeImpl.getServer().getWorld(suggestedDimensionId);
MoveEntityEvent.Teleport.Portal event = EntityUtil.handleDisplaceEntityPortalEvent(entityPlayerMP, suggestedDimensionId, toWorld.getDefaultTeleporter());
if (event == null || event.isCancelled()) {
return entityPlayerMP;
}
entityPlayerMP.invulnerableDimensionChange = true;
boolean sameDimension = entityPlayerMP.dimension == suggestedDimensionId;
// If leaving The End via End's Portal
// Sponge Start - Check the provider, not the world's dimension
final WorldServer fromWorldServer = (WorldServer) event.getFromTransform().getExtent();
if (fromWorldServer.provider instanceof WorldProviderEnd && suggestedDimensionId == 1) {
// if (this.dimension == 1 && dimensionIn == 1)
// Sponge End
fromWorldServer.removeEntity(entityPlayerMP);
if (!entityPlayerMP.queuedEndExit) {
entityPlayerMP.queuedEndExit = true;
entityPlayerMP.connection.sendPacket(new SPacketChangeGameState(4, entityPlayerMP.seenCredits ? 0.0F : 1.0F));
entityPlayerMP.seenCredits = true;
}
return entityPlayerMP;
}
// else { // Sponge - Remove unecessary
final WorldServer toWorldServer = (WorldServer) event.getToTransform().getExtent();
// not being loaded then short-circuit to prevent unnecessary logic from running
if (!sameDimension && fromWorldServer == toWorldServer) {
return entityPlayerMP;
}
transferPlayerToDimension(event, entityPlayerMP);
entityPlayerMP.connection.sendPacket(new SPacketEffect(1032, BlockPos.ORIGIN, 0, false));
// Sponge End
return entityPlayerMP;
}
Aggregations