mirror of
https://github.com/barkeser2002/CatServer.git
synced 2026-09-25 02:20:01 +03:00
260 lines
11 KiB
Diff
260 lines
11 KiB
Diff
--- ../src-base/minecraft/net/minecraft/village/Village.java
|
|
+++ ../src-work/minecraft/net/minecraft/village/Village.java
|
|
@@ -26,7 +26,7 @@
|
|
import net.minecraft.util.math.Vec3d;
|
|
import net.minecraft.world.World;
|
|
|
|
-public class Village
|
|
+public class Village implements net.minecraftforge.common.capabilities.ICapabilitySerializable<NBTTagCompound>
|
|
{
|
|
private World world;
|
|
private final List<VillageDoorInfo> villageDoorInfoList = Lists.<VillageDoorInfo>newArrayList();
|
|
@@ -37,17 +37,19 @@
|
|
private int tickCounter;
|
|
private int numVillagers;
|
|
private int noBreedTicks;
|
|
- private final Map<String, Integer> playerReputation = Maps.<String, Integer>newHashMap();
|
|
- private final List<Village.VillageAggressor> villageAgressors = Lists.<Village.VillageAggressor>newArrayList();
|
|
+ private final Map<UUID, Integer> playerReputation = Maps.<UUID, Integer>newHashMap();
|
|
+ private final List<VillageAggressor> villageAgressors = Lists.<VillageAggressor>newArrayList();
|
|
private int numIronGolems;
|
|
|
|
public Village()
|
|
{
|
|
+ this.capabilities = net.minecraftforge.event.ForgeEventFactory.gatherCapabilities(this);
|
|
}
|
|
|
|
public Village(World worldIn)
|
|
{
|
|
this.world = worldIn;
|
|
+ this.capabilities = net.minecraftforge.event.ForgeEventFactory.gatherCapabilities(this);
|
|
}
|
|
|
|
public void setWorld(World worldIn)
|
|
@@ -81,7 +83,7 @@
|
|
{
|
|
EntityIronGolem entityirongolem = new EntityIronGolem(this.world);
|
|
entityirongolem.setPosition(vec3d.x, vec3d.y, vec3d.z);
|
|
- this.world.spawnEntity(entityirongolem);
|
|
+ this.world.addEntity(entityirongolem, org.bukkit.event.entity.CreatureSpawnEvent.SpawnReason.VILLAGE_DEFENSE);
|
|
++this.numIronGolems;
|
|
}
|
|
}
|
|
@@ -272,7 +274,7 @@
|
|
|
|
public void addOrRenewAgressor(EntityLivingBase entitylivingbaseIn)
|
|
{
|
|
- for (Village.VillageAggressor village$villageaggressor : this.villageAgressors)
|
|
+ for (VillageAggressor village$villageaggressor : this.villageAgressors)
|
|
{
|
|
if (village$villageaggressor.agressor == entitylivingbaseIn)
|
|
{
|
|
@@ -281,18 +283,18 @@
|
|
}
|
|
}
|
|
|
|
- this.villageAgressors.add(new Village.VillageAggressor(entitylivingbaseIn, this.tickCounter));
|
|
+ this.villageAgressors.add(new VillageAggressor(entitylivingbaseIn, this.tickCounter));
|
|
}
|
|
|
|
@Nullable
|
|
public EntityLivingBase findNearestVillageAggressor(EntityLivingBase entitylivingbaseIn)
|
|
{
|
|
double d0 = Double.MAX_VALUE;
|
|
- Village.VillageAggressor village$villageaggressor = null;
|
|
+ VillageAggressor village$villageaggressor = null;
|
|
|
|
for (int i = 0; i < this.villageAgressors.size(); ++i)
|
|
{
|
|
- Village.VillageAggressor village$villageaggressor1 = this.villageAgressors.get(i);
|
|
+ VillageAggressor village$villageaggressor1 = this.villageAgressors.get(i);
|
|
double d1 = village$villageaggressor1.agressor.getDistanceSq(entitylivingbaseIn);
|
|
|
|
if (d1 <= d0)
|
|
@@ -310,11 +312,11 @@
|
|
double d0 = Double.MAX_VALUE;
|
|
EntityPlayer entityplayer = null;
|
|
|
|
- for (String s : this.playerReputation.keySet())
|
|
+ for (UUID s : this.playerReputation.keySet())
|
|
{
|
|
if (this.isPlayerReputationTooLow(s))
|
|
{
|
|
- EntityPlayer entityplayer1 = this.world.getPlayerEntityByName(s);
|
|
+ EntityPlayer entityplayer1 = this.world.getPlayerEntityByUUID(s);
|
|
|
|
if (entityplayer1 != null)
|
|
{
|
|
@@ -334,11 +336,11 @@
|
|
|
|
private void removeDeadAndOldAgressors()
|
|
{
|
|
- Iterator<Village.VillageAggressor> iterator = this.villageAgressors.iterator();
|
|
+ Iterator<VillageAggressor> iterator = this.villageAgressors.iterator();
|
|
|
|
while (iterator.hasNext())
|
|
{
|
|
- Village.VillageAggressor village$villageaggressor = iterator.next();
|
|
+ VillageAggressor village$villageaggressor = iterator.next();
|
|
|
|
if (!village$villageaggressor.agressor.isEntityAlive() || Math.abs(this.tickCounter - village$villageaggressor.agressionTime) > 300)
|
|
{
|
|
@@ -362,6 +364,7 @@
|
|
villagedoorinfo.resetDoorOpeningRestrictionCounter();
|
|
}
|
|
|
|
+ if (world.isBlockLoaded(villagedoorinfo.getDoorBlockPos())) // Forge: check that the door block is loaded to avoid loading chunks
|
|
if (!this.isWoodDoor(villagedoorinfo.getDoorBlockPos()) || Math.abs(this.tickCounter - villagedoorinfo.getLastActivityTimestamp()) > 1200)
|
|
{
|
|
this.centerHelper = this.centerHelper.subtract(villagedoorinfo.getDoorBlockPos());
|
|
@@ -415,25 +418,51 @@
|
|
}
|
|
}
|
|
|
|
+ @Deprecated //Hasn't worked since 1.9, use UUID version below.
|
|
public int getPlayerReputation(String playerName)
|
|
{
|
|
+ return this.getPlayerReputation(findUUID(playerName));
|
|
+ }
|
|
+
|
|
+ public int getPlayerReputation(UUID playerName)
|
|
+ {
|
|
Integer integer = this.playerReputation.get(playerName);
|
|
return integer == null ? 0 : integer.intValue();
|
|
}
|
|
|
|
+ private UUID findUUID(String name)
|
|
+ {
|
|
+ if (this.world == null || this.world.getMinecraftServer() == null)
|
|
+ return EntityPlayer.getOfflineUUID(name);
|
|
+ GameProfile profile = this.world.getMinecraftServer().getPlayerProfileCache().getGameProfileForUsername(name);
|
|
+ return profile == null ? EntityPlayer.getOfflineUUID(name) : profile.getId();
|
|
+ }
|
|
+
|
|
+ @Deprecated //Hasn't worked since 1.9, use UUID version below.
|
|
public int modifyPlayerReputation(String playerName, int reputation)
|
|
{
|
|
+ return this.modifyPlayerReputation(findUUID(playerName), reputation);
|
|
+ }
|
|
+
|
|
+ public int modifyPlayerReputation(UUID playerName, int reputation)
|
|
+ {
|
|
int i = this.getPlayerReputation(playerName);
|
|
int j = MathHelper.clamp(i + reputation, -30, 10);
|
|
this.playerReputation.put(playerName, Integer.valueOf(j));
|
|
return j;
|
|
}
|
|
|
|
+ @Deprecated //Hasn't worked since 1.9, use UUID version below.
|
|
public boolean isPlayerReputationTooLow(String playerName)
|
|
{
|
|
- return this.getPlayerReputation(playerName) <= -15;
|
|
+ return this.isPlayerReputationTooLow(findUUID(playerName));
|
|
}
|
|
|
|
+ public boolean isPlayerReputationTooLow(UUID uuid)
|
|
+ {
|
|
+ return this.getPlayerReputation(uuid) <= -15;
|
|
+ }
|
|
+
|
|
public void readVillageDataFromNBT(NBTTagCompound compound)
|
|
{
|
|
this.numVillagers = compound.getInteger("PopSize");
|
|
@@ -459,21 +488,17 @@
|
|
{
|
|
NBTTagCompound nbttagcompound1 = nbttaglist1.getCompoundTagAt(j);
|
|
|
|
- if (nbttagcompound1.hasKey("UUID") && this.world != null && this.world.getMinecraftServer() != null)
|
|
+ if (nbttagcompound1.hasKey("UUID"))
|
|
{
|
|
- PlayerProfileCache playerprofilecache = this.world.getMinecraftServer().getPlayerProfileCache();
|
|
- GameProfile gameprofile = playerprofilecache.getProfileByUUID(UUID.fromString(nbttagcompound1.getString("UUID")));
|
|
-
|
|
- if (gameprofile != null)
|
|
- {
|
|
- this.playerReputation.put(gameprofile.getName(), Integer.valueOf(nbttagcompound1.getInteger("S")));
|
|
- }
|
|
+ this.playerReputation.put(UUID.fromString(nbttagcompound1.getString("UUID")), Integer.valueOf(nbttagcompound1.getInteger("S")));
|
|
}
|
|
else
|
|
{
|
|
- this.playerReputation.put(nbttagcompound1.getString("Name"), Integer.valueOf(nbttagcompound1.getInteger("S")));
|
|
+ //World is never set here, so this will always be offline UUIDs, sadly there is no way to convert this.
|
|
+ this.playerReputation.put(findUUID(nbttagcompound1.getString("Name")), Integer.valueOf(nbttagcompound1.getInteger("S")));
|
|
}
|
|
}
|
|
+ if (this.capabilities != null && compound.hasKey("ForgeCaps")) this.capabilities.deserializeNBT(compound.getCompoundTag("ForgeCaps"));
|
|
}
|
|
|
|
public void writeVillageDataToNBT(NBTTagCompound compound)
|
|
@@ -507,18 +532,14 @@
|
|
compound.setTag("Doors", nbttaglist);
|
|
NBTTagList nbttaglist1 = new NBTTagList();
|
|
|
|
- for (String s : this.playerReputation.keySet())
|
|
+ for (UUID s : this.playerReputation.keySet())
|
|
{
|
|
NBTTagCompound nbttagcompound1 = new NBTTagCompound();
|
|
- PlayerProfileCache playerprofilecache = this.world.getMinecraftServer().getPlayerProfileCache();
|
|
|
|
try
|
|
{
|
|
- GameProfile gameprofile = playerprofilecache.getGameProfileForUsername(s);
|
|
-
|
|
- if (gameprofile != null)
|
|
{
|
|
- nbttagcompound1.setString("UUID", gameprofile.getId().toString());
|
|
+ nbttagcompound1.setString("UUID", s.toString());
|
|
nbttagcompound1.setInteger("S", ((Integer)this.playerReputation.get(s)).intValue());
|
|
nbttaglist1.appendTag(nbttagcompound1);
|
|
}
|
|
@@ -530,6 +551,7 @@
|
|
}
|
|
|
|
compound.setTag("Players", nbttaglist1);
|
|
+ if (this.capabilities != null) compound.setTag("ForgeCaps", this.capabilities.serializeNBT());
|
|
}
|
|
|
|
public void endMatingSeason()
|
|
@@ -544,7 +566,7 @@
|
|
|
|
public void setDefaultPlayerReputation(int defaultReputation)
|
|
{
|
|
- for (String s : this.playerReputation.keySet())
|
|
+ for (UUID s : this.playerReputation.keySet())
|
|
{
|
|
this.modifyPlayerReputation(s, defaultReputation);
|
|
}
|
|
@@ -561,4 +583,31 @@
|
|
this.agressionTime = agressionTimeIn;
|
|
}
|
|
}
|
|
+
|
|
+ /* ======================================== FORGE START =====================================*/
|
|
+ private net.minecraftforge.common.capabilities.CapabilityDispatcher capabilities;
|
|
+ public boolean hasCapability(net.minecraftforge.common.capabilities.Capability<?> capability, @Nullable EnumFacing facing)
|
|
+ {
|
|
+ return capabilities == null ? false : capabilities.hasCapability(capability, facing);
|
|
+ }
|
|
+
|
|
+ @Nullable
|
|
+ public <T> T getCapability(net.minecraftforge.common.capabilities.Capability<T> capability, @Nullable EnumFacing facing)
|
|
+ {
|
|
+ return capabilities == null ? null : capabilities.getCapability(capability, facing);
|
|
+ }
|
|
+
|
|
+ public void deserializeNBT(NBTTagCompound nbt)
|
|
+ {
|
|
+ this.readVillageDataFromNBT(nbt);;
|
|
+ }
|
|
+
|
|
+ public NBTTagCompound serializeNBT()
|
|
+ {
|
|
+ NBTTagCompound ret = new NBTTagCompound();
|
|
+ this.writeVillageDataToNBT(ret);
|
|
+ return ret;
|
|
+ }
|
|
+
|
|
+ /* ========================================= FORGE END ======================================*/
|
|
}
|