mirror of
https://github.com/PaperMC/Paper.git
synced 2024-12-12 01:41:05 +01:00
Second part of NPE and arctan update :3
This commit is contained in:
parent
cec04a7360
commit
bf9a55049e
7 changed files with 34 additions and 19 deletions
|
@ -6,6 +6,8 @@ import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
import java.util.Random;
|
import java.util.Random;
|
||||||
|
|
||||||
|
import org.bukkit.craftbukkit.CraftWorld;
|
||||||
|
|
||||||
public class Chunk {
|
public class Chunk {
|
||||||
|
|
||||||
public static boolean a;
|
public static boolean a;
|
||||||
|
@ -44,7 +46,8 @@ public class Chunk {
|
||||||
}
|
}
|
||||||
|
|
||||||
// CraftBukkit start
|
// CraftBukkit start
|
||||||
bukkitChunk = ((WorldServer) world).getWorld().popPreservedChunk( i, j );
|
CraftWorld cw = ((WorldServer) world).getWorld();
|
||||||
|
bukkitChunk = (cw == null) ? null:cw.popPreservedChunk( i, j );
|
||||||
if (bukkitChunk == null) {
|
if (bukkitChunk == null) {
|
||||||
bukkitChunk = new org.bukkit.craftbukkit.CraftChunk( this );
|
bukkitChunk = new org.bukkit.craftbukkit.CraftChunk( this );
|
||||||
}
|
}
|
||||||
|
|
|
@ -4,6 +4,7 @@ package net.minecraft.server;
|
||||||
import org.bukkit.craftbukkit.entity.CraftMonster;
|
import org.bukkit.craftbukkit.entity.CraftMonster;
|
||||||
import org.bukkit.craftbukkit.CraftServer;
|
import org.bukkit.craftbukkit.CraftServer;
|
||||||
import org.bukkit.craftbukkit.entity.CraftEntity;
|
import org.bukkit.craftbukkit.entity.CraftEntity;
|
||||||
|
import org.bukkit.craftbukkit.TrigMath;
|
||||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||||
import org.bukkit.event.entity.EntityDamageEvent;
|
import org.bukkit.event.entity.EntityDamageEvent;
|
||||||
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
||||||
|
@ -118,7 +119,7 @@ public class EntityCreature extends EntityLiving {
|
||||||
double d1 = vec3d.a - this.locX;
|
double d1 = vec3d.a - this.locX;
|
||||||
double d2 = vec3d.c - this.locZ;
|
double d2 = vec3d.c - this.locZ;
|
||||||
double d3 = vec3d.b - (double) l1;
|
double d3 = vec3d.b - (double) l1;
|
||||||
float f4 = (float) (Math.atan2(d2, d1) * 180.0D / 3.1415927410125732D) - 90.0F;
|
float f4 = (float) (TrigMath.atan2(d2, d1) * 180.0D / 3.1415927410125732D) - 90.0F;
|
||||||
float f5 = f4 - this.yaw;
|
float f5 = f4 - this.yaw;
|
||||||
|
|
||||||
for (this.by = this.bC; f5 < -180.0F; f5 += 360.0F) {
|
for (this.by = this.bC; f5 < -180.0F; f5 += 360.0F) {
|
||||||
|
|
|
@ -4,6 +4,7 @@ import java.util.List;
|
||||||
|
|
||||||
// CraftBukkit start
|
// CraftBukkit start
|
||||||
import org.bukkit.craftbukkit.CraftServer;
|
import org.bukkit.craftbukkit.CraftServer;
|
||||||
|
import org.bukkit.craftbukkit.TrigMath;
|
||||||
import org.bukkit.craftbukkit.entity.CraftItemDrop;
|
import org.bukkit.craftbukkit.entity.CraftItemDrop;
|
||||||
import org.bukkit.entity.Player;
|
import org.bukkit.entity.Player;
|
||||||
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
import org.bukkit.event.entity.EntityDamageByEntityEvent;
|
||||||
|
@ -124,7 +125,7 @@ public abstract class EntityHuman extends EntityLiving {
|
||||||
this.as = this.at;
|
this.as = this.at;
|
||||||
super.o();
|
super.o();
|
||||||
float f = MathHelper.a(this.motX * this.motX + this.motZ * this.motZ);
|
float f = MathHelper.a(this.motX * this.motX + this.motZ * this.motZ);
|
||||||
float f1 = (float) Math.atan(-this.motY * 0.20000000298023224D) * 15.0F;
|
float f1 = (float) TrigMath.atan(-this.motY * 0.20000000298023224D) * 15.0F;
|
||||||
|
|
||||||
if (f > 0.1F) {
|
if (f > 0.1F) {
|
||||||
f = 0.1F;
|
f = 0.1F;
|
||||||
|
|
|
@ -10,6 +10,7 @@ import org.bukkit.craftbukkit.CraftServer;
|
||||||
import org.bukkit.craftbukkit.CraftWorld;
|
import org.bukkit.craftbukkit.CraftWorld;
|
||||||
import org.bukkit.craftbukkit.entity.CraftEntity;
|
import org.bukkit.craftbukkit.entity.CraftEntity;
|
||||||
import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
import org.bukkit.craftbukkit.inventory.CraftItemStack;
|
||||||
|
import org.bukkit.craftbukkit.TrigMath;
|
||||||
import org.bukkit.event.Event.Type;
|
import org.bukkit.event.Event.Type;
|
||||||
import org.bukkit.event.entity.EntityDamageEvent;
|
import org.bukkit.event.entity.EntityDamageEvent;
|
||||||
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
import org.bukkit.event.entity.EntityDamageEvent.DamageCause;
|
||||||
|
@ -236,7 +237,7 @@ public abstract class EntityLiving extends Entity {
|
||||||
if (f > 0.05F) {
|
if (f > 0.05F) {
|
||||||
f3 = 1.0F;
|
f3 = 1.0F;
|
||||||
f2 = f * 3.0F;
|
f2 = f * 3.0F;
|
||||||
f1 = (float) Math.atan2(d1, d0) * 180.0F / 3.1415927F - 90.0F;
|
f1 = (float) TrigMath.atan2(d1, d0) * 180.0F / 3.1415927F - 90.0F;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (this.aY > 0.0F) {
|
if (this.aY > 0.0F) {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
|
|
||||||
package org.bukkit.craftbukkit;
|
package org.bukkit.craftbukkit;
|
||||||
|
|
||||||
|
import java.lang.ref.WeakReference;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
|
||||||
import net.minecraft.server.WorldServer;
|
import net.minecraft.server.WorldServer;
|
||||||
|
@ -11,27 +12,38 @@ import org.bukkit.block.Block;
|
||||||
import org.bukkit.craftbukkit.block.CraftBlock;
|
import org.bukkit.craftbukkit.block.CraftBlock;
|
||||||
|
|
||||||
public class CraftChunk implements Chunk {
|
public class CraftChunk implements Chunk {
|
||||||
private net.minecraft.server.Chunk chunk;
|
private WeakReference<net.minecraft.server.Chunk> weakChunk;
|
||||||
private final HashMap<Integer, Block> cache = new HashMap<Integer, Block>();
|
private final HashMap<Integer, Block> cache = new HashMap<Integer, Block>();
|
||||||
|
private WorldServer worldServer;
|
||||||
|
private int x;
|
||||||
|
private int z;
|
||||||
|
|
||||||
public CraftChunk(net.minecraft.server.Chunk chunk) {
|
public CraftChunk(net.minecraft.server.Chunk chunk) {
|
||||||
this.chunk = chunk;
|
this.weakChunk = new WeakReference<net.minecraft.server.Chunk>(chunk);
|
||||||
|
worldServer = (WorldServer) getHandle().d;
|
||||||
|
x = getHandle().j;
|
||||||
|
z = getHandle().k;
|
||||||
}
|
}
|
||||||
|
|
||||||
public World getWorld() {
|
public World getWorld() {
|
||||||
return ((WorldServer) chunk.d).getWorld();
|
return worldServer.getWorld();
|
||||||
}
|
}
|
||||||
|
|
||||||
public net.minecraft.server.Chunk getHandle() {
|
public net.minecraft.server.Chunk getHandle() {
|
||||||
return chunk;
|
net.minecraft.server.Chunk c = weakChunk.get();
|
||||||
|
if (c == null) {
|
||||||
|
weakChunk = new WeakReference<net.minecraft.server.Chunk>(worldServer.c(x,z));
|
||||||
|
c = weakChunk.get();
|
||||||
|
}
|
||||||
|
return c;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getX() {
|
public int getX() {
|
||||||
return chunk.j;
|
return x;
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getZ() {
|
public int getZ() {
|
||||||
return chunk.k;
|
return z;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -48,8 +60,5 @@ public class CraftChunk implements Chunk {
|
||||||
}
|
}
|
||||||
return block;
|
return block;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void breakLink() {
|
|
||||||
this.chunk = null;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -47,12 +47,11 @@ public class CraftWorld implements World {
|
||||||
}
|
}
|
||||||
|
|
||||||
public void preserveChunk( CraftChunk chunk ) {
|
public void preserveChunk( CraftChunk chunk ) {
|
||||||
chunk.breakLink();
|
unloadedChunks.put( (chunk.getX() << 16) + chunk.getZ(), chunk );
|
||||||
unloadedChunks.put( chunk.getX() << 16 + chunk.getZ(), chunk );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public CraftChunk popPreservedChunk( int x, int z ) {
|
public CraftChunk popPreservedChunk( int x, int z ) {
|
||||||
return unloadedChunks.remove( x << 16 + z );
|
return unloadedChunks.remove( (x << 16) + z );
|
||||||
}
|
}
|
||||||
|
|
||||||
public Block getBlockAt(int x, int y, int z) {
|
public Block getBlockAt(int x, int y, int z) {
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
package org.bukkit.craftbukkit;
|
package org.bukkit.craftbukkit;
|
||||||
/**
|
/**
|
||||||
* Got this code from a post by user aioobe on stackoverflow.com
|
* Credits for this class goes to user aioobe on stackoverflow.com
|
||||||
|
* Source: http://stackoverflow.com/questions/4454630/j2me-calculate-the-the-distance-between-2-latitude-and-longitude
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
public class TrigMath {
|
public class TrigMath {
|
||||||
|
|
Loading…
Reference in a new issue