| 1 | package net.minecraft.world.border;
|
| 2 |
|
| 3 | import com.google.common.collect.Lists;
|
| 4 | import java.util.List;
|
| 5 | import net.minecraft.entity.Entity;
|
| 6 | import net.minecraft.util.AxisAlignedBB;
|
| 7 | import net.minecraft.util.BlockPos;
|
| 8 | import net.minecraft.world.ChunkCoordIntPair;
|
| 9 |
|
| 10 | public class WorldBorder
|
| 11 | {
|
| 12 | private final List<IBorderListener> listeners = Lists.<IBorderListener>newArrayList();
|
| 13 | private double centerX = 0.0D;
|
| 14 | private double centerZ = 0.0D;
|
| 15 | private double startDiameter = 6.0E7D;
|
| 16 | private double endDiameter;
|
| 17 | private long endTime;
|
| 18 | private long startTime;
|
| 19 | private int worldSize;
|
| 20 | private double damageAmount;
|
| 21 | private double damageBuffer;
|
| 22 | private int warningTime;
|
| 23 | private int warningDistance;
|
| 24 |
|
| 25 | public WorldBorder()
|
| 26 | {
|
| 27 | this.endDiameter = this.startDiameter;
|
| 28 | this.worldSize = 29999984;
|
| 29 | this.damageAmount = 0.2D;
|
| 30 | this.damageBuffer = 5.0D;
|
| 31 | this.warningTime = 15;
|
| 32 | this.warningDistance = 5;
|
| 33 | }
|
| 34 |
|
| 35 | public boolean contains(BlockPos pos)
|
| 36 | {
|
| 37 | return (double)(pos.getX() + 1) > this.minX() && (double)pos.getX() < this.maxX() && (double)(pos.getZ() + 1) > this.minZ() && (double)pos.getZ() < this.maxZ();
|
| 38 | }
|
| 39 |
|
| 40 | public boolean contains(ChunkCoordIntPair range)
|
| 41 | {
|
| 42 | return (double)range.getXEnd() > this.minX() && (double)range.getXStart() < this.maxX() && (double)range.getZEnd() > this.minZ() && (double)range.getZStart() < this.maxZ();
|
| 43 | }
|
| 44 |
|
| 45 | public boolean contains(AxisAlignedBB bb)
|
| 46 | {
|
| 47 | return bb.maxX > this.minX() && bb.minX < this.maxX() && bb.maxZ > this.minZ() && bb.minZ < this.maxZ();
|
| 48 | }
|
| 49 |
|
| 50 | public double getClosestDistance(Entity entityIn)
|
| 51 | {
|
| 52 | return this.getClosestDistance(entityIn.posX, entityIn.posZ);
|
| 53 | }
|
| 54 |
|
| 55 | public double getClosestDistance(double x, double z)
|
| 56 | {
|
| 57 | double d0 = z - this.minZ();
|
| 58 | double d1 = this.maxZ() - z;
|
| 59 | double d2 = x - this.minX();
|
| 60 | double d3 = this.maxX() - x;
|
| 61 | double d4 = Math.min(d2, d3);
|
| 62 | d4 = Math.min(d4, d0);
|
| 63 | return Math.min(d4, d1);
|
| 64 | }
|
| 65 |
|
| 66 | public EnumBorderStatus getStatus()
|
| 67 | {
|
| 68 | return this.endDiameter < this.startDiameter ? EnumBorderStatus.SHRINKING : (this.endDiameter > this.startDiameter ? EnumBorderStatus.GROWING : EnumBorderStatus.STATIONARY);
|
| 69 | }
|
| 70 |
|
| 71 | public double minX()
|
| 72 | {
|
| 73 | double d0 = this.getCenterX() - this.getDiameter() / 2.0D;
|
| 74 |
|
| 75 | if (d0 < (double)(-this.worldSize))
|
| 76 | {
|
| 77 | d0 = (double)(-this.worldSize);
|
| 78 | }
|
| 79 |
|
| 80 | return d0;
|
| 81 | }
|
| 82 |
|
| 83 | public double minZ()
|
| 84 | {
|
| 85 | double d0 = this.getCenterZ() - this.getDiameter() / 2.0D;
|
| 86 |
|
| 87 | if (d0 < (double)(-this.worldSize))
|
| 88 | {
|
| 89 | d0 = (double)(-this.worldSize);
|
| 90 | }
|
| 91 |
|
| 92 | return d0;
|
| 93 | }
|
| 94 |
|
| 95 | public double maxX()
|
| 96 | {
|
| 97 | double d0 = this.getCenterX() + this.getDiameter() / 2.0D;
|
| 98 |
|
| 99 | if (d0 > (double)this.worldSize)
|
| 100 | {
|
| 101 | d0 = (double)this.worldSize;
|
| 102 | }
|
| 103 |
|
| 104 | return d0;
|
| 105 | }
|
| 106 |
|
| 107 | public double maxZ()
|
| 108 | {
|
| 109 | double d0 = this.getCenterZ() + this.getDiameter() / 2.0D;
|
| 110 |
|
| 111 | if (d0 > (double)this.worldSize)
|
| 112 | {
|
| 113 | d0 = (double)this.worldSize;
|
| 114 | }
|
| 115 |
|
| 116 | return d0;
|
| 117 | }
|
| 118 |
|
| 119 | public double getCenterX()
|
| 120 | {
|
| 121 | return this.centerX;
|
| 122 | }
|
| 123 |
|
| 124 | public double getCenterZ()
|
| 125 | {
|
| 126 | return this.centerZ;
|
| 127 | }
|
| 128 |
|
| 129 | public void setCenter(double x, double z)
|
| 130 | {
|
| 131 | this.centerX = x;
|
| 132 | this.centerZ = z;
|
| 133 |
|
| 134 | for (IBorderListener iborderlistener : this.getListeners())
|
| 135 | {
|
| 136 | iborderlistener.onCenterChanged(this, x, z);
|
| 137 | }
|
| 138 | }
|
| 139 |
|
| 140 | public double getDiameter()
|
| 141 | {
|
| 142 | if (this.getStatus() != EnumBorderStatus.STATIONARY)
|
| 143 | {
|
| 144 | double d0 = (double)((float)(System.currentTimeMillis() - this.startTime) / (float)(this.endTime - this.startTime));
|
| 145 |
|
| 146 | if (d0 < 1.0D)
|
| 147 | {
|
| 148 | return this.startDiameter + (this.endDiameter - this.startDiameter) * d0;
|
| 149 | }
|
| 150 |
|
| 151 | this.setTransition(this.endDiameter);
|
| 152 | }
|
| 153 |
|
| 154 | return this.startDiameter;
|
| 155 | }
|
| 156 |
|
| 157 | public long getTimeUntilTarget()
|
| 158 | {
|
| 159 | return this.getStatus() != EnumBorderStatus.STATIONARY ? this.endTime - System.currentTimeMillis() : 0L;
|
| 160 | }
|
| 161 |
|
| 162 | public double getTargetSize()
|
| 163 | {
|
| 164 | return this.endDiameter;
|
| 165 | }
|
| 166 |
|
| 167 | public void setTransition(double newSize)
|
| 168 | {
|
| 169 | this.startDiameter = newSize;
|
| 170 | this.endDiameter = newSize;
|
| 171 | this.endTime = System.currentTimeMillis();
|
| 172 | this.startTime = this.endTime;
|
| 173 |
|
| 174 | for (IBorderListener iborderlistener : this.getListeners())
|
| 175 | {
|
| 176 | iborderlistener.onSizeChanged(this, newSize);
|
| 177 | }
|
| 178 | }
|
| 179 |
|
| 180 | public void setTransition(double oldSize, double newSize, long time)
|
| 181 | {
|
| 182 | this.startDiameter = oldSize;
|
| 183 | this.endDiameter = newSize;
|
| 184 | this.startTime = System.currentTimeMillis();
|
| 185 | this.endTime = this.startTime + time;
|
| 186 |
|
| 187 | for (IBorderListener iborderlistener : this.getListeners())
|
| 188 | {
|
| 189 | iborderlistener.onTransitionStarted(this, oldSize, newSize, time);
|
| 190 | }
|
| 191 | }
|
| 192 |
|
| 193 | protected List<IBorderListener> getListeners()
|
| 194 | {
|
| 195 | return Lists.newArrayList(this.listeners);
|
| 196 | }
|
| 197 |
|
| 198 | public void addListener(IBorderListener listener)
|
| 199 | {
|
| 200 | this.listeners.add(listener);
|
| 201 | }
|
| 202 |
|
| 203 | public void setSize(int size)
|
| 204 | {
|
| 205 | this.worldSize = size;
|
| 206 | }
|
| 207 |
|
| 208 | public int getSize()
|
| 209 | {
|
| 210 | return this.worldSize;
|
| 211 | }
|
| 212 |
|
| 213 | public double getDamageBuffer()
|
| 214 | {
|
| 215 | return this.damageBuffer;
|
| 216 | }
|
| 217 |
|
| 218 | public void setDamageBuffer(double bufferSize)
|
| 219 | {
|
| 220 | this.damageBuffer = bufferSize;
|
| 221 |
|
| 222 | for (IBorderListener iborderlistener : this.getListeners())
|
| 223 | {
|
| 224 | iborderlistener.onDamageBufferChanged(this, bufferSize);
|
| 225 | }
|
| 226 | }
|
| 227 |
|
| 228 | public double getDamageAmount()
|
| 229 | {
|
| 230 | return this.damageAmount;
|
| 231 | }
|
| 232 |
|
| 233 | public void setDamageAmount(double newAmount)
|
| 234 | {
|
| 235 | this.damageAmount = newAmount;
|
| 236 |
|
| 237 | for (IBorderListener iborderlistener : this.getListeners())
|
| 238 | {
|
| 239 | iborderlistener.onDamageAmountChanged(this, newAmount);
|
| 240 | }
|
| 241 | }
|
| 242 |
|
| 243 | public double getResizeSpeed()
|
| 244 | {
|
| 245 | return this.endTime == this.startTime ? 0.0D : Math.abs(this.startDiameter - this.endDiameter) / (double)(this.endTime - this.startTime);
|
| 246 | }
|
| 247 |
|
| 248 | public int getWarningTime()
|
| 249 | {
|
| 250 | return this.warningTime;
|
| 251 | }
|
| 252 |
|
| 253 | public void setWarningTime(int warningTime)
|
| 254 | {
|
| 255 | this.warningTime = warningTime;
|
| 256 |
|
| 257 | for (IBorderListener iborderlistener : this.getListeners())
|
| 258 | {
|
| 259 | iborderlistener.onWarningTimeChanged(this, warningTime);
|
| 260 | }
|
| 261 | }
|
| 262 |
|
| 263 | public int getWarningDistance()
|
| 264 | {
|
| 265 | return this.warningDistance;
|
| 266 | }
|
| 267 |
|
| 268 | public void setWarningDistance(int warningDistance)
|
| 269 | {
|
| 270 | this.warningDistance = warningDistance;
|
| 271 |
|
| 272 | for (IBorderListener iborderlistener : this.getListeners())
|
| 273 | {
|
| 274 | iborderlistener.onWarningDistanceChanged(this, warningDistance);
|
| 275 | }
|
| 276 | }
|
| 277 | }
|
| 278 |
|