Skip to content
Merged

PR #17

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions nPaper-API/src/main/java/org/bukkit/entity/Entity.java
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,20 @@ public interface Entity extends Metadatable {
* @return True if entity is on ground.
*/
public boolean isOnGround();

/**
* Reduction of the knockback.
*
* @param reduction The new knockback reduction.
*/
public void setKnockbackReduction(float reduction);

/**
* Gets the actual knockback reduction of the entity
*
* @return Knockback reduction
*/
public float getKnockbackReduction();

/**
* Gets the current world this entity resides in
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public enum InventoryType {
* A player's inventory, with 9 QUICKBAR slots, 27 CONTAINER slots, and 4
* ARMOR slots. The ARMOUR slots may not be visible to the player, though.
*/
PLAYER(36,"Player"),
PLAYER(40,"Player"), // nPaper - add the 4 ARMOR slot
/**
* The creative mode inventory, with only 9 QUICKBAR slots and nothing
* else. (The actual creative interface with the items is client-side and
Expand Down
2 changes: 1 addition & 1 deletion nPaper-Server/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@
<dependency>
<groupId>org.xerial</groupId>
<artifactId>sqlite-jdbc</artifactId>
<version>3.40.0.0</version>
<version>3.42.0.0</version>
<type>jar</type>
<scope>compile</scope>
</dependency>
Expand Down
58 changes: 15 additions & 43 deletions nPaper-Server/src/main/java/net/minecraft/server/DataWatcher.java
Original file line number Diff line number Diff line change
@@ -1,35 +1,34 @@
package net.minecraft.server;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.concurrent.locks.ReadWriteLock;
import java.util.concurrent.locks.ReentrantReadWriteLock;

import net.minecraft.util.org.apache.commons.lang3.ObjectUtils;
import org.spigotmc.ProtocolData; // Spigot - protocol patch

import net.minecraft.util.org.apache.commons.lang3.ObjectUtils;

public class DataWatcher {

private final Entity a;
private boolean b = true;
// Spigot Start
private static final net.minecraft.util.gnu.trove.map.TObjectIntMap classToId = new net.minecraft.util.gnu.trove.map.hash.TObjectIntHashMap( 10, 0.5f, -1 );
private final net.minecraft.util.gnu.trove.map.TIntObjectMap dataValues = new net.minecraft.util.gnu.trove.map.hash.TIntObjectHashMap( 10, 0.5f, -1 );
private final net.minecraft.util.gnu.trove.map.TIntObjectMap<WatchableObject> dataValues = new net.minecraft.util.gnu.trove.map.hash.TIntObjectHashMap<WatchableObject>( 10, 0.5f, -1 );
// These exist as an attempt at backwards compatability for (broken) NMS plugins
private static final Map c = net.minecraft.util.gnu.trove.TDecorators.wrap( classToId );
private final Map d = net.minecraft.util.gnu.trove.TDecorators.wrap( dataValues );
// Spigot End
private boolean e;
private ReadWriteLock f = new ReentrantReadWriteLock();

public DataWatcher(Entity entity) {
this.a = entity;
}

boolean registrationLocked; // PandaSpigot
public void a(int i, Object object) {
if (registrationLocked) throw new IllegalStateException("Registering datawatcher object after entity initialization"); // PandaSpigot
int integer = classToId.get(object.getClass()); // Spigot

// Spigot start - protocol patch
Expand All @@ -54,19 +53,15 @@ public void a(int i, Object object) {
} else {
WatchableObject watchableobject = new WatchableObject(integer, i, object); // Spigot

this.f.writeLock().lock();
this.dataValues.put(i, watchableobject); // Spigot
this.f.writeLock().unlock();
this.b = false;
}
}

public void add(int i, int j) {
WatchableObject watchableobject = new WatchableObject(j, i, null);

this.f.writeLock().lock();
this.dataValues.put(i, watchableobject); // Spigot
this.f.writeLock().unlock();
this.b = false;
}

Expand Down Expand Up @@ -107,22 +102,7 @@ public ProtocolData.DualInt getDualInt(int i) {
// Spigot end

private WatchableObject i(int i) {
this.f.readLock().lock();

WatchableObject watchableobject;

try {
watchableobject = (WatchableObject) this.dataValues.get(i); // Spigot
} catch (Throwable throwable) {
CrashReport crashreport = CrashReport.a(throwable, "Getting synched entity data");
CrashReportSystemDetails crashreportsystemdetails = crashreport.a("Synched entity data");

crashreportsystemdetails.a("Data ID", Integer.valueOf(i));
throw new ReportedException(crashreport);
}

this.f.readLock().unlock();
return watchableobject;
return (WatchableObject) this.dataValues.get(i);
}

public void watch(int i, Object object) {
Expand Down Expand Up @@ -165,20 +145,19 @@ public static void a(List list, PacketDataSerializer packetdataserializer, int v
packetdataserializer.writeByte(127);
}

public List b() {
ArrayList arraylist = null;
public List<WatchableObject> b() {
ArrayList<WatchableObject> arraylist = null;

if (this.e) {
this.f.readLock().lock();
Iterator iterator = this.dataValues.valueCollection().iterator(); // Spigot
Iterator<WatchableObject> iterator = this.dataValues.valueCollection().iterator(); // Spigot

while (iterator.hasNext()) {
WatchableObject watchableobject = (WatchableObject) iterator.next();

if (watchableobject.d()) {
watchableobject.a(false);
if (arraylist == null) {
arraylist = new ArrayList();
arraylist = new ArrayList<WatchableObject>();
}

// Spigot start - copy ItemStacks to prevent ConcurrentModificationExceptions
Expand All @@ -195,8 +174,6 @@ public List b() {
arraylist.add(watchableobject);
}
}

this.f.readLock().unlock();
}

this.e = false;
Expand All @@ -210,7 +187,6 @@ public void a(PacketDataSerializer packetdataserializer) {

public void a(PacketDataSerializer packetdataserializer, int version) {
// Spigot end
this.f.readLock().lock();
Iterator iterator = this.dataValues.valueCollection().iterator(); // Spigot

while (iterator.hasNext()) {
Expand All @@ -219,14 +195,11 @@ public void a(PacketDataSerializer packetdataserializer, int version) {
a(packetdataserializer, watchableobject, version); // Spigot - protocol patch
}

this.f.readLock().unlock();
packetdataserializer.writeByte(127);
}

public List c() {
ArrayList arraylist = new ArrayList(); // Spigot

this.f.readLock().lock();
public List<WatchableObject> c() {
ArrayList<WatchableObject> arraylist = new ArrayList(); // Spigot

arraylist.addAll(this.dataValues.valueCollection()); // Spigot
// Spigot start - copy ItemStacks to prevent ConcurrentModificationExceptions
Expand All @@ -245,7 +218,6 @@ public List c() {
}
// Spigot end

this.f.readLock().unlock();
return arraylist;
}

Expand Down Expand Up @@ -315,12 +287,12 @@ private static void a(PacketDataSerializer packetdataserializer, WatchableObject
}
// Spigot end

public static List b(PacketDataSerializer packetdataserializer) {
ArrayList arraylist = null;
public static List<WatchableObject> b(PacketDataSerializer packetdataserializer) {
ArrayList<WatchableObject> arraylist = null;

for (byte b0 = packetdataserializer.readByte(); b0 != 127; b0 = packetdataserializer.readByte()) {
if (arraylist == null) {
arraylist = new ArrayList();
arraylist = new ArrayList<WatchableObject>();
}

int i = (b0 & 224) >> 5;
Expand Down
18 changes: 1 addition & 17 deletions nPaper-Server/src/main/java/net/minecraft/server/Entity.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,6 @@ public void retrack() {
protected int aq;
private boolean invulnerable;
public UUID uniqueID; // CraftBukkit - protected -> public
public EnumEntitySize as;
public boolean valid; // CraftBukkit
public org.bukkit.projectiles.ProjectileSource projectileSource; // CraftBukkit - For projectiles only
public boolean inUnloadedChunk = false; // PaperSpigot - Remove entities in unloaded chunks
Expand Down Expand Up @@ -155,7 +154,6 @@ public Entity(World world) {
this.maxFireTicks = 1;
this.justCreated = true;
this.uniqueID = new UUID(random.nextLong(), random.nextLong()); // Spigot
this.as = EnumEntitySize.SIZE_2;
this.world = world;
this.setPosition(0.0D, 0.0D, 0.0D);
if (world != null) {
Expand All @@ -171,6 +169,7 @@ public Entity(World world) {
this.datawatcher.a(0, Byte.valueOf((byte) 0));
this.datawatcher.a(1, Short.valueOf((short) 300));
this.c();
this.datawatcher.registrationLocked = true; // PandaSpigot
}

protected abstract void c();
Expand Down Expand Up @@ -205,21 +204,6 @@ protected void a(float f, float f1) {
this.move((double) (f2 - this.width), 0.0D, (double) (f2 - this.width));
}
}

f2 = f % 2.0F;
if ((double) f2 < 0.375D) {
this.as = EnumEntitySize.SIZE_1;
} else if ((double) f2 < 0.75D) {
this.as = EnumEntitySize.SIZE_2;
} else if ((double) f2 < 1.0D) {
this.as = EnumEntitySize.SIZE_3;
} else if ((double) f2 < 1.375D) {
this.as = EnumEntitySize.SIZE_4;
} else if ((double) f2 < 1.75D) {
this.as = EnumEntitySize.SIZE_5;
} else {
this.as = EnumEntitySize.SIZE_6;
}
}

protected void b(float f, float f1) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,12 @@ public EntityEnderPearl(World world, EntityLiving entityliving) {

// nPaper start - antipearl glitch
public void h() {
if (PaperSpigotConfig.fixEnderPearlGlitch && this.world.getCubes(this, this.boundingBox.grow(0.25D, 0.25D, 0.25D)).isEmpty()) {
final EntityLiving entityliving = this.getShooter();
if (entityliving != null && entityliving instanceof EntityHuman && !entityliving.isAlive()) {
this.die();
return;
}
if (PaperSpigotConfig.fixEnderPearlGlitch && this.world.getCubes(this, this.boundingBox.grow(0.225D, 0.1D, 0.225D)).isEmpty()) {
this.lastValidLocation = getBukkitEntity().getLocation();
}
super.h();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,26 @@ public void h() {
this.j(this.locX, (this.boundingBox.b + this.boundingBox.e) / 2.0D, this.locZ);
double d0 = 8.0D;

EntityHuman foundTarget = null;
boolean wasCancelled = false;
if (this.targetTime < this.a - 20 + this.getId() % 100) {
if (this.targetPlayer == null || this.targetPlayer.f(this) > d0 * d0) {
this.targetPlayer = this.world.findNearbyPlayer(this, d0);
foundTarget = this.world.findNearbyPlayer(this, d0);
if(foundTarget == null) {
this.targetPlayer = foundTarget;
} else if (foundTarget != null && !foundTarget.equals(this.targetPlayer)) {
// CraftBukkit start
EntityTargetEvent event = CraftEventFactory.callEntityTargetEvent(this, foundTarget, EntityTargetEvent.TargetReason.CLOSEST_PLAYER);
Entity target = event.getTarget() == null ? null : ((org.bukkit.craftbukkit.entity.CraftEntity) event.getTarget()).getHandle();
if (!(event.isCancelled())) {
if (target == null) {
this.targetPlayer = null;
} else if (target instanceof EntityHuman) {
this.targetPlayer = (EntityHuman) target;
}
}
// CraftBukkit end
}
}

this.targetTime = this.a;
Expand All @@ -73,7 +90,7 @@ public void h() {
Entity target = event.getTarget() == null ? null : ((org.bukkit.craftbukkit.entity.CraftEntity) event.getTarget()).getHandle();

if (!event.isCancelled() && target != null) {
double d1 = (target.locX - this.locX) / d0;
double d1 = (target.locX - this.locX) / d0;
double d2 = (target.locY + (double) target.getHeadHeight() - this.locY) / d0;
double d3 = (target.locZ - this.locZ) / d0;
double d4 = Math.sqrt(d1 * d1 + d2 * d2 + d3 * d3);
Expand Down Expand Up @@ -104,9 +121,12 @@ public void h() {

++this.a;
++this.b;
if (this.b >= 6000) {
if (this.b >= this.world.spigotConfig.expDespawnRate) { // Rinny - add ExpDespawnRate :)
this.die();
}
} else if (wasCancelled) { // Reduce desync
EntityTrackerEntry tracker = (EntityTrackerEntry)((WorldServer)this.world).tracker.trackedEntities.get(getId());
tracker.broadcast(new PacketPlayOutRelEntityMove(getId(), (byte)(MathHelper.floor(this.locX * 32.0D) - tracker.xLoc), (byte)(MathHelper.floor(this.locY * 32.0D) - tracker.yLoc), (byte)(MathHelper.floor(this.locZ * 32.0D) - tracker.zLoc), this.onGround));
}
}

public boolean N() {
Expand All @@ -120,27 +140,25 @@ protected void burn(int i) {
public boolean damageEntity(DamageSource damagesource, float f) {
if (this.isInvulnerable()) {
return false;
} else {
this.Q();
this.d = (int) ((float) this.d - f);
if (this.d <= 0) {
this.die();
}

return false;
}
this.Q();
this.d = (int) ((float) this.d - f);
if (this.d <= 0) {
this.die();
}
return false;
}

public void b(NBTTagCompound nbttagcompound) {
nbttagcompound.setShort("Health", (short) ((byte) this.d));
nbttagcompound.setShort("Age", (short) this.b);
nbttagcompound.setShort("Value", (short) this.value);
nbttagcompound.setInt("Value", this.value);
}

public void a(NBTTagCompound nbttagcompound) {
this.d = nbttagcompound.getShort("Health") & 255;
this.b = nbttagcompound.getShort("Age");
this.value = nbttagcompound.getShort("Value");
this.value = nbttagcompound.getInt("Value");
}

public void b_(EntityHuman entityhuman) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ public boolean damageEntity(DamageSource damagesource, float f) {
HangingBreakEvent event = new HangingBreakEvent((Hanging) this.getBukkitEntity(), HangingBreakEvent.RemoveCause.DEFAULT);
PaintingBreakEvent paintingEvent = null;
if (damagesource.getEntity() != null) {
event = new org.bukkit.event.hanging.HangingBreakByEntityEvent((Hanging) this.getBukkitEntity(), damagesource.getEntity() == null ? null : damagesource.getEntity().getBukkitEntity());
event = new org.bukkit.event.hanging.HangingBreakByEntityEvent((Hanging) this.getBukkitEntity(), damagesource.getEntity() == null ? null : (org.bukkit.entity.Entity) damagesource.getEntity().getBukkitEntity());

if (this instanceof EntityPainting) {
// Fire old painting event until it can be removed
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -883,15 +883,16 @@ public void a(Entity entity, float f, double d0, double d1) {
this.al = true;
// Rinny start - configurable knockback
double magnitude = MathHelper.sqrt(d0 * d0 + d1 * d1);
double d2 = this.world.paperSpigotConfig.knockbackForceAndHeight;
final double knockbackReduction = getBukkitEntity().getKnockbackReduction();
final double force = (world.paperSpigotConfig.knockbackForceAndHeight * (1.0D - knockbackReduction));

this.motX /= 2.0;
this.motY /= 2.0;
this.motZ /= 2.0;

this.motX -= d0 / magnitude * d2;
this.motY = MathHelper.limit(this.motY + d2, 0.05D, this.world.paperSpigotConfig.knockbackVerticalLimit);
this.motZ -= d1 / magnitude * d2;
this.motX -= d0 / magnitude * force;
this.motY = MathHelper.limit(this.motY + force, 0.05D, this.world.paperSpigotConfig.knockbackVerticalLimit);
this.motZ -= d1 / magnitude * force;
// Rinny end
}
}
Expand Down Expand Up @@ -1045,7 +1046,7 @@ public Double apply(Double f) {
public Double apply(Double f) {
if (human) {
if (!damagesource.ignoresArmor() && ((EntityHuman) EntityLiving.this).isBlocking() && f > 0.0F) {
return -(f - ((1.0F + f) * 0.5F));
return -(f - ((1.0F + f) * EntityLiving.this.world.paperSpigotConfig.playerBlockingDamageMultiplier));
}
}
return -0.0;
Expand Down
Loading