1
0
forked from xjboss/KCauldronX

First attempt to fix #141

This commit is contained in:
Prototik 2015-09-03 15:58:51 +07:00
parent 1e51ceeb31
commit 923b9e81a0
4 changed files with 121 additions and 114 deletions

View File

@ -1,7 +1,9 @@
--- ../src-base/minecraft/net/minecraft/entity/EntityLivingBase.java --- ../src-base/minecraft/net/minecraft/entity/EntityLivingBase.java
+++ ../src-work/minecraft/net/minecraft/entity/EntityLivingBase.java +++ ../src-work/minecraft/net/minecraft/entity/EntityLivingBase.java
@@ -2,12 +2,14 @@ @@ -1,13 +1,16 @@
package net.minecraft.entity;
+import cpw.mods.fml.common.FMLLog;
import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly; import cpw.mods.fml.relauncher.SideOnly;
+ +
@ -15,7 +17,7 @@
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
import net.minecraft.enchantment.EnchantmentHelper; import net.minecraft.enchantment.EnchantmentHelper;
@@ -50,14 +52,30 @@ @@ -50,14 +53,30 @@
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraft.world.WorldServer; import net.minecraft.world.WorldServer;
import net.minecraftforge.common.ForgeHooks; import net.minecraftforge.common.ForgeHooks;
@ -48,7 +50,7 @@
private final ItemStack[] previousEquipment = new ItemStack[5]; private final ItemStack[] previousEquipment = new ItemStack[5];
public boolean isSwingInProgress; public boolean isSwingInProgress;
public int swingProgressInt; public int swingProgressInt;
@@ -83,7 +101,7 @@ @@ -83,7 +102,7 @@
public float rotationYawHead; public float rotationYawHead;
public float prevRotationYawHead; public float prevRotationYawHead;
public float jumpMovementFactor = 0.02F; public float jumpMovementFactor = 0.02F;
@ -57,7 +59,7 @@
protected int recentlyHit; protected int recentlyHit;
protected boolean dead; protected boolean dead;
protected int entityAge; protected int entityAge;
@@ -93,7 +111,7 @@ @@ -93,7 +112,7 @@
protected float field_70763_ax; protected float field_70763_ax;
protected float field_70741_aB; protected float field_70741_aB;
protected int scoreValue; protected int scoreValue;
@ -66,7 +68,7 @@
protected boolean isJumping; protected boolean isJumping;
public float moveStrafing; public float moveStrafing;
public float moveForward; public float moveForward;
@@ -104,21 +122,26 @@ @@ -104,21 +123,26 @@
protected double newPosZ; protected double newPosZ;
protected double newRotationYaw; protected double newRotationYaw;
protected double newRotationPitch; protected double newRotationPitch;
@ -96,7 +98,7 @@
this.preventEntitySpawning = true; this.preventEntitySpawning = true;
this.field_70770_ap = (float)(Math.random() + 1.0D) * 0.01F; this.field_70770_ap = (float)(Math.random() + 1.0D) * 0.01F;
this.setPosition(this.posX, this.posY, this.posZ); this.setPosition(this.posX, this.posY, this.posZ);
@@ -173,7 +196,18 @@ @@ -173,7 +197,18 @@
} }
else if (!this.worldObj.isRemote && this.fallDistance > 3.0F) else if (!this.worldObj.isRemote && this.fallDistance > 3.0F)
{ {
@ -116,7 +118,7 @@
} }
block.onFallenUpon(this.worldObj, i, j, k, this, this.fallDistance); block.onFallenUpon(this.worldObj, i, j, k, this, this.fallDistance);
@@ -234,7 +268,12 @@ @@ -234,7 +269,12 @@
} }
else else
{ {
@ -130,7 +132,7 @@
} }
if (this.isEntityAlive() && this.isWet()) if (this.isEntityAlive() && this.isWet())
@@ -299,6 +338,22 @@ @@ -299,6 +339,22 @@
this.worldObj.theProfiler.endSection(); this.worldObj.theProfiler.endSection();
} }
@ -153,7 +155,7 @@
public boolean isChild() public boolean isChild()
{ {
return false; return false;
@@ -308,22 +363,21 @@ @@ -308,22 +364,21 @@
{ {
++this.deathTime; ++this.deathTime;
@ -185,7 +187,7 @@
this.setDead(); this.setDead();
for (i = 0; i < 20; ++i) for (i = 0; i < 20; ++i)
@@ -485,6 +539,22 @@ @@ -485,6 +540,22 @@
} }
} }
@ -208,7 +210,7 @@
if (p_70037_1_.hasKey("HealF", 99)) if (p_70037_1_.hasKey("HealF", 99))
{ {
this.setHealth(p_70037_1_.getFloat("HealF")); this.setHealth(p_70037_1_.getFloat("HealF"));
@@ -614,12 +684,14 @@ @@ -614,12 +685,14 @@
public boolean isPotionActive(int p_82165_1_) public boolean isPotionActive(int p_82165_1_)
{ {
@ -225,7 +227,7 @@
} }
public PotionEffect getActivePotionEffect(Potion p_70660_1_) public PotionEffect getActivePotionEffect(Potion p_70660_1_)
@@ -710,25 +782,66 @@ @@ -710,25 +783,66 @@
} }
} }
@ -293,7 +295,7 @@
this.dataWatcher.updateObject(6, Float.valueOf(MathHelper.clamp_float(p_70606_1_, 0.0F, this.getMaxHealth()))); this.dataWatcher.updateObject(6, Float.valueOf(MathHelper.clamp_float(p_70606_1_, 0.0F, this.getMaxHealth())));
} }
@@ -757,7 +870,8 @@ @@ -757,7 +871,8 @@
} }
else else
{ {
@ -303,7 +305,7 @@
{ {
this.getEquipmentInSlot(4).damageItem((int)(p_70097_2_ * 4.0F + this.rand.nextFloat() * p_70097_2_ * 2.0F), this); this.getEquipmentInSlot(4).damageItem((int)(p_70097_2_ * 4.0F + this.rand.nextFloat() * p_70097_2_ * 2.0F), this);
p_70097_2_ *= 0.75F; p_70097_2_ *= 0.75F;
@@ -773,16 +887,27 @@ @@ -773,16 +888,27 @@
return false; return false;
} }
@ -334,7 +336,7 @@
this.hurtTime = this.maxHurtTime = 10; this.hurtTime = this.maxHurtTime = 10;
} }
@@ -938,6 +1063,22 @@ @@ -938,6 +1064,22 @@
if (!ForgeHooks.onLivingDrops(this, p_70645_1_, capturedDrops, i, recentlyHit > 0, j)) if (!ForgeHooks.onLivingDrops(this, p_70645_1_, capturedDrops, i, recentlyHit > 0, j))
{ {
@ -357,7 +359,7 @@
for (EntityItem item : capturedDrops) for (EntityItem item : capturedDrops)
{ {
worldObj.spawnEntityInWorld(item); worldObj.spawnEntityInWorld(item);
@@ -1010,8 +1151,17 @@ @@ -1010,8 +1152,17 @@
if (i > 0) if (i > 0)
{ {
@ -376,7 +378,7 @@
int j = MathHelper.floor_double(this.posX); int j = MathHelper.floor_double(this.posX);
int k = MathHelper.floor_double(this.posY - 0.20000000298023224D - (double)this.yOffset); int k = MathHelper.floor_double(this.posY - 0.20000000298023224D - (double)this.yOffset);
int l = MathHelper.floor_double(this.posZ); int l = MathHelper.floor_double(this.posZ);
@@ -1065,7 +1215,7 @@ @@ -1065,7 +1216,7 @@
{ {
int i = 25 - this.getTotalArmorValue(); int i = 25 - this.getTotalArmorValue();
float f1 = p_70655_2_ * (float)i; float f1 = p_70655_2_ * (float)i;
@ -385,7 +387,7 @@
p_70655_2_ = f1 / 25.0F; p_70655_2_ = f1 / 25.0F;
} }
@@ -1089,7 +1239,8 @@ @@ -1089,7 +1240,8 @@
int j; int j;
float f1; float f1;
@ -395,7 +397,7 @@
{ {
i = (this.getActivePotionEffect(Potion.resistance).getAmplifier() + 1) * 5; i = (this.getActivePotionEffect(Potion.resistance).getAmplifier() + 1) * 5;
j = 25 - i; j = 25 - i;
@@ -1122,26 +1273,161 @@ @@ -1122,26 +1274,160 @@
} }
} }
@ -420,7 +422,6 @@
- p_70665_2_ = Math.max(p_70665_2_ - this.getAbsorptionAmount(), 0.0F); - p_70665_2_ = Math.max(p_70665_2_ - this.getAbsorptionAmount(), 0.0F);
- this.setAbsorptionAmount(this.getAbsorptionAmount() - (f1 - p_70665_2_)); - this.setAbsorptionAmount(this.getAbsorptionAmount() - (f1 - p_70665_2_));
+ final boolean human = this instanceof EntityPlayer; + final boolean human = this instanceof EntityPlayer;
+ float originalDamage = f;
+ // Cauldron start - apply forge damage hook + // Cauldron start - apply forge damage hook
+ f = ForgeHooks.onLivingHurt(this, damagesource, f); + f = ForgeHooks.onLivingHurt(this, damagesource, f);
+ if (f <= 0) return true; + if (f <= 0) return true;
@ -512,7 +513,7 @@
+ }; + };
+ float absorptionModifier = absorption.apply((double) f).floatValue(); + float absorptionModifier = absorption.apply((double) f).floatValue();
+ +
+ EntityDamageEvent event = CraftEventFactory.handleLivingEntityDamageEvent(this, damagesource, originalDamage, hardHatModifier, blockingModifier, + EntityDamageEvent event = CraftEventFactory.handleLivingEntityDamageEvent(this, damagesource, f, hardHatModifier, blockingModifier,
+ armorModifier, resistanceModifier, magicModifier, absorptionModifier, hardHat, blocking, armor, resistance, magic, absorption); + armorModifier, resistanceModifier, magicModifier, absorptionModifier, hardHat, blocking, armor, resistance, magic, absorption);
+ if (event.isCancelled()) + if (event.isCancelled())
{ {

View File

@ -895,7 +895,7 @@
+ entity = entityIterator.next(); + entity = entityIterator.next();
+ +
+ if (entity.markedForRemoval || entity.isDead) { + if (entity.markedForRemoval || entity.isDead) {
+ theProfiler.startSection("remove"); + theProfiler.startSection("remove");
+ int x = entity.chunkCoordX; + int x = entity.chunkCoordX;
+ int y = entity.chunkCoordZ; + int y = entity.chunkCoordZ;
+ if (entity.addedToChunk && chunkExists(x, y)) + if (entity.addedToChunk && chunkExists(x, y))

View File

@ -15,106 +15,106 @@ import net.minecraft.server.MinecraftServer;
import net.minecraftforge.server.command.ForgeCommand; import net.minecraftforge.server.command.ForgeCommand;
public class KCauldronCommand extends Command { public class KCauldronCommand extends Command {
public static final String NAME = "kc"; public static final String NAME = "kc";
public static final String CHECK = NAME + ".check"; public static final String CHECK = NAME + ".check";
public static final String UPDATE = NAME + ".update"; public static final String UPDATE = NAME + ".update";
public static final String TPS = NAME + ".tps"; public static final String TPS = NAME + ".tps";
public static final String RESTART = NAME + ".restart"; public static final String RESTART = NAME + ".restart";
public KCauldronCommand() { public KCauldronCommand() {
super(NAME); super(NAME);
StringBuilder builder = new StringBuilder(); StringBuilder builder = new StringBuilder();
builder.append(String.format("/%s check - Check to update\n", NAME)); builder.append(String.format("/%s check - Check to update\n", NAME));
builder.append(String.format("/%s update [version] - Update to specified or latest version\n", NAME)); builder.append(String.format("/%s update [version] - Update to specified or latest version\n", NAME));
builder.append(String.format("/%s tps - Show tps statistics\n", NAME)); builder.append(String.format("/%s tps - Show tps statistics\n", NAME));
builder.append(String.format("/%s restart - Restart server\n", NAME)); builder.append(String.format("/%s restart - Restart server\n", NAME));
setUsage(builder.toString()); setUsage(builder.toString());
setPermission("kcauldron"); setPermission("kcauldron");
} }
public boolean testPermission(CommandSender target, String permission) { public boolean testPermission(CommandSender target, String permission) {
if (testPermissionSilent(target, permission)) { if (testPermissionSilent(target, permission)) {
return true; return true;
} }
target.sendMessage(ChatColor.RED target.sendMessage(ChatColor.RED
+ "I'm sorry, but you do not have permission to perform this command. Please contact the server administrators if you believe that this is in error."); + "I'm sorry, but you do not have permission to perform this command. Please contact the server administrators if you believe that this is in error.");
return false; return false;
} }
public boolean testPermissionSilent(CommandSender target, String permission) { public boolean testPermissionSilent(CommandSender target, String permission) {
if (!super.testPermissionSilent(target)) { if (!super.testPermissionSilent(target)) {
return false; return false;
} }
for (String p : permission.split(";")) for (String p : permission.split(";"))
if (target.hasPermission(p)) if (target.hasPermission(p))
return true; return true;
return false; return false;
} }
@Override @Override
public boolean execute(CommandSender sender, String commandLabel, String[] args) { public boolean execute(CommandSender sender, String commandLabel, String[] args) {
if (!testPermission(sender)) if (!testPermission(sender))
return true; return true;
if (args.length == 0) { if (args.length == 0) {
sender.sendMessage(ChatColor.YELLOW + "Please specify action"); sender.sendMessage(ChatColor.YELLOW + "Please specify action");
sender.sendMessage(ChatColor.AQUA + usageMessage); sender.sendMessage(ChatColor.AQUA + usageMessage);
return true; return true;
} }
String action = args[0]; String action = args[0];
if ("check".equals(action)) { if ("check".equals(action)) {
if (!testPermission(sender, CHECK)) if (!testPermission(sender, CHECK))
return true; return true;
sender.sendMessage(ChatColor.GREEN + "Initiated version check..."); sender.sendMessage(ChatColor.GREEN + "Initiated version check...");
KVersionRetriever.startServer(new CommandSenderUpdateCallback(sender), false); KVersionRetriever.startServer(new CommandSenderUpdateCallback(sender), false);
} else if ("update".equals(action)) { } else if ("update".equals(action)) {
KCauldronUpdater.initUpdate(sender, args.length > 1 ? args[1] : null); KCauldronUpdater.initUpdate(sender, args.length > 1 ? args[1] : null);
} else if ("tps".equals(action)) { } else if ("tps".equals(action)) {
if (!testPermission(sender, TPS)) if (!testPermission(sender, TPS))
return true; return true;
World currentWorld = null; World currentWorld = null;
if (sender instanceof CraftPlayer) { if (sender instanceof CraftPlayer) {
currentWorld = ((CraftPlayer) sender).getWorld(); currentWorld = ((CraftPlayer) sender).getWorld();
} }
sender.sendMessage(ChatColor.DARK_BLUE + "---------------------------------------"); sender.sendMessage(ChatColor.DARK_BLUE + "---------------------------------------");
final MinecraftServer server = MinecraftServer.getServer(); final MinecraftServer server = MinecraftServer.getServer();
for (World world : server.server.getWorlds()) { for (World world : server.server.getWorlds()) {
if (world instanceof CraftWorld) { if (world instanceof CraftWorld) {
boolean current = currentWorld != null && currentWorld == world; boolean current = currentWorld != null && currentWorld == world;
net.minecraft.world.World mcWorld = ((CraftWorld) world).getHandle(); net.minecraft.world.World mcWorld = ((CraftWorld) world).getHandle();
String bukkitName = world.getName(); String bukkitName = world.getName();
int dimensionId = mcWorld.provider.dimensionId; int dimensionId = mcWorld.provider.dimensionId;
String name = mcWorld.provider.getDimensionName(); String name = mcWorld.provider.getDimensionName();
String displayName = name.equals(bukkitName) ? name : String.format("%s | %s", name, bukkitName); String displayName = name.equals(bukkitName) ? name : String.format("%s | %s", name, bukkitName);
double worldTickTime = mean(server.worldTickTimes.get(dimensionId)) * 1.0E-6D; double worldTickTime = mean(server.worldTickTimes.get(dimensionId)) * 1.0E-6D;
double worldTPS = Math.min(1000.0 / worldTickTime, 20); double worldTPS = Math.min(1000.0 / worldTickTime, 20);
sender.sendMessage(String.format("%s[%d] %s%s %s- %s%.2fms / %.2ftps", ChatColor.GOLD, dimensionId, sender.sendMessage(String.format("%s[%d] %s%s %s- %s%.2fms / %.2ftps", ChatColor.GOLD, dimensionId,
current ? ChatColor.GREEN : ChatColor.YELLOW, displayName, ChatColor.RESET, ChatColor.DARK_RED, worldTickTime, current ? ChatColor.GREEN : ChatColor.YELLOW, displayName, ChatColor.RESET, ChatColor.DARK_RED, worldTickTime,
worldTPS)); worldTPS));
} }
} }
double meanTickTime = mean(server.tickTimeArray) * 1.0E-6D; double meanTickTime = mean(server.tickTimeArray) * 1.0E-6D;
double meanTPS = Math.min(1000.0 / meanTickTime, 20); double meanTPS = Math.min(1000.0 / meanTickTime, 20);
sender.sendMessage(String.format("%sOverall - %s%s%.2fms / %.2ftps", ChatColor.BLUE, ChatColor.RESET, sender.sendMessage(String.format("%sOverall - %s%s%.2fms / %.2ftps", ChatColor.BLUE, ChatColor.RESET,
ChatColor.DARK_RED, meanTickTime, meanTPS)); ChatColor.DARK_RED, meanTickTime, meanTPS));
} else if ("restart".equals(action)) { } else if ("restart".equals(action)) {
if (!testPermission(sender, RESTART)) if (!testPermission(sender, RESTART))
return true; return true;
KCauldron.restart(); KCauldron.restart();
} else { } else {
sender.sendMessage(ChatColor.RED + "Unknown action"); sender.sendMessage(ChatColor.RED + "Unknown action");
} }
return true; return true;
} }
private static final long mean(long[] array) { private static final long mean(long[] array) {
long r = 0; long r = 0;
for (long i : array) for (long i : array)
r += i; r += i;
return r / array.length; return r / array.length;
} }
} }

View File

@ -22,6 +22,7 @@ import com.mojang.authlib.GameProfile;
import net.minecraft.entity.EntityTracker; import net.minecraft.entity.EntityTracker;
import net.minecraft.entity.EntityTrackerEntry; import net.minecraft.entity.EntityTrackerEntry;
import net.minecraft.entity.SharedMonsterAttributes;
import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.network.play.server.S23PacketBlockChange; import net.minecraft.network.play.server.S23PacketBlockChange;
import net.minecraft.network.play.server.S33PacketUpdateSign; import net.minecraft.network.play.server.S33PacketUpdateSign;
@ -79,6 +80,11 @@ public class CraftPlayer extends CraftHumanEntity implements Player {
super(server, entity); super(server, entity);
firstPlayed = System.currentTimeMillis(); firstPlayed = System.currentTimeMillis();
double maxHealth = entity.getEntityAttribute(SharedMonsterAttributes.maxHealth).getBaseValue();
if (maxHealth != health) {
healthScale = maxHealth;
scaledHealth = true;
}
} }
public GameProfile getProfile() { public GameProfile getProfile() {