Skip to content

Commit 343ccbf

Browse files
committed
first commit
0 parents  commit 343ccbf

13 files changed

+5521
-0
lines changed

BlockHut.java

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
package net.minecraft.src;
2+
3+
import java.util.List;
4+
import java.util.Random;
5+
6+
public class BlockHut extends BlockChest {
7+
protected int hutWidth;
8+
protected int hutHeight;
9+
protected int clearingRange;
10+
protected int halfWidth;
11+
protected int workingRange;
12+
protected int textureID;
13+
14+
public BlockHut(int blockID) {
15+
super(blockID);
16+
setTickOnLoad(true);
17+
18+
// Need to create the item that will be dropped
19+
//Item.itemsList[blockID] = new ItemBlock(blockID - 256);
20+
}
21+
22+
public int idDropped(int i, Random random) {
23+
return blockID;
24+
}
25+
26+
protected int findTopGround(World world, int x, int z) {
27+
int ySolid = world.findTopSolidBlock(x, z);
28+
int blockId = world.getBlockId(x, ySolid, z);
29+
while(blockId==Block.leaves.blockID ||
30+
blockId==Block.wood.blockID ||
31+
blockId==Block.cactus.blockID ||
32+
blockId==Block.crops.blockID ||
33+
blockId==Block.fence.blockID ||
34+
blockId==Block.fire.blockID ||
35+
blockId==0)
36+
{
37+
ySolid--;
38+
blockId = world.getBlockId(x, ySolid, z);
39+
}
40+
return ySolid;
41+
}
42+
43+
// scan for block type in the specified range
44+
protected Vec3D scanForBlockNearPoint(World world, int blockId, int x, int y, int z,
45+
int rx, int ry, int rz) {
46+
47+
Vec3D entityVec = Vec3D.createVector(x, y, z);
48+
49+
Vec3D closestVec = null;
50+
double minDistance = 999999999;
51+
52+
for (int i = x - rx; i <= x + rx; i++)
53+
for (int j = y - ry; j <= y + ry; j++)
54+
for (int k = z - rz; k <= z + rz; k++) {
55+
if (world.getBlockId(i, j, k) == blockId) {
56+
Vec3D tempVec = Vec3D.createVector(i, j, k);
57+
58+
if (closestVec == null
59+
|| tempVec.distanceTo(entityVec) < minDistance) {
60+
closestVec = tempVec;
61+
minDistance = closestVec.distanceTo(entityVec);
62+
}
63+
}
64+
}
65+
66+
return closestVec;
67+
}
68+
69+
70+
}

BlockHutFarmer.java

Lines changed: 231 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,231 @@
1+
package net.minecraft.src;
2+
3+
import java.util.List;
4+
import java.util.Random;
5+
6+
public class BlockHutFarmer extends BlockHut {
7+
8+
private EntityFarmer em;
9+
10+
public BlockHutFarmer(int blockID, int _textureID) {
11+
super(blockID);
12+
textureID = _textureID;
13+
hutWidth = 5;
14+
hutHeight = 3;
15+
clearingRange = 4;
16+
halfWidth = hutWidth/2;
17+
workingRange = 16;
18+
em=null;
19+
// Sets the recipe be two planks horizontal to each other
20+
// CraftingManager.getInstance().addRecipe(new ItemStack(blockID, 1,0),
21+
// new Object[] { "##", Character.valueOf('#'), Block.dirt,});
22+
}
23+
24+
25+
public boolean canPlaceBlockAt(World world, int i, int j, int k)
26+
{
27+
// check if there are other chests nearby
28+
Vec3D chestPos = scanForBlockNearPoint(world, mod_MineColony.hutFarmer.blockID, i,j,k, workingRange, 20, workingRange);
29+
if (chestPos != null)
30+
return false;
31+
32+
return super.canPlaceBlockAt(world, i, j, k);
33+
}
34+
35+
public boolean blockActivated(World world, int i, int j, int k, EntityPlayer entityplayer)
36+
{
37+
// build house when clicked with stick
38+
ItemStack is = entityplayer.getCurrentEquippedItem();
39+
if(is !=null && is.getItem()!=null && (is.getItem().shiftedIndex == mod_MineColony.scepterGold.shiftedIndex))
40+
{
41+
// clean area around house
42+
for (int x = i - clearingRange; x <= i + clearingRange; x++)
43+
for (int z = k - clearingRange; z <= k + clearingRange; z++)
44+
for (int y = j; y < j + hutHeight; y++) {
45+
if(x!=i || y!=j || z!=k)
46+
world.setBlockWithNotify(x, y, z, 0);
47+
}
48+
49+
// floor
50+
for (int x = i - halfWidth-1; x <= i + halfWidth+1; x++)
51+
for (int z = k - halfWidth-2; z <= k + halfWidth+2; z++) {
52+
world.setBlockWithNotify(x, j - 1, z, Block.cobblestone.blockID);
53+
}
54+
55+
// roof
56+
for (int x = i - halfWidth-1; x <= i + halfWidth+1; x++)
57+
for (int z = k - halfWidth-1; z <= k + halfWidth+1; z++) {
58+
world.setBlockWithNotify(x, j + hutHeight-1, z, Block.planks.blockID);
59+
}
60+
61+
for (int dy = 0 ; dy <= 5; dy++)
62+
for (int x = i - halfWidth -1 +dy; x <= i + halfWidth-dy+1; x++)
63+
for (int z = k - halfWidth-1; z <= k + halfWidth+1; z++) {
64+
if(dy>=0 && x!=i-halfWidth-1+dy && x!=i+halfWidth-dy+1)
65+
world.setBlockWithNotify(x, j +hutHeight + dy, z, Block.cloth.blockID);
66+
else
67+
{
68+
if(x==i)
69+
world.setBlockWithNotify(x, j +hutHeight + dy, z, Block.planks.blockID);
70+
else
71+
{
72+
world.setBlockWithNotify(x, j +hutHeight + dy, z, Block.stairCompactPlanks.blockID);
73+
if(x>i)
74+
world.setBlockMetadataWithNotify(x, j +hutHeight + dy, z, 1);
75+
}
76+
}
77+
}
78+
79+
// wall
80+
for (int z = k - halfWidth-1; z <= k + halfWidth+1; z++)
81+
for (int y = j; y<= j+1; y++)
82+
{
83+
if(z!=k)
84+
{
85+
if(y==j)
86+
world.setBlockWithNotify(i - halfWidth-1, y, z,Block.wood.blockID);
87+
88+
if(y==j+1)
89+
world.setBlockWithNotify(i - halfWidth-1, y, z,Block.planks.blockID);
90+
91+
world.setBlockWithNotify(i + halfWidth+1, y, z,Block.fence.blockID);
92+
}
93+
}
94+
95+
// windows
96+
// wooden
97+
world.setBlockWithNotify(i - halfWidth-1, j+1, k-2, Block.stairCompactPlanks.blockID);
98+
world.setBlockMetadataWithNotify(i - halfWidth-1, j+1, k-2, 3);
99+
world.setBlockWithNotify(i - halfWidth-1, j+1, k-1, Block.stairCompactPlanks.blockID);
100+
world.setBlockMetadataWithNotify(i - halfWidth-1, j+1, k-1, 2);
101+
102+
world.setBlockWithNotify(i - halfWidth-1, j+1, k+1, Block.stairCompactPlanks.blockID);
103+
world.setBlockMetadataWithNotify(i - halfWidth-1, j+1, k+1, 3);
104+
world.setBlockWithNotify(i - halfWidth-1, j+1, k+2, Block.stairCompactPlanks.blockID);
105+
world.setBlockMetadataWithNotify(i - halfWidth-1, j+1, k+2, 2);
106+
107+
// fences
108+
world.setBlockWithNotify(i + halfWidth+1, j+1, k-2, 0);
109+
world.setBlockWithNotify(i + halfWidth+1, j+1, k+2, 0);
110+
}
111+
else if(is !=null && (is.getItem().shiftedIndex == mod_MineColony.scepterSteel.shiftedIndex))
112+
{
113+
// fence
114+
Vec3D chestPos = Vec3D.createVector(i, j, k);
115+
for(int dx = i-workingRange; dx<=i+workingRange;dx++)
116+
for(int dz=k-workingRange; dz<=k+workingRange;dz++)
117+
{
118+
int dy = findTopGround(world, dx, dz);
119+
int groundBlockId = world.getBlockId(dx, dy, dz);
120+
if(groundBlockId == Block.dirt.blockID ||
121+
groundBlockId == Block.grass.blockID ||
122+
groundBlockId == Block.gravel.blockID ||
123+
groundBlockId == Block.sand.blockID ||
124+
groundBlockId == Block.stone.blockID)
125+
{
126+
if(dx == i-workingRange || dx == i+workingRange ||
127+
dz == k-workingRange || dz == k+workingRange)
128+
world.setBlockWithNotify(dx,dy+1,dz, Block.fence.blockID);
129+
}
130+
}
131+
}
132+
else
133+
return super.blockActivated(world, i, j, k, entityplayer);
134+
135+
return true;
136+
137+
}
138+
139+
public void onBlockAdded(World world, int i, int j, int k) {
140+
super.onBlockAdded(world, i, j, k);
141+
//world.setWorldTime(0);
142+
143+
// Chest for stuff with 5 stone axes
144+
world.setBlockWithNotify(i, j, k, mod_MineColony.hutFarmer.blockID);
145+
TileEntityChest tileentitychest = (TileEntityChest) world
146+
.getBlockTileEntity(i, j, k);
147+
148+
tileentitychest.setInventorySlotContents(0, new ItemStack(Item.hoeWood, 1));
149+
tileentitychest.setInventorySlotContents(1, new ItemStack(Item.shovelWood, 1));
150+
tileentitychest.setInventorySlotContents(2, new ItemStack(Item.seeds, 10));
151+
152+
153+
//tileentitychest.setInventorySlotContents(8, new ItemStack(mod_MineColony.scepterGold, 1));
154+
155+
spawnWorker(world, i, j, k);
156+
}
157+
158+
public void updateTick(World world, int i, int j, int k, Random random)
159+
{
160+
super.updateTick(world, i, j, k, random);
161+
162+
if(getFarmerAround(world, i,j,k)==null)
163+
{
164+
if(em!=null)
165+
em.isDead = true;
166+
spawnWorker(world, i, j, k);
167+
}
168+
}
169+
170+
public void spawnWorker(World world, int i, int j, int k)
171+
{
172+
em = (EntityFarmer)EntityList.createEntityInWorld("Farmer", world);
173+
174+
// scan for first free block near chest
175+
Vec3D spawnPoint = scanForBlockNearPoint(world, 0, i, j, k, 1, 0, 1);
176+
if(spawnPoint==null)
177+
spawnPoint = scanForBlockNearPoint(world, Block.snow.blockID, i, j, k, 1, 0, 1);
178+
179+
if(spawnPoint!=null)
180+
{
181+
em.setPosition(spawnPoint.xCoord, spawnPoint.yCoord, spawnPoint.zCoord);
182+
em.setHomePosition(i, j, k);
183+
world.entityJoinedWorld(em);
184+
}
185+
186+
}
187+
188+
public void onBlockRemoval(World world, int i, int j, int k)
189+
{
190+
em = getFarmerAround(world, i,j,k);
191+
if(em!=null)
192+
{
193+
em.isDead=true;
194+
}
195+
}
196+
197+
public EntityFarmer getFarmerAround(World world, int i, int j, int k)
198+
{
199+
List list = world.getEntitiesWithinAABB(EntityFarmer.class, this.getCollisionBoundingBoxFromPool(world, i, j, k).expand(workingRange, 20, workingRange));
200+
if (list != null) {
201+
for (int ii = 0; ii < list.size(); ii++) {
202+
if (list.get(ii) instanceof EntityFarmer) {
203+
return (EntityFarmer)list.get(ii);
204+
}
205+
}
206+
}
207+
208+
return null;
209+
}
210+
211+
public int getBlockTextureFromSide(int side)
212+
{
213+
if(side==1)
214+
{
215+
// Workshop top
216+
return textureID;
217+
}
218+
return blockIndexInTexture;
219+
}
220+
221+
public int getBlockTexture(IBlockAccess iblockaccess, int i, int j, int k, int l)
222+
{
223+
if(l == 1)
224+
{
225+
return textureID;
226+
}
227+
else
228+
return super.getBlockTexture(iblockaccess, i, j, k, l);
229+
}
230+
231+
}

0 commit comments

Comments
 (0)