Files
CatServer/patches/net/minecraft/command/CommandSpreadPlayers.java.patch
2019-02-24 22:29:41 +08:00

174 lines
8.8 KiB
Diff

--- ../src-base/minecraft/net/minecraft/command/CommandSpreadPlayers.java
+++ ../src-work/minecraft/net/minecraft/command/CommandSpreadPlayers.java
@@ -10,6 +10,7 @@
import java.util.Set;
import javax.annotation.Nullable;
import net.minecraft.block.material.Material;
+import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.scoreboard.Team;
@@ -18,6 +19,7 @@
import net.minecraft.util.math.MathHelper;
import net.minecraft.util.text.TextComponentTranslation;
import net.minecraft.world.World;
+import net.minecraft.world.gen.ChunkProviderServer;
public class CommandSpreadPlayers extends CommandBase
{
@@ -90,19 +92,19 @@
else
{
sender.sendMessage(new TextComponentTranslation("commands.spreadplayers.spreading." + (flag ? "teams" : "players"), new Object[] {list.size(), d3, d0, d1, d2}));
- this.spread(sender, list, new CommandSpreadPlayers.Position(d0, d1), d2, d3, (list.get(0)).world, flag);
+ this.spread(sender, list, new Position(d0, d1), d2, d3, (list.get(0)).world, flag);
}
}
}
- private void spread(ICommandSender sender, List<Entity> p_110669_2_, CommandSpreadPlayers.Position pos, double spreadDistance, double maxRange, World worldIn, boolean respectTeams) throws CommandException
+ private void spread(ICommandSender sender, List<Entity> p_110669_2_, Position pos, double spreadDistance, double maxRange, World worldIn, boolean respectTeams) throws CommandException
{
Random random = new Random();
double d0 = pos.x - maxRange;
double d1 = pos.z - maxRange;
double d2 = pos.x + maxRange;
double d3 = pos.z + maxRange;
- CommandSpreadPlayers.Position[] acommandspreadplayers$position = this.createInitialPositions(random, respectTeams ? this.getNumberOfTeams(p_110669_2_) : p_110669_2_.size(), d0, d1, d2, d3);
+ Position[] acommandspreadplayers$position = this.createInitialPositions(random, respectTeams ? this.getNumberOfTeams(p_110669_2_) : p_110669_2_.size(), d0, d1, d2, d3);
int i = this.spreadPositions(pos, spreadDistance, worldIn, random, d0, d1, d2, d3, acommandspreadplayers$position, respectTeams);
double d4 = this.setPlayerPositions(p_110669_2_, worldIn, acommandspreadplayers$position, respectTeams);
notifyCommandListener(sender, this, "commands.spreadplayers.success." + (respectTeams ? "teams" : "players"), new Object[] {acommandspreadplayers$position.length, pos.x, pos.z});
@@ -132,7 +134,7 @@
return set.size();
}
- private int spreadPositions(CommandSpreadPlayers.Position p_110668_1_, double p_110668_2_, World worldIn, Random random, double minX, double minZ, double maxX, double maxZ, CommandSpreadPlayers.Position[] p_110668_14_, boolean respectTeams) throws CommandException
+ private int spreadPositions(Position p_110668_1_, double p_110668_2_, World worldIn, Random random, double minX, double minZ, double maxX, double maxZ, Position[] p_110668_14_, boolean respectTeams) throws CommandException
{
boolean flag = true;
double d0 = 3.4028234663852886E38D;
@@ -145,15 +147,15 @@
for (int j = 0; j < p_110668_14_.length; ++j)
{
- CommandSpreadPlayers.Position commandspreadplayers$position = p_110668_14_[j];
+ Position commandspreadplayers$position = p_110668_14_[j];
int k = 0;
- CommandSpreadPlayers.Position commandspreadplayers$position1 = new CommandSpreadPlayers.Position();
+ Position commandspreadplayers$position1 = new Position();
for (int l = 0; l < p_110668_14_.length; ++l)
{
if (j != l)
{
- CommandSpreadPlayers.Position commandspreadplayers$position2 = p_110668_14_[l];
+ Position commandspreadplayers$position2 = p_110668_14_[l];
double d1 = commandspreadplayers$position.dist(commandspreadplayers$position2);
d0 = Math.min(d1, d0);
@@ -193,7 +195,7 @@
if (!flag)
{
- for (CommandSpreadPlayers.Position commandspreadplayers$position3 : p_110668_14_)
+ for (Position commandspreadplayers$position3 : p_110668_14_)
{
if (!commandspreadplayers$position3.isSafe(worldIn))
{
@@ -214,16 +216,16 @@
}
}
- private double setPlayerPositions(List<Entity> p_110671_1_, World worldIn, CommandSpreadPlayers.Position[] p_110671_3_, boolean p_110671_4_)
+ private double setPlayerPositions(List<Entity> p_110671_1_, World worldIn, Position[] p_110671_3_, boolean p_110671_4_)
{
double d0 = 0.0D;
int i = 0;
- Map<Team, CommandSpreadPlayers.Position> map = Maps.<Team, CommandSpreadPlayers.Position>newHashMap();
+ Map<Team, Position> map = Maps.<Team, Position>newHashMap();
for (int j = 0; j < p_110671_1_.size(); ++j)
{
Entity entity = p_110671_1_.get(j);
- CommandSpreadPlayers.Position commandspreadplayers$position;
+ Position commandspreadplayers$position;
if (p_110671_4_)
{
@@ -244,7 +246,7 @@
entity.setPositionAndUpdate((double)((float)MathHelper.floor(commandspreadplayers$position.x) + 0.5F), (double)commandspreadplayers$position.getSpawnY(worldIn), (double)MathHelper.floor(commandspreadplayers$position.z) + 0.5D);
double d2 = Double.MAX_VALUE;
- for (CommandSpreadPlayers.Position commandspreadplayers$position1 : p_110671_3_)
+ for (Position commandspreadplayers$position1 : p_110671_3_)
{
if (commandspreadplayers$position != commandspreadplayers$position1)
{
@@ -260,13 +262,13 @@
return d0;
}
- private CommandSpreadPlayers.Position[] createInitialPositions(Random p_110670_1_, int p_110670_2_, double p_110670_3_, double p_110670_5_, double p_110670_7_, double p_110670_9_)
+ private Position[] createInitialPositions(Random p_110670_1_, int p_110670_2_, double p_110670_3_, double p_110670_5_, double p_110670_7_, double p_110670_9_)
{
- CommandSpreadPlayers.Position[] acommandspreadplayers$position = new CommandSpreadPlayers.Position[p_110670_2_];
+ Position[] acommandspreadplayers$position = new Position[p_110670_2_];
for (int i = 0; i < acommandspreadplayers$position.length; ++i)
{
- CommandSpreadPlayers.Position commandspreadplayers$position = new CommandSpreadPlayers.Position();
+ Position commandspreadplayers$position = new Position();
commandspreadplayers$position.randomize(p_110670_1_, p_110670_3_, p_110670_5_, p_110670_7_, p_110670_9_);
acommandspreadplayers$position[i] = commandspreadplayers$position;
}
@@ -294,7 +296,7 @@
this.z = zIn;
}
- double dist(CommandSpreadPlayers.Position pos)
+ double dist(Position pos)
{
double d0 = this.x - pos.x;
double d1 = this.z - pos.z;
@@ -313,7 +315,7 @@
return MathHelper.sqrt(this.x * this.x + this.z * this.z);
}
- public void moveAway(CommandSpreadPlayers.Position pos)
+ public void moveAway(Position pos)
{
this.x -= pos.x;
this.z -= pos.z;
@@ -356,7 +358,7 @@
{
blockpos = blockpos.down();
- if (worldIn.getBlockState(blockpos).getMaterial() != Material.AIR)
+ if (getBlockState(worldIn, blockpos).getMaterial() != Material.AIR)
{
return blockpos.getY() + 1;
}
@@ -372,7 +374,7 @@
while (blockpos.getY() > 0)
{
blockpos = blockpos.down();
- Material material = worldIn.getBlockState(blockpos).getMaterial();
+ Material material = getBlockState(worldIn, blockpos).getMaterial();
if (material != Material.AIR)
{
@@ -388,5 +390,12 @@
this.x = MathHelper.nextDouble(rand, p_111097_2_, p_111097_6_);
this.z = MathHelper.nextDouble(rand, p_111097_4_, p_111097_8_);
}
+
+ // CraftBukkit start - add a version of getBlockState which force loads chunks
+ private static IBlockState getBlockState(World world, BlockPos position) {
+ ((ChunkProviderServer) world.getChunkProvider()).loadChunk(position.getX() >> 4, position.getZ() >> 4);
+ return world.getBlockState(position);
+ }
+ // CraftBukkit end
}
}