下面列出了net.minecraft.util.ChatComponentTranslation#net.minecraft.world.WorldServer 实例代码,或者点击链接到github查看源代码,也可以在右侧发表评论。
@Override
public void handle(ByteBuf data, EntityPlayer player) {
if (ModConfigs.disabled) return;
int dim = data.readInt();
int xPos = data.readInt();
int yPos = data.readInt();
int zPos = data.readInt();
if (!DimensionManager.isDimensionRegistered(dim)) return;
WorldServer world = MinecraftServer.getServer().worldServerForDimension(dim);
if (world == null) return;
TileEntity tile = world.getTileEntity(xPos, yPos, zPos);
if (tile != null) {
//FIXME: This is currently a very "forceful" method of doing this, and not technically guaranteed to produce correct results
// This would be much better handled by using the getDescriptionPacket method and wrapping that packet in a LookingGlass
// packet to control delivery timing, allowing for processing the packet while the correct target world is the active world
// This idea requires that that system be in place, though, so until then this hack will hopefully hold.
NBTTagCompound tag = new NBTTagCompound();
tile.writeToNBT(tag);
ServerPacketDispatcher.getInstance().addPacket(player, PacketTileEntityNBT.createPacket(xPos, yPos, zPos, tag, dim));
}
}
protected void tryDoVenting() {
BlockPos machinePos = metaTileEntity.getPos();
EnumFacing ventingSide = getVentingSide();
BlockPos ventingBlockPos = machinePos.offset(ventingSide);
IBlockState blockOnPos = metaTileEntity.getWorld().getBlockState(ventingBlockPos);
if (blockOnPos.getCollisionBoundingBox(metaTileEntity.getWorld(), ventingBlockPos) == Block.NULL_AABB) {
metaTileEntity.getWorld()
.getEntitiesWithinAABB(EntityLivingBase.class, new AxisAlignedBB(ventingBlockPos), EntitySelectors.CAN_AI_TARGET)
.forEach(entity -> entity.attackEntityFrom(DamageSources.getHeatDamage(), 6.0f));
WorldServer world = (WorldServer) metaTileEntity.getWorld();
double posX = machinePos.getX() + 0.5 + ventingSide.getFrontOffsetX() * 0.6;
double posY = machinePos.getY() + 0.5 + ventingSide.getFrontOffsetY() * 0.6;
double posZ = machinePos.getZ() + 0.5 + ventingSide.getFrontOffsetZ() * 0.6;
world.spawnParticle(EnumParticleTypes.SMOKE_LARGE, posX, posY, posZ,
7 + world.rand.nextInt(3),
ventingSide.getFrontOffsetX() / 2.0,
ventingSide.getFrontOffsetY() / 2.0,
ventingSide.getFrontOffsetZ() / 2.0, 0.1);
world.playSound(null, posX, posY, posZ, SoundEvents.BLOCK_LAVA_EXTINGUISH, SoundCategory.BLOCKS, 1.0f, 1.0f);
setNeedsVenting(false);
} else if (!ventingStuck) {
setVentingStuck(true);
}
}
public boolean burnCablesInPath(World world, long voltage, long amperage) {
for (BlockPos blockPos : path.keySet()) {
WireProperties wireProperties = path.get(blockPos);
if (voltage > wireProperties.voltage || amperage > wireProperties.amperage) {
TileEntity tileEntity = world.getTileEntity(blockPos);
if (tileEntity instanceof TileEntityCable) {
world.setBlockToAir(blockPos);
world.setBlockState(blockPos, Blocks.FIRE.getDefaultState());
if (!world.isRemote) {
((WorldServer) world).spawnParticle(EnumParticleTypes.SMOKE_LARGE,
blockPos.getX() + 0.5, blockPos.getY() + 0.5, blockPos.getZ() + 0.5,
5 + world.rand.nextInt(3), 0.0, 0.0, 0.0, 0.1);
}
}
}
}
return true;
}
public static boolean targetOutsideOfPlayerRange(ItemStack stack, EntityPlayer player)
{
TargetData target = TargetData.getTargetFromSelectedModule(stack, ModuleType.TYPE_LINKCRYSTAL);
if (target == null)
{
return true;
}
// We allow a max range of 64 blocks, to hopefully be on the safer side
//return target.dimension != player.dimension || player.getDistanceSq(target.posX, target.posY, target.posZ) >= 4096.0d;
WorldServer world = FMLCommonHandler.instance().getMinecraftServerInstance().getWorld(target.dimension);
if ((player instanceof EntityPlayerMP) == false || world == null ||
world.getPlayerChunkMap().isPlayerWatchingChunk((EntityPlayerMP) player, target.pos.getX() >> 4, target.pos.getZ() >> 4) == false)
{
return true;
}
return false;
}
public Map<String, BlockPos> getNearestStructures(final WorldServer world, final BlockPos pos) {
final ImmutableMap.Builder<String, BlockPos> result = ImmutableMap.builder();
visitStructures(world, (generator, structure) -> {
try {
BlockPos structPos = generator.getNearestStructurePos(world, structure, pos, true);
if (structPos != null) {
if (!Strings.isNullOrEmpty(structure)) result.put(structure, structPos);
}
} catch (IndexOutOfBoundsException e) {
// bug in MC, just ignore
// hopefully fixed by magic of ASM
}
});
return result.build();
}
public final int despawnVanillaAnimals(WorldServer worldObj)
{
int count = 0;
for (int j = 0; j < worldObj.loadedEntityList.size(); j++)
{
Entity entity = (Entity) worldObj.loadedEntityList.get(j);
if (!(entity instanceof EntityLiving))
{
continue;
}
if ((entity instanceof EntityCow || entity instanceof EntitySheep || entity instanceof EntityPig || entity instanceof EntityOcelot || entity instanceof EntityChicken || entity instanceof EntitySquid || entity instanceof EntityWolf))
{
count += entityDespawnCheck(worldObj, (EntityLiving) entity);
}
}
return count;
}
public static void teleportToDimension(EntityPlayer player, int dimension, double x, double y, double z) {
int oldDimension = player.getEntityWorld().provider.getDimension();
EntityPlayerMP entityPlayerMP = (EntityPlayerMP) player;
MinecraftServer server = player.getEntityWorld().getMinecraftServer();
WorldServer worldServer = server.getWorld(dimension);
player.addExperienceLevel(0);
if (worldServer == null || worldServer.getMinecraftServer() == null) { // Dimension doesn't exist
throw new IllegalArgumentException("Dimension: " + dimension + " doesn't exist!");
}
worldServer.getMinecraftServer().getPlayerList().transferPlayerToDimension(entityPlayerMP, dimension, new GTCommandTeleporter(worldServer, x, y, z));
player.setPositionAndUpdate(x, y, z);
if (oldDimension == 1) {
// For some reason teleporting out of the end does weird things.
player.setPositionAndUpdate(x, y, z);
worldServer.spawnEntity(player);
worldServer.updateEntityWithOptionalForce(player, false);
}
}
private static Map<CellLoc, Short> calculateCellLocs(WorldServer world) {
ConcurrentHashMap<CellLoc, Short> oldDat = MazeHandler.labyrinth;
ConcurrentHashMap<CellLoc, Short> bufferOld = new ConcurrentHashMap<CellLoc, Short>(labyrinthCopy);
MazeHandler.labyrinth = labyrinthCopy;
int chX = getHighestPossibleRandWH(); //To ensure we're always +x and +z
int chZ = getHighestPossibleRandWH();
int w = randWH(world.rand);
int h = randWH(world.rand);
while (MazeHandler.mazesInRange(chX, chZ, w, h)) {
chX++; //We grow the mazes in +x direction!
}
MazeThread mt = new MazeThread(chX, chZ, w, h, world.rand.nextLong());
mt.run();
Map<CellLoc, Short> locs = calculateDifferences(bufferOld);
labyrinthCopy = MazeHandler.labyrinth;
MazeHandler.labyrinth = oldDat;
return locs;
}
@Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) {
if (!testPermission(sender)) return true;
if (args.length != 1) {
sender.sendMessage(ChatColor.RED + "Usage: " + usageMessage);
return false;
}
if (args[0].equals("reload")) {
Command.broadcastCommandMessage(sender, ChatColor.RED + "Please note that this command is not supported and may cause issues.");
Command.broadcastCommandMessage(sender, ChatColor.RED + "If you encounter any issues please use the /stop command to restart your server.");
MinecraftServer console = MinecraftServer.getServerCB();
org.spigotmc.SpigotConfig.init((File) console.options.valueOf("spigot-settings"));
for (WorldServer world : console.worlds) {
world.spigotConfig.init();
}
console.server.reloadCount++;
Command.broadcastCommandMessage(sender, ChatColor.GREEN + "Reload complete.");
}
return true;
}
public static void generateLoot(ItemStackHandler items, String tableStr, long seed,
World world, EntityPlayer player) {
Random rnd = new Random(seed);
double maxFullness = (0.6 + rnd.nextDouble() * 0.2);
int maxOccupiedSlots = (int)Math.ceil(items.getSlots() * maxFullness);
LootTableManager manager = world.getLootTableManager();
LootTable table = manager.getLootTableFromLocation(new ResourceLocation(tableStr));
LootContext context = new LootContext(((player != null) ? player.getLuck() : 0),
(WorldServer)world, manager, player, null, null);
List<ItemStack> loot = table.generateLootForPools(rnd, context);
Collections.shuffle(loot);
List<Integer> randomizedSlots = new ArrayList<Integer>(items.getSlots());
for (int i = 0; i < items.getSlots(); i++) randomizedSlots.add(i);
Collections.shuffle(randomizedSlots);
for (int i = 0; (i < maxOccupiedSlots) && (i < loot.size()); i++) {
ItemStack stack = loot.get(i);
int slot = randomizedSlots.get(i);
items.setStackInSlot(slot, stack);
}
}
@Override
public IMessage onMessage(final MessageQuestUpdate message, MessageContext ctx) {
if (ctx.side != Side.SERVER) {
return null;
}
final EntityPlayerMP player = ctx.getServerHandler().player;
if (player == null) {
return null;
}
final WorldServer worldServer = player.getServerWorld();
worldServer.addScheduledTask(new Runnable() {
@Override
public void run() {
new Worker(message.action).work(message, player);
}
});
return null;
}
private static void chunkLoadPostProcess(Chunk chunk) {
if (chunk != null) {
WorldServer world = (WorldServer) chunk.getWorld();
world.getChunkProvider().id2ChunkMap.put(ChunkPos.asLong(chunk.x, chunk.z), chunk);
org.spongepowered.api.world.Chunk spongeChunk = (org.spongepowered.api.world.Chunk) chunk;
for (Direction direction : CARDINAL_SET) {
Vector3i neighborPosition = spongeChunk.getPosition().add(direction.asBlockOffset());
ChunkProviderBridge spongeChunkProvider = (ChunkProviderBridge) world.getChunkProvider();
net.minecraft.world.chunk.Chunk neighbor = spongeChunkProvider.bridge$getLoadedChunkWithoutMarkingActive(neighborPosition.getX(), neighborPosition.getZ());
if (neighbor != null) {
int neighborIndex = directionToIndex(direction);
int oppositeNeighborIndex = directionToIndex(direction.getOpposite());
((ChunkBridge) spongeChunk).bridge$setNeighborChunk(neighborIndex, neighbor);
((ChunkBridge) neighbor).bridge$setNeighborChunk(oppositeNeighborIndex, (net.minecraft.world.chunk.Chunk)(Object) chunk);
}
}
chunk.populate(world.getChunkProvider(), world.getChunkProvider().chunkGenerator);
}
}
public static void updateData(Entity targetEntity)
{
if (!targetEntity.worldObj.isRemote)
{
WorldServer world = (WorldServer) targetEntity.worldObj;
NBTTagCompound nbt = CyberwareAPI.getCapability(targetEntity).serializeNBT();
if (targetEntity instanceof EntityPlayer)
{
PACKET_HANDLER.sendTo(new CyberwareSyncPacket(nbt, targetEntity.getEntityId()), (EntityPlayerMP) targetEntity);
//System.out.println("Sent data for player " + ((EntityPlayer) targetEntity).getName() + " to that player's client");
}
for (EntityPlayer trackingPlayer : world.getEntityTracker().getTrackingPlayers(targetEntity))
{
PACKET_HANDLER.sendTo(new CyberwareSyncPacket(nbt, targetEntity.getEntityId()), (EntityPlayerMP) trackingPlayer);
if (targetEntity instanceof EntityPlayer)
{
//System.out.println("Sent data for player " + ((EntityPlayer) targetEntity).getName() + " to player " + trackingPlayer.getName());
}
}
}
}
@Override
public void generate(World world, BlockPos pos)
{
PlacementSettings settings = new PlacementSettings();
Template temp = null;
String suffix = world.provider.getDimensionType().getSuffix();
String opts = world.getWorldInfo().getGeneratorOptions() + suffix;
if (!Strings.isNullOrEmpty(opts))
temp = StructureUtil.loadTemplate(new ResourceLocation(opts), (WorldServer)world, true);
if (temp == null)
temp = StructureUtil.loadTemplate(new ResourceLocation("/config/", this.fileName + suffix), (WorldServer)world, !Strings.isNullOrEmpty(suffix));
if (temp == null)
return; //If we're not in the overworld, and we don't have a template...
BlockPos spawn = StructureUtil.findSpawn(temp, settings);
if (spawn != null)
{
pos = pos.subtract(spawn);
world.setSpawnPoint(pos);
}
temp.addBlocksToWorld(world, pos, settings, 0); //Push to world, with no neighbor notifications!
world.getPendingBlockUpdates(new StructureBoundingBox(pos, pos.add(temp.getSize())), true); //Remove block updates, so that sand doesn't fall!
}
@Override
public TileEntity createRelocatedTile(BlockPos newPos, ShipTransform transform,
CoordinateSpaceType coordinateSpaceType) {
TileEntityPassengerChair relocatedTile = new TileEntityPassengerChair();
relocatedTile.setWorld(getWorld());
relocatedTile.setPos(newPos);
if (chairEntityUUID != null) {
EntityMountableChair chairEntity = (EntityMountableChair) ((WorldServer) getWorld())
.getEntityFromUuid(chairEntityUUID);
if (chairEntity != null) {
Vec3d newMountPos = transform
.transform(chairEntity.getMountPos(), TransformType.SUBSPACE_TO_GLOBAL);
chairEntity.setMountValues(newMountPos, coordinateSpaceType, newPos);
} else {
chairEntityUUID = null;
}
}
relocatedTile.chairEntityUUID = this.chairEntityUUID;
// Move everything to the new tile.
this.chairEntityUUID = null;
this.markDirty();
return relocatedTile;
}
@Override
public InventoryChangeMessage onMessage(final InventoryMessage message, MessageContext ctx)
{
final EntityPlayerMP player = ctx.getServerHandler().playerEntity;
IThreadListener mainThread = (WorldServer)ctx.getServerHandler().playerEntity.world;
mainThread.addScheduledTask(new Runnable()
{
@Override
public void run()
{
ItemStack[] changes = null;
if (message.combine)
changes = combineSlots(player, message.invA, message.slotA, message.invB, message.slotB, message.containerPos);
else
changes = swapSlots(player, message.invA, message.slotA, message.invB, message.slotB, message.containerPos);
if (changes != null)
MalmoMod.network.sendTo(new InventoryChangeMessage(changes[0], changes[1]), player);
}
});
return null;
}
@Override
public IMessage onMessage(final SMapRequestPacket message, final MessageContext ctx) {
IThreadListener mainThread = (WorldServer) ctx.getServerHandler().player.world; // or Minecraft.getMinecraft() on the client
mainThread.addScheduledTask(new Runnable()
{
@Override
public void run()
{
int j;
IslandMap map = WorldGen.getInstance().getIslandMap(message.islandX, message.islandZ);
long seed = ctx.getServerHandler().player.world.getSeed()+Helper.combineCoords(message.islandX, message.islandZ);
TFC.network.sendTo(new CMapPacket(message.islandX, message.islandZ, seed), ctx.getServerHandler().player);
}
});
return null; // no response in this case
}
private void ensureCompiled() {
if (!this.codeChanged) return;
FMLLog.fine("Eval my code: %s", this.code);
// now execute the code
try {
PythonEngine.eval(this.code, this.context);
if (!world.isRemote) {
((WorldServer)world).spawnParticle(EnumParticleTypes.CRIT,
pos.getX() + .5, pos.getY() + 1, pos.getZ() + .5,
20, 0, 0, 0, .5, new int[0]);
}
} catch (ScriptException e) {
failz0r(world, pos, "Error running code, traceback:\n%s", stackTraceToString(e));
}
this.codeChanged = false;
}
@Override
public void updateTask() {
super.updateTask();
--this.shottick;
if (this.shottick == 60 || this.shottick == 80) {
EntityTofuGandlem.this.playSound(SoundEvents.BLOCK_IRON_TRAPDOOR_OPEN, 2.0F, 1.4F);
((WorldServer) EntityTofuGandlem.this.world).spawnParticle(EnumParticleTypes.CRIT, EntityTofuGandlem.this.posX, EntityTofuGandlem.this.posY, EntityTofuGandlem.this.posZ, 15, 0.2D, 0.2D, 0.2D, 0.0D);
}
if (this.shottick <= 20) {
if (EntityTofuGandlem.this.ticksExisted % 5 == 0) {
for (int i = 0; i < 6; i++) {
EntityThrowable projectile = new EntityFukumame(EntityTofuGandlem.this.world, EntityTofuGandlem.this);
Vec3d vec3d = EntityTofuGandlem.this.getLook(1.0F);
playSound(SoundEvents.ENTITY_SNOWBALL_THROW, 3.0F, 1.0F / (EntityTofuGandlem.this.getRNG().nextFloat() * 0.4F + 0.8F));
projectile.setLocationAndAngles(EntityTofuGandlem.this.posX + vec3d.x * 1.3D, EntityTofuGandlem.this.posY + (EntityTofuGandlem.this.getEyeHeight() / 2), EntityTofuGandlem.this.posZ + vec3d.z * 1.2D, EntityTofuGandlem.this.rotationYaw, EntityTofuGandlem.this.rotationPitch);
float d0 = (EntityTofuGandlem.this.rand.nextFloat() * 12.0F) - 6.0F;
projectile.shoot(EntityTofuGandlem.this, EntityTofuGandlem.this.rotationPitch, EntityTofuGandlem.this.rotationYaw + d0, 0.0F, 1.5f, 0.8F);
EntityTofuGandlem.this.world.spawnEntity(projectile);
}
}
}
}
@Override
public void onPlayerStoppedUsing(ItemStack stack, World worldIn, EntityLivingBase entityLiving, int timeLeft) {
int i = this.getMaxItemUseDuration(stack) - timeLeft;
if (i < 0) return;
entityLiving.swingArm(entityLiving.getActiveHand());
float f = (float) entityLiving.getEntityAttribute(SharedMonsterAttributes.ATTACK_DAMAGE).getAttributeValue();
f += EnchantmentHelper.getModifierForCreature(stack, entityLiving.getCreatureAttribute()) / 1.2F;
float f1 = i / 15F;
f1 = (f1 * f1 + f1 * 2.0F) / 2F;
if(f1>8F) f1=8f;
float f3 = f1 + EnchantmentHelper.getSweepingDamageRatio(entityLiving) * f ;
float sweepingRatio = EnchantmentHelper.getSweepingDamageRatio(entityLiving);
for (Entity entitylivingbase : worldIn.getEntitiesWithinAABB(Entity.class, entityLiving.getEntityBoundingBox().grow(1.6D + sweepingRatio * 1.2D, 0.5D + sweepingRatio * 0.15D, 1.6D + sweepingRatio * 1.2D))) {
if (entitylivingbase != entityLiving && !entityLiving.isOnSameTeam(entitylivingbase)) {
if (entitylivingbase instanceof EntityLivingBase) {
f1 = f1/10;
((EntityLivingBase) entitylivingbase).knockBack(entityLiving, 0.4F + 0.6F * f1 * EnchantmentHelper.getSweepingDamageRatio(entityLiving), MathHelper.sin(entityLiving.rotationYaw * 0.017453292F), (-MathHelper.cos(entityLiving.rotationYaw * 0.017453292F)));
entitylivingbase.attackEntityFrom(DamageSource.causePlayerDamage((EntityPlayer) entityLiving), f3);
}
if (entitylivingbase instanceof MultiPartEntityPart) {
entitylivingbase.attackEntityFrom(DamageSource.causePlayerDamage((EntityPlayer) entityLiving), f3);
}
}
}
worldIn.playSound(null, entityLiving.posX, entityLiving.posY, entityLiving.posZ, SoundEvents.ENTITY_PLAYER_ATTACK_SWEEP, entityLiving.getSoundCategory(), 1.0F, 1.0F);
if (worldIn instanceof WorldServer) {
double d0 = (-MathHelper.sin(entityLiving.rotationYaw * 0.017453292F));
double d1 = MathHelper.cos(entityLiving.rotationYaw * 0.017453292F);
((WorldServer) worldIn).spawnParticle(EnumParticleTypes.SWEEP_ATTACK, entityLiving.posX + d0, entityLiving.posY + entityLiving.height * 0.5D, entityLiving.posZ + d1, 0, d0, 0.0D, d1, 0.0D);
}
stack.damageItem(2, entityLiving);
((EntityPlayer) entityLiving).getCooldownTracker().setCooldown(this, 25);
}
@SubscribeEvent
public static void onLivingUpdate(LivingEvent.LivingUpdateEvent event) {
final Entity entity = event.getEntity();
final World world = entity.getEntityWorld();
if(world.isRemote) {
return;
}
final MinecraftServer server = world.getMinecraftServer();
final NBTTagCompound data = entity.getEntityData();
if(data.hasUniqueId(NYANED_ENTITY_UUID_KEY)) {
final Entity nyanedEntity =
server.getEntityFromUuid(data.getUniqueId(NYANED_ENTITY_UUID_KEY));
if(nyanedEntity == null || nyanedEntity.isDead) {
world.removeEntity(entity);
return;
}
}
if(data.getBoolean(HAS_NYAN_ENTITY_KEY)) {
updateNyanEntity(server, (WorldServer) world, entity, data);
} else if(!data.hasKey(HAS_NYAN_ENTITY_KEY)) {
if(entity instanceof EntityPlayer || random.nextInt(10) == 0) {
data.setBoolean(HAS_NYAN_ENTITY_KEY, true);
updateNyanEntity(server, (WorldServer) world, entity, data);
} else {
data.setBoolean(HAS_NYAN_ENTITY_KEY, false);
}
}
}
public AIBreakBlock(EntityGolemBase golem) {
this.golem = golem;
if (golem.worldObj instanceof WorldServer) {
this.player = new GolemFakePlayer((WorldServer) golem.worldObj, golem);
}
setMutexBits(3);
}
public static FakePlayer get(WorldServer world) {
FakePlayer ret = GREGTECH_PLAYER != null ? GREGTECH_PLAYER.get() : null;
if (ret == null) {
ret = FakePlayerFactory.get(world, GREGTECH);
GREGTECH_PLAYER = new WeakReference<>(ret);
}
return ret;
}
@Override
public void update() {
super.update();
ItemStack baitStack = importItems.getStackInSlot(0);
if (!getWorld().isRemote && energyContainer.getEnergyStored() >= energyAmountPerFish && getTimer() % fishingTicks == 0L && !baitStack.isEmpty()) {
WorldServer world = (WorldServer) this.getWorld();
int waterCount = 0;
int edgeSize = (int) Math.sqrt(WATER_CHECK_SIZE);
for (int x = 0; x < edgeSize; x++){
for (int z = 0; z < edgeSize; z++){
BlockPos waterCheckPos = getPos().down().add(x - edgeSize / 2, 0, z - edgeSize / 2);
if (world.getBlockState(waterCheckPos).getBlock() instanceof BlockLiquid &&
world.getBlockState(waterCheckPos).getMaterial() == Material.WATER) {
waterCount++;
}
}
}
if (waterCount == WATER_CHECK_SIZE) {
LootTable table = world.getLootTableManager().getLootTableFromLocation(LootTableList.GAMEPLAY_FISHING);
NonNullList<ItemStack> itemStacks = NonNullList.create();
itemStacks.addAll(table.generateLootForPools(world.rand, new LootContext.Builder(world).build()));
if(addItemsToItemHandler(exportItems, true, itemStacks)) {
addItemsToItemHandler(exportItems, false, itemStacks);
energyContainer.removeEnergy(energyAmountPerFish);
baitStack.shrink(1);
}
}
}
if(!getWorld().isRemote && getTimer() % 5 == 0) {
pushItemsIntoNearbyHandlers(getFrontFacing());
}
}
public void teleport(Entity entity, WorldServer world) {
if (entity.isEntityAlive()) {
entity.setLocationAndAngles(entity.posX, entity.posY, entity.posZ, entity.rotationYaw, entity.rotationPitch);
world.spawnEntity(entity);
world.updateEntityWithOptionalForce(entity, false);
}
entity.setWorld(world);
}
public static Set<EntityPlayerMP> getPlayersWatchingEntity(WorldServer server, Entity entity) {
final EntityTracker tracker = server.getEntityTracker();
@SuppressWarnings("unchecked")
final Set<? extends EntityPlayerMP> trackingPlayers = (Set<? extends EntityPlayerMP>)tracker.getTrackingPlayers(entity);
return ImmutableSet.copyOf(trackingPlayers);
}
@SubscribeEvent
public void worldTick(WorldTickEvent event) {
if (event.phase == Phase.END && !event.world.isRemote) {
ChunkLoaderManager.tickEnd((WorldServer) event.world);
PlayerChunkViewerManager.instance().calculateChunkChanges((WorldServer) event.world);
}
}
/**
* Checks to see if the situation for firing the laser exists... and changes the state accordingly
*/
public void checkCanRun() {
//Laser requires lense, redstone power, not be jammed, and be in orbit and energy to function
if(world.isBlockIndirectlyGettingPowered(getPos()) == 0 || !isAllowedToRun()) {
if(laserSat.isAlive()) {
laserSat.deactivateLaser();
}
setRunning(false);
} else if(!laserSat.isAlive() && !finished && !laserSat.getJammed() && world.isBlockIndirectlyGettingPowered(getPos()) > 0 && canMachineSeeEarth()) {
//Laser will be on at this point
int orbitDimId = ((WorldProviderSpace)this.world.provider).getDimensionProperties(getPos()).getParentPlanet();
if(orbitDimId == SpaceObjectManager.WARPDIMID)
return;
WorldServer orbitWorld = DimensionManager.getWorld(orbitDimId);
if(orbitWorld == null) {
DimensionManager.initDimension(orbitDimId);
orbitWorld = DimensionManager.getWorld(orbitDimId);
if(orbitWorld == null)
return;
}
if(ticket == null) {
ticket = ForgeChunkManager.requestTicket(AdvancedRocketry.instance, this.world, Type.NORMAL);
if(ticket != null)
ForgeChunkManager.forceChunk(ticket, new ChunkPos(getPos().getX() / 16 - (getPos().getX() < 0 ? 1 : 0), getPos().getZ() / 16 - (getPos().getZ() < 0 ? 1 : 0)));
}
setRunning(laserSat.activateLaser(orbitWorld, laserX, laserZ));
}
if(!this.world.isRemote)
PacketHandler.sendToNearby(new PacketMachine(this, (byte)12), 128, pos, this.world.provider.getDimension());
}
@SubscribeEvent
public void tickStart(TickEvent.WorldTickEvent tick)
{
World w = tick.world;
if (!(w instanceof WorldServer))
{
return;
}
if (tick.phase == TickEvent.Phase.START)
{
counter = 0;
getSemaphoreFor(w);
}
else
{
ListMultimap<ChunkPos, String> pending = pendingWork.get(w);
if (pending == null)
{
return;
}
ImmutableList<Entry<ChunkPos, String>> forProcessing = ImmutableList.copyOf(Iterables.limit(pending.entries(), maxPerTick + 1));
for (Entry<ChunkPos, String> entry : forProcessing)
{
if (counter++ > maxPerTick)
{
FMLLog.fine("Completed %d retrogens this tick. There are %d left for world %s", counter, pending.size(), w.getWorldInfo().getWorldName());
return;
}
runRetrogen((WorldServer)w, entry.getKey(), entry.getValue());
}
}
}
private boolean tryPlaceBlock(final WorldServer world, final BlockPos pos) {
return FakePlayerPool.instance.executeOnPlayer(world, (PlayerUserReturning<Boolean>)fakePlayer -> {
if (tryPlaceBlock(fakePlayer, world, pos, EnumFacing.UP)) return true;
for (EnumFacing dir : PLACE_DIRECTIONS) {
if (tryPlaceBlock(fakePlayer, world, pos.offset(dir), dir)) return true;
}
return false;
});
}