base mod created
This commit is contained in:
@@ -0,0 +1,183 @@
|
||||
package net.minecraft.village;
|
||||
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
public class MerchantRecipe
|
||||
{
|
||||
/** Item the Villager buys. */
|
||||
private ItemStack itemToBuy;
|
||||
/** Second Item the Villager buys. */
|
||||
private ItemStack secondItemToBuy;
|
||||
/** Item the Villager sells. */
|
||||
private ItemStack itemToSell;
|
||||
/** Saves how much has been tool used when put into to slot to be enchanted. */
|
||||
private int toolUses;
|
||||
/** Maximum times this trade can be used. */
|
||||
private int maxTradeUses;
|
||||
private boolean rewardsExp;
|
||||
|
||||
public MerchantRecipe(NBTTagCompound tagCompound)
|
||||
{
|
||||
this.itemToBuy = ItemStack.EMPTY;
|
||||
this.secondItemToBuy = ItemStack.EMPTY;
|
||||
this.itemToSell = ItemStack.EMPTY;
|
||||
this.readFromTags(tagCompound);
|
||||
}
|
||||
|
||||
public MerchantRecipe(ItemStack buy1, ItemStack buy2, ItemStack sell)
|
||||
{
|
||||
this(buy1, buy2, sell, 0, 7);
|
||||
}
|
||||
|
||||
public MerchantRecipe(ItemStack buy1, ItemStack buy2, ItemStack sell, int toolUsesIn, int maxTradeUsesIn)
|
||||
{
|
||||
this.itemToBuy = ItemStack.EMPTY;
|
||||
this.secondItemToBuy = ItemStack.EMPTY;
|
||||
this.itemToSell = ItemStack.EMPTY;
|
||||
this.itemToBuy = buy1;
|
||||
this.secondItemToBuy = buy2;
|
||||
this.itemToSell = sell;
|
||||
this.toolUses = toolUsesIn;
|
||||
this.maxTradeUses = maxTradeUsesIn;
|
||||
this.rewardsExp = true;
|
||||
}
|
||||
|
||||
public MerchantRecipe(ItemStack buy1, ItemStack sell)
|
||||
{
|
||||
this(buy1, ItemStack.EMPTY, sell);
|
||||
}
|
||||
|
||||
public MerchantRecipe(ItemStack buy1, Item sellItem)
|
||||
{
|
||||
this(buy1, new ItemStack(sellItem));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the itemToBuy.
|
||||
*/
|
||||
public ItemStack getItemToBuy()
|
||||
{
|
||||
return this.itemToBuy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets secondItemToBuy.
|
||||
*/
|
||||
public ItemStack getSecondItemToBuy()
|
||||
{
|
||||
return this.secondItemToBuy;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets if Villager has secondItemToBuy.
|
||||
*/
|
||||
public boolean hasSecondItemToBuy()
|
||||
{
|
||||
return !this.secondItemToBuy.isEmpty();
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets itemToSell.
|
||||
*/
|
||||
public ItemStack getItemToSell()
|
||||
{
|
||||
return this.itemToSell;
|
||||
}
|
||||
|
||||
public int getToolUses()
|
||||
{
|
||||
return this.toolUses;
|
||||
}
|
||||
|
||||
public int getMaxTradeUses()
|
||||
{
|
||||
return this.maxTradeUses;
|
||||
}
|
||||
|
||||
public void incrementToolUses()
|
||||
{
|
||||
++this.toolUses;
|
||||
}
|
||||
|
||||
public void increaseMaxTradeUses(int increment)
|
||||
{
|
||||
this.maxTradeUses += increment;
|
||||
}
|
||||
|
||||
public boolean isRecipeDisabled()
|
||||
{
|
||||
return this.toolUses >= this.maxTradeUses;
|
||||
}
|
||||
|
||||
/**
|
||||
* Compensates {@link net.minecraft.village.MerchantRecipe#toolUses toolUses} with {@link
|
||||
* net.minecraft.village.MerchantRecipe#maxTradeUses maxTradeUses}
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void compensateToolUses()
|
||||
{
|
||||
this.toolUses = this.maxTradeUses;
|
||||
}
|
||||
|
||||
public boolean getRewardsExp()
|
||||
{
|
||||
return this.rewardsExp;
|
||||
}
|
||||
|
||||
public void readFromTags(NBTTagCompound tagCompound)
|
||||
{
|
||||
NBTTagCompound nbttagcompound = tagCompound.getCompoundTag("buy");
|
||||
this.itemToBuy = new ItemStack(nbttagcompound);
|
||||
NBTTagCompound nbttagcompound1 = tagCompound.getCompoundTag("sell");
|
||||
this.itemToSell = new ItemStack(nbttagcompound1);
|
||||
|
||||
if (tagCompound.hasKey("buyB", 10))
|
||||
{
|
||||
this.secondItemToBuy = new ItemStack(tagCompound.getCompoundTag("buyB"));
|
||||
}
|
||||
|
||||
if (tagCompound.hasKey("uses", 99))
|
||||
{
|
||||
this.toolUses = tagCompound.getInteger("uses");
|
||||
}
|
||||
|
||||
if (tagCompound.hasKey("maxUses", 99))
|
||||
{
|
||||
this.maxTradeUses = tagCompound.getInteger("maxUses");
|
||||
}
|
||||
else
|
||||
{
|
||||
this.maxTradeUses = 7;
|
||||
}
|
||||
|
||||
if (tagCompound.hasKey("rewardExp", 1))
|
||||
{
|
||||
this.rewardsExp = tagCompound.getBoolean("rewardExp");
|
||||
}
|
||||
else
|
||||
{
|
||||
this.rewardsExp = true;
|
||||
}
|
||||
}
|
||||
|
||||
public NBTTagCompound writeToTags()
|
||||
{
|
||||
NBTTagCompound nbttagcompound = new NBTTagCompound();
|
||||
nbttagcompound.setTag("buy", this.itemToBuy.writeToNBT(new NBTTagCompound()));
|
||||
nbttagcompound.setTag("sell", this.itemToSell.writeToNBT(new NBTTagCompound()));
|
||||
|
||||
if (!this.secondItemToBuy.isEmpty())
|
||||
{
|
||||
nbttagcompound.setTag("buyB", this.secondItemToBuy.writeToNBT(new NBTTagCompound()));
|
||||
}
|
||||
|
||||
nbttagcompound.setInteger("uses", this.toolUses);
|
||||
nbttagcompound.setInteger("maxUses", this.maxTradeUses);
|
||||
nbttagcompound.setBoolean("rewardExp", this.rewardsExp);
|
||||
return nbttagcompound;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,138 @@
|
||||
package net.minecraft.village;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.nbt.NBTUtil;
|
||||
import net.minecraft.network.PacketBuffer;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
public class MerchantRecipeList extends ArrayList<MerchantRecipe>
|
||||
{
|
||||
public MerchantRecipeList()
|
||||
{
|
||||
}
|
||||
|
||||
public MerchantRecipeList(NBTTagCompound compound)
|
||||
{
|
||||
this.readRecipiesFromTags(compound);
|
||||
}
|
||||
|
||||
/**
|
||||
* can par1,par2 be used to in crafting recipe par3
|
||||
*/
|
||||
@Nullable
|
||||
public MerchantRecipe canRecipeBeUsed(ItemStack stack0, ItemStack stack1, int index)
|
||||
{
|
||||
if (index > 0 && index < this.size())
|
||||
{
|
||||
MerchantRecipe merchantrecipe1 = (MerchantRecipe)this.get(index);
|
||||
return !this.areItemStacksExactlyEqual(stack0, merchantrecipe1.getItemToBuy()) || (!stack1.isEmpty() || merchantrecipe1.hasSecondItemToBuy()) && (!merchantrecipe1.hasSecondItemToBuy() || !this.areItemStacksExactlyEqual(stack1, merchantrecipe1.getSecondItemToBuy())) || stack0.getCount() < merchantrecipe1.getItemToBuy().getCount() || merchantrecipe1.hasSecondItemToBuy() && stack1.getCount() < merchantrecipe1.getSecondItemToBuy().getCount() ? null : merchantrecipe1;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (int i = 0; i < this.size(); ++i)
|
||||
{
|
||||
MerchantRecipe merchantrecipe = (MerchantRecipe)this.get(i);
|
||||
|
||||
if (this.areItemStacksExactlyEqual(stack0, merchantrecipe.getItemToBuy()) && stack0.getCount() >= merchantrecipe.getItemToBuy().getCount() && (!merchantrecipe.hasSecondItemToBuy() && stack1.isEmpty() || merchantrecipe.hasSecondItemToBuy() && this.areItemStacksExactlyEqual(stack1, merchantrecipe.getSecondItemToBuy()) && stack1.getCount() >= merchantrecipe.getSecondItemToBuy().getCount()))
|
||||
{
|
||||
return merchantrecipe;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean areItemStacksExactlyEqual(ItemStack stack1, ItemStack stack2)
|
||||
{
|
||||
return ItemStack.areItemsEqual(stack1, stack2) && (!stack2.hasTagCompound() || stack1.hasTagCompound() && NBTUtil.areNBTEquals(stack2.getTagCompound(), stack1.getTagCompound(), false));
|
||||
}
|
||||
|
||||
public void writeToBuf(PacketBuffer buffer)
|
||||
{
|
||||
buffer.writeByte((byte)(this.size() & 255));
|
||||
|
||||
for (int i = 0; i < this.size(); ++i)
|
||||
{
|
||||
MerchantRecipe merchantrecipe = (MerchantRecipe)this.get(i);
|
||||
buffer.writeItemStack(merchantrecipe.getItemToBuy());
|
||||
buffer.writeItemStack(merchantrecipe.getItemToSell());
|
||||
ItemStack itemstack = merchantrecipe.getSecondItemToBuy();
|
||||
buffer.writeBoolean(!itemstack.isEmpty());
|
||||
|
||||
if (!itemstack.isEmpty())
|
||||
{
|
||||
buffer.writeItemStack(itemstack);
|
||||
}
|
||||
|
||||
buffer.writeBoolean(merchantrecipe.isRecipeDisabled());
|
||||
buffer.writeInt(merchantrecipe.getToolUses());
|
||||
buffer.writeInt(merchantrecipe.getMaxTradeUses());
|
||||
}
|
||||
}
|
||||
|
||||
public void readRecipiesFromTags(NBTTagCompound compound)
|
||||
{
|
||||
NBTTagList nbttaglist = compound.getTagList("Recipes", 10);
|
||||
|
||||
for (int i = 0; i < nbttaglist.tagCount(); ++i)
|
||||
{
|
||||
NBTTagCompound nbttagcompound = nbttaglist.getCompoundTagAt(i);
|
||||
this.add(new MerchantRecipe(nbttagcompound));
|
||||
}
|
||||
}
|
||||
|
||||
public NBTTagCompound getRecipiesAsTags()
|
||||
{
|
||||
NBTTagCompound nbttagcompound = new NBTTagCompound();
|
||||
NBTTagList nbttaglist = new NBTTagList();
|
||||
|
||||
for (int i = 0; i < this.size(); ++i)
|
||||
{
|
||||
MerchantRecipe merchantrecipe = (MerchantRecipe)this.get(i);
|
||||
nbttaglist.appendTag(merchantrecipe.writeToTags());
|
||||
}
|
||||
|
||||
nbttagcompound.setTag("Recipes", nbttaglist);
|
||||
return nbttagcompound;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public static MerchantRecipeList readFromBuf(PacketBuffer buffer) throws IOException
|
||||
{
|
||||
MerchantRecipeList merchantrecipelist = new MerchantRecipeList();
|
||||
int i = buffer.readByte() & 255;
|
||||
|
||||
for (int j = 0; j < i; ++j)
|
||||
{
|
||||
ItemStack itemstack = buffer.readItemStack();
|
||||
ItemStack itemstack1 = buffer.readItemStack();
|
||||
ItemStack itemstack2 = ItemStack.EMPTY;
|
||||
|
||||
if (buffer.readBoolean())
|
||||
{
|
||||
itemstack2 = buffer.readItemStack();
|
||||
}
|
||||
|
||||
boolean flag = buffer.readBoolean();
|
||||
int k = buffer.readInt();
|
||||
int l = buffer.readInt();
|
||||
MerchantRecipe merchantrecipe = new MerchantRecipe(itemstack, itemstack2, itemstack1, k, l);
|
||||
|
||||
if (flag)
|
||||
{
|
||||
merchantrecipe.compensateToolUses();
|
||||
}
|
||||
|
||||
merchantrecipelist.add(merchantrecipe);
|
||||
}
|
||||
|
||||
return merchantrecipelist;
|
||||
}
|
||||
}
|
||||
669
build/tmp/recompileMc/sources/net/minecraft/village/Village.java
Normal file
669
build/tmp/recompileMc/sources/net/minecraft/village/Village.java
Normal file
@@ -0,0 +1,669 @@
|
||||
package net.minecraft.village;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import com.google.common.collect.Maps;
|
||||
import com.mojang.authlib.GameProfile;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.UUID;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockDoor;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
import net.minecraft.entity.monster.EntityIronGolem;
|
||||
import net.minecraft.entity.passive.EntityVillager;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.server.management.PlayerProfileCache;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.AxisAlignedBB;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class Village implements net.minecraftforge.common.capabilities.ICapabilitySerializable<NBTTagCompound>
|
||||
{
|
||||
private World world;
|
||||
/** list of VillageDoorInfo objects */
|
||||
private final List<VillageDoorInfo> villageDoorInfoList = Lists.<VillageDoorInfo>newArrayList();
|
||||
/**
|
||||
* This is the sum of all door coordinates and used to calculate the actual village center by dividing by the number
|
||||
* of doors.
|
||||
*/
|
||||
private BlockPos centerHelper = BlockPos.ORIGIN;
|
||||
/** This is the actual village center. */
|
||||
private BlockPos center = BlockPos.ORIGIN;
|
||||
private int villageRadius;
|
||||
private int lastAddDoorTimestamp;
|
||||
private int tickCounter;
|
||||
private int numVillagers;
|
||||
/** Timestamp of tick count when villager last bred */
|
||||
private int noBreedTicks;
|
||||
/** List of player reputations with this village */
|
||||
private final Map<UUID, Integer> playerReputation = Maps.<UUID, Integer>newHashMap();
|
||||
private final List<Village.VillageAggressor> villageAgressors = Lists.<Village.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)
|
||||
{
|
||||
this.world = worldIn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Called periodically by VillageCollection
|
||||
*/
|
||||
public void tick(int tickCounterIn)
|
||||
{
|
||||
this.tickCounter = tickCounterIn;
|
||||
this.removeDeadAndOutOfRangeDoors();
|
||||
this.removeDeadAndOldAgressors();
|
||||
|
||||
if (tickCounterIn % 20 == 0)
|
||||
{
|
||||
this.updateNumVillagers();
|
||||
}
|
||||
|
||||
if (tickCounterIn % 30 == 0)
|
||||
{
|
||||
this.updateNumIronGolems();
|
||||
}
|
||||
|
||||
int i = this.numVillagers / 10;
|
||||
|
||||
if (this.numIronGolems < i && this.villageDoorInfoList.size() > 20 && this.world.rand.nextInt(7000) == 0)
|
||||
{
|
||||
Vec3d vec3d = this.findRandomSpawnPos(this.center, 2, 4, 2);
|
||||
|
||||
if (vec3d != null)
|
||||
{
|
||||
EntityIronGolem entityirongolem = new EntityIronGolem(this.world);
|
||||
entityirongolem.setPosition(vec3d.x, vec3d.y, vec3d.z);
|
||||
this.world.spawnEntity(entityirongolem);
|
||||
++this.numIronGolems;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private Vec3d findRandomSpawnPos(BlockPos pos, int x, int y, int z)
|
||||
{
|
||||
for (int i = 0; i < 10; ++i)
|
||||
{
|
||||
BlockPos blockpos = pos.add(this.world.rand.nextInt(16) - 8, this.world.rand.nextInt(6) - 3, this.world.rand.nextInt(16) - 8);
|
||||
|
||||
if (this.isBlockPosWithinSqVillageRadius(blockpos) && this.isAreaClearAround(new BlockPos(x, y, z), blockpos))
|
||||
{
|
||||
return new Vec3d((double)blockpos.getX(), (double)blockpos.getY(), (double)blockpos.getZ());
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks to see if the volume around blockLocation is clear and able to fit blockSize
|
||||
*/
|
||||
private boolean isAreaClearAround(BlockPos blockSize, BlockPos blockLocation)
|
||||
{
|
||||
if (!this.world.getBlockState(blockLocation.down()).isTopSolid())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
int i = blockLocation.getX() - blockSize.getX() / 2;
|
||||
int j = blockLocation.getZ() - blockSize.getZ() / 2;
|
||||
|
||||
for (int k = i; k < i + blockSize.getX(); ++k)
|
||||
{
|
||||
for (int l = blockLocation.getY(); l < blockLocation.getY() + blockSize.getY(); ++l)
|
||||
{
|
||||
for (int i1 = j; i1 < j + blockSize.getZ(); ++i1)
|
||||
{
|
||||
if (this.world.getBlockState(new BlockPos(k, l, i1)).isNormalCube())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
private void updateNumIronGolems()
|
||||
{
|
||||
List<EntityIronGolem> list = this.world.<EntityIronGolem>getEntitiesWithinAABB(EntityIronGolem.class, new AxisAlignedBB((double)(this.center.getX() - this.villageRadius), (double)(this.center.getY() - 4), (double)(this.center.getZ() - this.villageRadius), (double)(this.center.getX() + this.villageRadius), (double)(this.center.getY() + 4), (double)(this.center.getZ() + this.villageRadius)));
|
||||
this.numIronGolems = list.size();
|
||||
}
|
||||
|
||||
private void updateNumVillagers()
|
||||
{
|
||||
List<EntityVillager> list = this.world.<EntityVillager>getEntitiesWithinAABB(EntityVillager.class, new AxisAlignedBB((double)(this.center.getX() - this.villageRadius), (double)(this.center.getY() - 4), (double)(this.center.getZ() - this.villageRadius), (double)(this.center.getX() + this.villageRadius), (double)(this.center.getY() + 4), (double)(this.center.getZ() + this.villageRadius)));
|
||||
this.numVillagers = list.size();
|
||||
|
||||
if (this.numVillagers == 0)
|
||||
{
|
||||
this.playerReputation.clear();
|
||||
}
|
||||
}
|
||||
|
||||
public BlockPos getCenter()
|
||||
{
|
||||
return this.center;
|
||||
}
|
||||
|
||||
public int getVillageRadius()
|
||||
{
|
||||
return this.villageRadius;
|
||||
}
|
||||
|
||||
/**
|
||||
* Actually get num village door info entries, but that boils down to number of doors. Called by
|
||||
* EntityAIVillagerMate and VillageSiege
|
||||
*/
|
||||
public int getNumVillageDoors()
|
||||
{
|
||||
return this.villageDoorInfoList.size();
|
||||
}
|
||||
|
||||
public int getTicksSinceLastDoorAdding()
|
||||
{
|
||||
return this.tickCounter - this.lastAddDoorTimestamp;
|
||||
}
|
||||
|
||||
public int getNumVillagers()
|
||||
{
|
||||
return this.numVillagers;
|
||||
}
|
||||
|
||||
/**
|
||||
* Checks to see if the distance squared between this BlockPos and the center of this Village is less than this
|
||||
* Village's villageRadius squared
|
||||
*/
|
||||
public boolean isBlockPosWithinSqVillageRadius(BlockPos pos)
|
||||
{
|
||||
return this.center.distanceSq(pos) < (double)(this.villageRadius * this.villageRadius);
|
||||
}
|
||||
|
||||
/**
|
||||
* called only by class EntityAIMoveThroughVillage
|
||||
*/
|
||||
public List<VillageDoorInfo> getVillageDoorInfoList()
|
||||
{
|
||||
return this.villageDoorInfoList;
|
||||
}
|
||||
|
||||
public VillageDoorInfo getNearestDoor(BlockPos pos)
|
||||
{
|
||||
VillageDoorInfo villagedoorinfo = null;
|
||||
int i = Integer.MAX_VALUE;
|
||||
|
||||
for (VillageDoorInfo villagedoorinfo1 : this.villageDoorInfoList)
|
||||
{
|
||||
int j = villagedoorinfo1.getDistanceToDoorBlockSq(pos);
|
||||
|
||||
if (j < i)
|
||||
{
|
||||
villagedoorinfo = villagedoorinfo1;
|
||||
i = j;
|
||||
}
|
||||
}
|
||||
|
||||
return villagedoorinfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns {@link net.minecraft.village.VillageDoorInfo VillageDoorInfo} from given block position
|
||||
*/
|
||||
public VillageDoorInfo getDoorInfo(BlockPos pos)
|
||||
{
|
||||
VillageDoorInfo villagedoorinfo = null;
|
||||
int i = Integer.MAX_VALUE;
|
||||
|
||||
for (VillageDoorInfo villagedoorinfo1 : this.villageDoorInfoList)
|
||||
{
|
||||
int j = villagedoorinfo1.getDistanceToDoorBlockSq(pos);
|
||||
|
||||
if (j > 256)
|
||||
{
|
||||
j = j * 1000;
|
||||
}
|
||||
else
|
||||
{
|
||||
j = villagedoorinfo1.getDoorOpeningRestrictionCounter();
|
||||
}
|
||||
|
||||
if (j < i)
|
||||
{
|
||||
BlockPos blockpos = villagedoorinfo1.getDoorBlockPos();
|
||||
EnumFacing enumfacing = villagedoorinfo1.getInsideDirection();
|
||||
|
||||
if (this.world.getBlockState(blockpos.offset(enumfacing, 1)).getBlock().isPassable(this.world, blockpos.offset(enumfacing, 1)) && this.world.getBlockState(blockpos.offset(enumfacing, -1)).getBlock().isPassable(this.world, blockpos.offset(enumfacing, -1)) && this.world.getBlockState(blockpos.up().offset(enumfacing, 1)).getBlock().isPassable(this.world, blockpos.up().offset(enumfacing, 1)) && this.world.getBlockState(blockpos.up().offset(enumfacing, -1)).getBlock().isPassable(this.world, blockpos.up().offset(enumfacing, -1)))
|
||||
{
|
||||
villagedoorinfo = villagedoorinfo1;
|
||||
i = j;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return villagedoorinfo;
|
||||
}
|
||||
|
||||
/**
|
||||
* if door not existed in this village, null will be returned
|
||||
*/
|
||||
@Nullable
|
||||
public VillageDoorInfo getExistedDoor(BlockPos doorBlock)
|
||||
{
|
||||
if (this.center.distanceSq(doorBlock) > (double)(this.villageRadius * this.villageRadius))
|
||||
{
|
||||
return null;
|
||||
}
|
||||
else
|
||||
{
|
||||
for (VillageDoorInfo villagedoorinfo : this.villageDoorInfoList)
|
||||
{
|
||||
if (villagedoorinfo.getDoorBlockPos().getX() == doorBlock.getX() && villagedoorinfo.getDoorBlockPos().getZ() == doorBlock.getZ() && Math.abs(villagedoorinfo.getDoorBlockPos().getY() - doorBlock.getY()) <= 1)
|
||||
{
|
||||
return villagedoorinfo;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
public void addVillageDoorInfo(VillageDoorInfo doorInfo)
|
||||
{
|
||||
this.villageDoorInfoList.add(doorInfo);
|
||||
this.centerHelper = this.centerHelper.add(doorInfo.getDoorBlockPos());
|
||||
this.updateVillageRadiusAndCenter();
|
||||
this.lastAddDoorTimestamp = doorInfo.getLastActivityTimestamp();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns true, if there is not a single village door left. Called by VillageCollection
|
||||
*/
|
||||
public boolean isAnnihilated()
|
||||
{
|
||||
return this.villageDoorInfoList.isEmpty();
|
||||
}
|
||||
|
||||
public void addOrRenewAgressor(EntityLivingBase entitylivingbaseIn)
|
||||
{
|
||||
for (Village.VillageAggressor village$villageaggressor : this.villageAgressors)
|
||||
{
|
||||
if (village$villageaggressor.agressor == entitylivingbaseIn)
|
||||
{
|
||||
village$villageaggressor.agressionTime = this.tickCounter;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
this.villageAgressors.add(new Village.VillageAggressor(entitylivingbaseIn, this.tickCounter));
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public EntityLivingBase findNearestVillageAggressor(EntityLivingBase entitylivingbaseIn)
|
||||
{
|
||||
double d0 = Double.MAX_VALUE;
|
||||
Village.VillageAggressor village$villageaggressor = null;
|
||||
|
||||
for (int i = 0; i < this.villageAgressors.size(); ++i)
|
||||
{
|
||||
Village.VillageAggressor village$villageaggressor1 = this.villageAgressors.get(i);
|
||||
double d1 = village$villageaggressor1.agressor.getDistanceSq(entitylivingbaseIn);
|
||||
|
||||
if (d1 <= d0)
|
||||
{
|
||||
village$villageaggressor = village$villageaggressor1;
|
||||
d0 = d1;
|
||||
}
|
||||
}
|
||||
|
||||
return village$villageaggressor == null ? null : village$villageaggressor.agressor;
|
||||
}
|
||||
|
||||
public EntityPlayer getNearestTargetPlayer(EntityLivingBase villageDefender)
|
||||
{
|
||||
double d0 = Double.MAX_VALUE;
|
||||
EntityPlayer entityplayer = null;
|
||||
|
||||
for (UUID s : this.playerReputation.keySet())
|
||||
{
|
||||
if (this.isPlayerReputationTooLow(s))
|
||||
{
|
||||
EntityPlayer entityplayer1 = this.world.getPlayerEntityByUUID(s);
|
||||
|
||||
if (entityplayer1 != null)
|
||||
{
|
||||
double d1 = entityplayer1.getDistanceSq(villageDefender);
|
||||
|
||||
if (d1 <= d0)
|
||||
{
|
||||
entityplayer = entityplayer1;
|
||||
d0 = d1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return entityplayer;
|
||||
}
|
||||
|
||||
private void removeDeadAndOldAgressors()
|
||||
{
|
||||
Iterator<Village.VillageAggressor> iterator = this.villageAgressors.iterator();
|
||||
|
||||
while (iterator.hasNext())
|
||||
{
|
||||
Village.VillageAggressor village$villageaggressor = iterator.next();
|
||||
|
||||
if (!village$villageaggressor.agressor.isEntityAlive() || Math.abs(this.tickCounter - village$villageaggressor.agressionTime) > 300)
|
||||
{
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void removeDeadAndOutOfRangeDoors()
|
||||
{
|
||||
boolean flag = false;
|
||||
boolean flag1 = this.world.rand.nextInt(50) == 0;
|
||||
Iterator<VillageDoorInfo> iterator = this.villageDoorInfoList.iterator();
|
||||
|
||||
while (iterator.hasNext())
|
||||
{
|
||||
VillageDoorInfo villagedoorinfo = iterator.next();
|
||||
|
||||
if (flag1)
|
||||
{
|
||||
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());
|
||||
flag = true;
|
||||
villagedoorinfo.setIsDetachedFromVillageFlag(true);
|
||||
iterator.remove();
|
||||
}
|
||||
}
|
||||
|
||||
if (flag)
|
||||
{
|
||||
this.updateVillageRadiusAndCenter();
|
||||
}
|
||||
}
|
||||
|
||||
private boolean isWoodDoor(BlockPos pos)
|
||||
{
|
||||
IBlockState iblockstate = this.world.getBlockState(pos);
|
||||
Block block = iblockstate.getBlock();
|
||||
|
||||
if (block instanceof BlockDoor)
|
||||
{
|
||||
return iblockstate.getMaterial() == Material.WOOD;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
private void updateVillageRadiusAndCenter()
|
||||
{
|
||||
int i = this.villageDoorInfoList.size();
|
||||
|
||||
if (i == 0)
|
||||
{
|
||||
this.center = BlockPos.ORIGIN;
|
||||
this.villageRadius = 0;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.center = new BlockPos(this.centerHelper.getX() / i, this.centerHelper.getY() / i, this.centerHelper.getZ() / i);
|
||||
int j = 0;
|
||||
|
||||
for (VillageDoorInfo villagedoorinfo : this.villageDoorInfoList)
|
||||
{
|
||||
j = Math.max(villagedoorinfo.getDistanceToDoorBlockSq(this.center), j);
|
||||
}
|
||||
|
||||
this.villageRadius = Math.max(32, (int)Math.sqrt((double)j) + 1);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Return the village reputation for a player
|
||||
*/
|
||||
@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();
|
||||
}
|
||||
|
||||
/**
|
||||
* Modify a players reputation in the village. Use positive values to increase reputation and negative values to
|
||||
* decrease. <br>Note that a players reputation is clamped between -30 and 10
|
||||
*/
|
||||
@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;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether this player has a too low reputation with this village.
|
||||
*/
|
||||
@Deprecated //Hasn't worked since 1.9, use UUID version below.
|
||||
public boolean isPlayerReputationTooLow(String playerName)
|
||||
{
|
||||
return this.isPlayerReputationTooLow(findUUID(playerName));
|
||||
}
|
||||
|
||||
public boolean isPlayerReputationTooLow(UUID uuid)
|
||||
{
|
||||
return this.getPlayerReputation(uuid) <= -15;
|
||||
}
|
||||
|
||||
/**
|
||||
* Read this village's data from NBT.
|
||||
*/
|
||||
public void readVillageDataFromNBT(NBTTagCompound compound)
|
||||
{
|
||||
this.numVillagers = compound.getInteger("PopSize");
|
||||
this.villageRadius = compound.getInteger("Radius");
|
||||
this.numIronGolems = compound.getInteger("Golems");
|
||||
this.lastAddDoorTimestamp = compound.getInteger("Stable");
|
||||
this.tickCounter = compound.getInteger("Tick");
|
||||
this.noBreedTicks = compound.getInteger("MTick");
|
||||
this.center = new BlockPos(compound.getInteger("CX"), compound.getInteger("CY"), compound.getInteger("CZ"));
|
||||
this.centerHelper = new BlockPos(compound.getInteger("ACX"), compound.getInteger("ACY"), compound.getInteger("ACZ"));
|
||||
NBTTagList nbttaglist = compound.getTagList("Doors", 10);
|
||||
|
||||
for (int i = 0; i < nbttaglist.tagCount(); ++i)
|
||||
{
|
||||
NBTTagCompound nbttagcompound = nbttaglist.getCompoundTagAt(i);
|
||||
VillageDoorInfo villagedoorinfo = new VillageDoorInfo(new BlockPos(nbttagcompound.getInteger("X"), nbttagcompound.getInteger("Y"), nbttagcompound.getInteger("Z")), nbttagcompound.getInteger("IDX"), nbttagcompound.getInteger("IDZ"), nbttagcompound.getInteger("TS"));
|
||||
this.villageDoorInfoList.add(villagedoorinfo);
|
||||
}
|
||||
|
||||
NBTTagList nbttaglist1 = compound.getTagList("Players", 10);
|
||||
|
||||
for (int j = 0; j < nbttaglist1.tagCount(); ++j)
|
||||
{
|
||||
NBTTagCompound nbttagcompound1 = nbttaglist1.getCompoundTagAt(j);
|
||||
|
||||
if (nbttagcompound1.hasKey("UUID"))
|
||||
{
|
||||
this.playerReputation.put(UUID.fromString(nbttagcompound1.getString("UUID")), Integer.valueOf(nbttagcompound1.getInteger("S")));
|
||||
}
|
||||
else
|
||||
{
|
||||
//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"));
|
||||
}
|
||||
|
||||
/**
|
||||
* Write this village's data to NBT.
|
||||
*/
|
||||
public void writeVillageDataToNBT(NBTTagCompound compound)
|
||||
{
|
||||
compound.setInteger("PopSize", this.numVillagers);
|
||||
compound.setInteger("Radius", this.villageRadius);
|
||||
compound.setInteger("Golems", this.numIronGolems);
|
||||
compound.setInteger("Stable", this.lastAddDoorTimestamp);
|
||||
compound.setInteger("Tick", this.tickCounter);
|
||||
compound.setInteger("MTick", this.noBreedTicks);
|
||||
compound.setInteger("CX", this.center.getX());
|
||||
compound.setInteger("CY", this.center.getY());
|
||||
compound.setInteger("CZ", this.center.getZ());
|
||||
compound.setInteger("ACX", this.centerHelper.getX());
|
||||
compound.setInteger("ACY", this.centerHelper.getY());
|
||||
compound.setInteger("ACZ", this.centerHelper.getZ());
|
||||
NBTTagList nbttaglist = new NBTTagList();
|
||||
|
||||
for (VillageDoorInfo villagedoorinfo : this.villageDoorInfoList)
|
||||
{
|
||||
NBTTagCompound nbttagcompound = new NBTTagCompound();
|
||||
nbttagcompound.setInteger("X", villagedoorinfo.getDoorBlockPos().getX());
|
||||
nbttagcompound.setInteger("Y", villagedoorinfo.getDoorBlockPos().getY());
|
||||
nbttagcompound.setInteger("Z", villagedoorinfo.getDoorBlockPos().getZ());
|
||||
nbttagcompound.setInteger("IDX", villagedoorinfo.getInsideOffsetX());
|
||||
nbttagcompound.setInteger("IDZ", villagedoorinfo.getInsideOffsetZ());
|
||||
nbttagcompound.setInteger("TS", villagedoorinfo.getLastActivityTimestamp());
|
||||
nbttaglist.appendTag(nbttagcompound);
|
||||
}
|
||||
|
||||
compound.setTag("Doors", nbttaglist);
|
||||
NBTTagList nbttaglist1 = new NBTTagList();
|
||||
|
||||
for (UUID s : this.playerReputation.keySet())
|
||||
{
|
||||
NBTTagCompound nbttagcompound1 = new NBTTagCompound();
|
||||
|
||||
try
|
||||
{
|
||||
{
|
||||
nbttagcompound1.setString("UUID", s.toString());
|
||||
nbttagcompound1.setInteger("S", ((Integer)this.playerReputation.get(s)).intValue());
|
||||
nbttaglist1.appendTag(nbttagcompound1);
|
||||
}
|
||||
}
|
||||
catch (RuntimeException var9)
|
||||
{
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
compound.setTag("Players", nbttaglist1);
|
||||
if (this.capabilities != null) compound.setTag("ForgeCaps", this.capabilities.serializeNBT());
|
||||
}
|
||||
|
||||
/**
|
||||
* Prevent villager breeding for a fixed interval of time
|
||||
*/
|
||||
public void endMatingSeason()
|
||||
{
|
||||
this.noBreedTicks = this.tickCounter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Return whether villagers mating refractory period has passed
|
||||
*/
|
||||
public boolean isMatingSeason()
|
||||
{
|
||||
return this.noBreedTicks == 0 || this.tickCounter - this.noBreedTicks >= 3600;
|
||||
}
|
||||
|
||||
public void setDefaultPlayerReputation(int defaultReputation)
|
||||
{
|
||||
for (UUID s : this.playerReputation.keySet())
|
||||
{
|
||||
this.modifyPlayerReputation(s, defaultReputation);
|
||||
}
|
||||
}
|
||||
|
||||
class VillageAggressor
|
||||
{
|
||||
public EntityLivingBase agressor;
|
||||
public int agressionTime;
|
||||
|
||||
VillageAggressor(EntityLivingBase agressorIn, int agressionTimeIn)
|
||||
{
|
||||
this.agressor = agressorIn;
|
||||
this.agressionTime = agressionTimeIn;
|
||||
}
|
||||
}
|
||||
|
||||
/* ======================================== FORGE START =====================================*/
|
||||
private net.minecraftforge.common.capabilities.CapabilityDispatcher capabilities;
|
||||
public boolean hasCapability(net.minecraftforge.common.capabilities.Capability<?> capability, @Nullable net.minecraft.util.EnumFacing facing)
|
||||
{
|
||||
return capabilities == null ? false : capabilities.hasCapability(capability, facing);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public <T> T getCapability(net.minecraftforge.common.capabilities.Capability<T> capability, @Nullable net.minecraft.util.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 ======================================*/
|
||||
}
|
||||
@@ -0,0 +1,323 @@
|
||||
package net.minecraft.village;
|
||||
|
||||
import com.google.common.collect.Lists;
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.BlockDoor;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.block.state.IBlockState;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.nbt.NBTTagList;
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldProvider;
|
||||
import net.minecraft.world.storage.WorldSavedData;
|
||||
|
||||
public class VillageCollection extends WorldSavedData
|
||||
{
|
||||
private World world;
|
||||
/**
|
||||
* This is a black hole. You can add data to this list through a public interface, but you can't query that
|
||||
* information in any way and it's not used internally either.
|
||||
*/
|
||||
private final List<BlockPos> villagerPositionsList = Lists.<BlockPos>newArrayList();
|
||||
private final List<VillageDoorInfo> newDoors = Lists.<VillageDoorInfo>newArrayList();
|
||||
private final List<Village> villageList = Lists.<Village>newArrayList();
|
||||
private int tickCounter;
|
||||
|
||||
public VillageCollection(String name)
|
||||
{
|
||||
super(name);
|
||||
}
|
||||
|
||||
public VillageCollection(World worldIn)
|
||||
{
|
||||
super(fileNameForProvider(worldIn.provider));
|
||||
this.world = worldIn;
|
||||
this.markDirty();
|
||||
}
|
||||
|
||||
public void setWorldsForAll(World worldIn)
|
||||
{
|
||||
this.world = worldIn;
|
||||
|
||||
for (Village village : this.villageList)
|
||||
{
|
||||
village.setWorld(worldIn);
|
||||
}
|
||||
}
|
||||
|
||||
public void addToVillagerPositionList(BlockPos pos)
|
||||
{
|
||||
if (this.villagerPositionsList.size() <= 64)
|
||||
{
|
||||
if (!this.positionInList(pos))
|
||||
{
|
||||
this.villagerPositionsList.add(pos);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs a single tick for the village collection
|
||||
*/
|
||||
public void tick()
|
||||
{
|
||||
++this.tickCounter;
|
||||
|
||||
for (Village village : this.villageList)
|
||||
{
|
||||
village.tick(this.tickCounter);
|
||||
}
|
||||
|
||||
this.removeAnnihilatedVillages();
|
||||
this.dropOldestVillagerPosition();
|
||||
this.addNewDoorsToVillageOrCreateVillage();
|
||||
|
||||
if (this.tickCounter % 400 == 0)
|
||||
{
|
||||
this.markDirty();
|
||||
}
|
||||
}
|
||||
|
||||
private void removeAnnihilatedVillages()
|
||||
{
|
||||
Iterator<Village> iterator = this.villageList.iterator();
|
||||
|
||||
while (iterator.hasNext())
|
||||
{
|
||||
Village village = iterator.next();
|
||||
|
||||
if (village.isAnnihilated())
|
||||
{
|
||||
iterator.remove();
|
||||
this.markDirty();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Get a list of villages.
|
||||
*/
|
||||
public List<Village> getVillageList()
|
||||
{
|
||||
return this.villageList;
|
||||
}
|
||||
|
||||
public Village getNearestVillage(BlockPos doorBlock, int radius)
|
||||
{
|
||||
Village village = null;
|
||||
double d0 = 3.4028234663852886E38D;
|
||||
|
||||
for (Village village1 : this.villageList)
|
||||
{
|
||||
double d1 = village1.getCenter().distanceSq(doorBlock);
|
||||
|
||||
if (d1 < d0)
|
||||
{
|
||||
float f = (float)(radius + village1.getVillageRadius());
|
||||
|
||||
if (d1 <= (double)(f * f))
|
||||
{
|
||||
village = village1;
|
||||
d0 = d1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return village;
|
||||
}
|
||||
|
||||
private void dropOldestVillagerPosition()
|
||||
{
|
||||
if (!this.villagerPositionsList.isEmpty())
|
||||
{
|
||||
this.addDoorsAround(this.villagerPositionsList.remove(0));
|
||||
}
|
||||
}
|
||||
|
||||
private void addNewDoorsToVillageOrCreateVillage()
|
||||
{
|
||||
for (int i = 0; i < this.newDoors.size(); ++i)
|
||||
{
|
||||
VillageDoorInfo villagedoorinfo = this.newDoors.get(i);
|
||||
Village village = this.getNearestVillage(villagedoorinfo.getDoorBlockPos(), 32);
|
||||
|
||||
if (village == null)
|
||||
{
|
||||
village = new Village(this.world);
|
||||
this.villageList.add(village);
|
||||
this.markDirty();
|
||||
}
|
||||
|
||||
village.addVillageDoorInfo(villagedoorinfo);
|
||||
}
|
||||
|
||||
this.newDoors.clear();
|
||||
}
|
||||
|
||||
private void addDoorsAround(BlockPos central)
|
||||
{
|
||||
if (!this.world.isAreaLoaded(central, 16)) return; // Forge: prevent loading unloaded chunks when checking for doors
|
||||
int i = 16;
|
||||
int j = 4;
|
||||
int k = 16;
|
||||
|
||||
for (int l = -16; l < 16; ++l)
|
||||
{
|
||||
for (int i1 = -4; i1 < 4; ++i1)
|
||||
{
|
||||
for (int j1 = -16; j1 < 16; ++j1)
|
||||
{
|
||||
BlockPos blockpos = central.add(l, i1, j1);
|
||||
|
||||
if (this.isWoodDoor(blockpos))
|
||||
{
|
||||
VillageDoorInfo villagedoorinfo = this.checkDoorExistence(blockpos);
|
||||
|
||||
if (villagedoorinfo == null)
|
||||
{
|
||||
this.addToNewDoorsList(blockpos);
|
||||
}
|
||||
else
|
||||
{
|
||||
villagedoorinfo.setLastActivityTimestamp(this.tickCounter);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* returns the VillageDoorInfo if it exists in any village or in the newDoor list, otherwise returns null
|
||||
*/
|
||||
@Nullable
|
||||
private VillageDoorInfo checkDoorExistence(BlockPos doorBlock)
|
||||
{
|
||||
for (VillageDoorInfo villagedoorinfo : this.newDoors)
|
||||
{
|
||||
if (villagedoorinfo.getDoorBlockPos().getX() == doorBlock.getX() && villagedoorinfo.getDoorBlockPos().getZ() == doorBlock.getZ() && Math.abs(villagedoorinfo.getDoorBlockPos().getY() - doorBlock.getY()) <= 1)
|
||||
{
|
||||
return villagedoorinfo;
|
||||
}
|
||||
}
|
||||
|
||||
for (Village village : this.villageList)
|
||||
{
|
||||
VillageDoorInfo villagedoorinfo1 = village.getExistedDoor(doorBlock);
|
||||
|
||||
if (villagedoorinfo1 != null)
|
||||
{
|
||||
return villagedoorinfo1;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
private void addToNewDoorsList(BlockPos doorBlock)
|
||||
{
|
||||
EnumFacing enumfacing = BlockDoor.getFacing(this.world, doorBlock);
|
||||
EnumFacing enumfacing1 = enumfacing.getOpposite();
|
||||
int i = this.countBlocksCanSeeSky(doorBlock, enumfacing, 5);
|
||||
int j = this.countBlocksCanSeeSky(doorBlock, enumfacing1, i + 1);
|
||||
|
||||
if (i != j)
|
||||
{
|
||||
this.newDoors.add(new VillageDoorInfo(doorBlock, i < j ? enumfacing : enumfacing1, this.tickCounter));
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Check five blocks in the direction. The centerPos will not be checked.
|
||||
*/
|
||||
private int countBlocksCanSeeSky(BlockPos centerPos, EnumFacing direction, int limitation)
|
||||
{
|
||||
int i = 0;
|
||||
|
||||
for (int j = 1; j <= 5; ++j)
|
||||
{
|
||||
if (this.world.canSeeSky(centerPos.offset(direction, j)))
|
||||
{
|
||||
++i;
|
||||
|
||||
if (i >= limitation)
|
||||
{
|
||||
return i;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return i;
|
||||
}
|
||||
|
||||
private boolean positionInList(BlockPos pos)
|
||||
{
|
||||
for (BlockPos blockpos : this.villagerPositionsList)
|
||||
{
|
||||
if (blockpos.equals(pos))
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean isWoodDoor(BlockPos doorPos)
|
||||
{
|
||||
IBlockState iblockstate = this.world.getBlockState(doorPos);
|
||||
Block block = iblockstate.getBlock();
|
||||
|
||||
if (block instanceof BlockDoor)
|
||||
{
|
||||
return iblockstate.getMaterial() == Material.WOOD;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* reads in data from the NBTTagCompound into this MapDataBase
|
||||
*/
|
||||
public void readFromNBT(NBTTagCompound nbt)
|
||||
{
|
||||
this.tickCounter = nbt.getInteger("Tick");
|
||||
NBTTagList nbttaglist = nbt.getTagList("Villages", 10);
|
||||
|
||||
for (int i = 0; i < nbttaglist.tagCount(); ++i)
|
||||
{
|
||||
NBTTagCompound nbttagcompound = nbttaglist.getCompoundTagAt(i);
|
||||
Village village = new Village();
|
||||
village.readVillageDataFromNBT(nbttagcompound);
|
||||
this.villageList.add(village);
|
||||
}
|
||||
}
|
||||
|
||||
public NBTTagCompound writeToNBT(NBTTagCompound compound)
|
||||
{
|
||||
compound.setInteger("Tick", this.tickCounter);
|
||||
NBTTagList nbttaglist = new NBTTagList();
|
||||
|
||||
for (Village village : this.villageList)
|
||||
{
|
||||
NBTTagCompound nbttagcompound = new NBTTagCompound();
|
||||
village.writeVillageDataToNBT(nbttagcompound);
|
||||
nbttaglist.appendTag(nbttagcompound);
|
||||
}
|
||||
|
||||
compound.setTag("Villages", nbttaglist);
|
||||
return compound;
|
||||
}
|
||||
|
||||
public static String fileNameForProvider(WorldProvider provider)
|
||||
{
|
||||
return "villages" + provider.getDimensionType().getSuffix();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,130 @@
|
||||
package net.minecraft.village;
|
||||
|
||||
import net.minecraft.util.EnumFacing;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
|
||||
public class VillageDoorInfo
|
||||
{
|
||||
/** a block representing the door. Could be either upper or lower part */
|
||||
private final BlockPos doorBlockPos;
|
||||
private final BlockPos insideBlock;
|
||||
/** the inside direction is where can see less sky */
|
||||
private final EnumFacing insideDirection;
|
||||
private int lastActivityTimestamp;
|
||||
private boolean isDetachedFromVillageFlag;
|
||||
private int doorOpeningRestrictionCounter;
|
||||
|
||||
public VillageDoorInfo(BlockPos pos, int deltaX, int deltaZ, int timestamp)
|
||||
{
|
||||
this(pos, getFaceDirection(deltaX, deltaZ), timestamp);
|
||||
}
|
||||
|
||||
private static EnumFacing getFaceDirection(int deltaX, int deltaZ)
|
||||
{
|
||||
if (deltaX < 0)
|
||||
{
|
||||
return EnumFacing.WEST;
|
||||
}
|
||||
else if (deltaX > 0)
|
||||
{
|
||||
return EnumFacing.EAST;
|
||||
}
|
||||
else
|
||||
{
|
||||
return deltaZ < 0 ? EnumFacing.NORTH : EnumFacing.SOUTH;
|
||||
}
|
||||
}
|
||||
|
||||
public VillageDoorInfo(BlockPos pos, EnumFacing facing, int timestamp)
|
||||
{
|
||||
this.doorBlockPos = pos;
|
||||
this.insideDirection = facing;
|
||||
this.insideBlock = pos.offset(facing, 2);
|
||||
this.lastActivityTimestamp = timestamp;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the squared distance between this door and the given coordinate.
|
||||
*/
|
||||
public int getDistanceSquared(int x, int y, int z)
|
||||
{
|
||||
return (int)this.doorBlockPos.distanceSq((double)x, (double)y, (double)z);
|
||||
}
|
||||
|
||||
public int getDistanceToDoorBlockSq(BlockPos pos)
|
||||
{
|
||||
return (int)pos.distanceSq(this.getDoorBlockPos());
|
||||
}
|
||||
|
||||
public int getDistanceToInsideBlockSq(BlockPos pos)
|
||||
{
|
||||
return (int)this.insideBlock.distanceSq(pos);
|
||||
}
|
||||
|
||||
public boolean isInsideSide(BlockPos pos)
|
||||
{
|
||||
int i = pos.getX() - this.doorBlockPos.getX();
|
||||
int j = pos.getZ() - this.doorBlockPos.getY();
|
||||
return i * this.insideDirection.getFrontOffsetX() + j * this.insideDirection.getFrontOffsetZ() >= 0;
|
||||
}
|
||||
|
||||
public void resetDoorOpeningRestrictionCounter()
|
||||
{
|
||||
this.doorOpeningRestrictionCounter = 0;
|
||||
}
|
||||
|
||||
public void incrementDoorOpeningRestrictionCounter()
|
||||
{
|
||||
++this.doorOpeningRestrictionCounter;
|
||||
}
|
||||
|
||||
public int getDoorOpeningRestrictionCounter()
|
||||
{
|
||||
return this.doorOpeningRestrictionCounter;
|
||||
}
|
||||
|
||||
public BlockPos getDoorBlockPos()
|
||||
{
|
||||
return this.doorBlockPos;
|
||||
}
|
||||
|
||||
public BlockPos getInsideBlockPos()
|
||||
{
|
||||
return this.insideBlock;
|
||||
}
|
||||
|
||||
public int getInsideOffsetX()
|
||||
{
|
||||
return this.insideDirection.getFrontOffsetX() * 2;
|
||||
}
|
||||
|
||||
public int getInsideOffsetZ()
|
||||
{
|
||||
return this.insideDirection.getFrontOffsetZ() * 2;
|
||||
}
|
||||
|
||||
public int getLastActivityTimestamp()
|
||||
{
|
||||
return this.lastActivityTimestamp;
|
||||
}
|
||||
|
||||
public void setLastActivityTimestamp(int timestamp)
|
||||
{
|
||||
this.lastActivityTimestamp = timestamp;
|
||||
}
|
||||
|
||||
public boolean getIsDetachedFromVillageFlag()
|
||||
{
|
||||
return this.isDetachedFromVillageFlag;
|
||||
}
|
||||
|
||||
public void setIsDetachedFromVillageFlag(boolean detached)
|
||||
{
|
||||
this.isDetachedFromVillageFlag = detached;
|
||||
}
|
||||
|
||||
public EnumFacing getInsideDirection()
|
||||
{
|
||||
return this.insideDirection;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,210 @@
|
||||
package net.minecraft.village;
|
||||
|
||||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import javax.annotation.Nullable;
|
||||
import net.minecraft.entity.EntityLiving;
|
||||
import net.minecraft.entity.IEntityLivingData;
|
||||
import net.minecraft.entity.monster.EntityZombie;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.MathHelper;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldEntitySpawner;
|
||||
|
||||
public class VillageSiege
|
||||
{
|
||||
private final World world;
|
||||
private boolean hasSetupSiege;
|
||||
private int siegeState = -1;
|
||||
private int siegeCount;
|
||||
private int nextSpawnTime;
|
||||
/** Instance of Village. */
|
||||
private Village village;
|
||||
private int spawnX;
|
||||
private int spawnY;
|
||||
private int spawnZ;
|
||||
|
||||
public VillageSiege(World worldIn)
|
||||
{
|
||||
this.world = worldIn;
|
||||
}
|
||||
|
||||
/**
|
||||
* Runs a single tick for the village siege
|
||||
*/
|
||||
public void tick()
|
||||
{
|
||||
if (this.world.isDaytime())
|
||||
{
|
||||
this.siegeState = 0;
|
||||
}
|
||||
else if (this.siegeState != 2)
|
||||
{
|
||||
if (this.siegeState == 0)
|
||||
{
|
||||
float f = this.world.getCelestialAngle(0.0F);
|
||||
|
||||
if ((double)f < 0.5D || (double)f > 0.501D)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
this.siegeState = this.world.rand.nextInt(10) == 0 ? 1 : 2;
|
||||
this.hasSetupSiege = false;
|
||||
|
||||
if (this.siegeState == 2)
|
||||
{
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
if (this.siegeState != -1)
|
||||
{
|
||||
if (!this.hasSetupSiege)
|
||||
{
|
||||
if (!this.trySetupSiege())
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
this.hasSetupSiege = true;
|
||||
}
|
||||
|
||||
if (this.nextSpawnTime > 0)
|
||||
{
|
||||
--this.nextSpawnTime;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.nextSpawnTime = 2;
|
||||
|
||||
if (this.siegeCount > 0)
|
||||
{
|
||||
this.spawnZombie();
|
||||
--this.siegeCount;
|
||||
}
|
||||
else
|
||||
{
|
||||
this.siegeState = 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private boolean trySetupSiege()
|
||||
{
|
||||
List<EntityPlayer> list = this.world.playerEntities;
|
||||
Iterator iterator = list.iterator();
|
||||
|
||||
while (true)
|
||||
{
|
||||
if (!iterator.hasNext())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
EntityPlayer entityplayer = (EntityPlayer)iterator.next();
|
||||
|
||||
if (!entityplayer.isSpectator())
|
||||
{
|
||||
this.village = this.world.getVillageCollection().getNearestVillage(new BlockPos(entityplayer), 1);
|
||||
|
||||
if (this.village != null && this.village.getNumVillageDoors() >= 10 && this.village.getTicksSinceLastDoorAdding() >= 20 && this.village.getNumVillagers() >= 20)
|
||||
{
|
||||
BlockPos blockpos = this.village.getCenter();
|
||||
float f = (float)this.village.getVillageRadius();
|
||||
boolean flag = false;
|
||||
|
||||
for (int i = 0; i < 10; ++i)
|
||||
{
|
||||
float f1 = this.world.rand.nextFloat() * ((float)Math.PI * 2F);
|
||||
this.spawnX = blockpos.getX() + (int)((double)(MathHelper.cos(f1) * f) * 0.9D);
|
||||
this.spawnY = blockpos.getY();
|
||||
this.spawnZ = blockpos.getZ() + (int)((double)(MathHelper.sin(f1) * f) * 0.9D);
|
||||
flag = false;
|
||||
|
||||
for (Village village : this.world.getVillageCollection().getVillageList())
|
||||
{
|
||||
if (village != this.village && village.isBlockPosWithinSqVillageRadius(new BlockPos(this.spawnX, this.spawnY, this.spawnZ)))
|
||||
{
|
||||
flag = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (!flag)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (flag)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Vec3d vec3d = this.findRandomSpawnPos(new BlockPos(this.spawnX, this.spawnY, this.spawnZ));
|
||||
|
||||
if (vec3d != null)
|
||||
{
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
this.nextSpawnTime = 0;
|
||||
this.siegeCount = 20;
|
||||
return true;
|
||||
}
|
||||
|
||||
private boolean spawnZombie()
|
||||
{
|
||||
Vec3d vec3d = this.findRandomSpawnPos(new BlockPos(this.spawnX, this.spawnY, this.spawnZ));
|
||||
|
||||
if (vec3d == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
EntityZombie entityzombie;
|
||||
|
||||
try
|
||||
{
|
||||
entityzombie = new EntityZombie(this.world);
|
||||
entityzombie.onInitialSpawn(this.world.getDifficultyForLocation(new BlockPos(entityzombie)), (IEntityLivingData)null);
|
||||
}
|
||||
catch (Exception exception)
|
||||
{
|
||||
exception.printStackTrace();
|
||||
return false;
|
||||
}
|
||||
|
||||
entityzombie.setLocationAndAngles(vec3d.x, vec3d.y, vec3d.z, this.world.rand.nextFloat() * 360.0F, 0.0F);
|
||||
this.world.spawnEntity(entityzombie);
|
||||
BlockPos blockpos = this.village.getCenter();
|
||||
entityzombie.setHomePosAndDistance(blockpos, this.village.getVillageRadius());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private Vec3d findRandomSpawnPos(BlockPos pos)
|
||||
{
|
||||
for (int i = 0; i < 10; ++i)
|
||||
{
|
||||
BlockPos blockpos = pos.add(this.world.rand.nextInt(16) - 8, this.world.rand.nextInt(6) - 3, this.world.rand.nextInt(16) - 8);
|
||||
|
||||
if (this.village.isBlockPosWithinSqVillageRadius(blockpos) && WorldEntitySpawner.canCreatureTypeSpawnAtLocation(EntityLiving.SpawnPlacementType.ON_GROUND, this.world, blockpos))
|
||||
{
|
||||
return new Vec3d((double)blockpos.getX(), (double)blockpos.getY(), (double)blockpos.getZ());
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
// Auto generated package-info by MCP
|
||||
@ParametersAreNonnullByDefault
|
||||
@MethodsReturnNonnullByDefault
|
||||
package net.minecraft.village;
|
||||
|
||||
import mcp.MethodsReturnNonnullByDefault;
|
||||
import javax.annotation.ParametersAreNonnullByDefault;
|
||||
Reference in New Issue
Block a user