Got the tree farming working a little better and added a place holder 'harvest' effect

This commit is contained in:
CrazyPants committed 2014-05-04 00:38:18 +08:00
1 parent 89e183619f
commit 0a56bfed16
5 files changed
+102 -24

No files matched your search

@@ -6,6 +6,7 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.IIcon;
import net.minecraft.world.World;
import crazypants.enderio.EnderIO;
import crazypants.enderio.GuiHandler;
import crazypants.enderio.ModObject;
import crazypants.enderio.machine.AbstractMachineBlock;
@@ -13,6 +14,7 @@ import crazypants.enderio.machine.AbstractMachineBlock;
public class BlockFarmStation extends AbstractMachineBlock<TileFarmStation> {
public static BlockFarmStation create() {
EnderIO.packetPipeline.registerPacket(FarmActionPacket.class);
BlockFarmStation result = new BlockFarmStation();
result.init();
return result;
@@ -0,0 +1,66 @@
package crazypants.enderio.farm;
import io.netty.buffer.ByteBuf;
import io.netty.channel.ChannelHandlerContext;
import java.util.ArrayList;
import java.util.List;
import java.util.Random;
import net.minecraft.entity.player.EntityPlayer;
import crazypants.enderio.network.IPacketEio;
import crazypants.util.BlockCoord;
public class FarmActionPacket implements IPacketEio {
private static Random rand = new Random();
private List<BlockCoord> coords;
public FarmActionPacket() {
}
public FarmActionPacket(List<BlockCoord> coords) {
this.coords = coords;
}
@Override
public void encode(ChannelHandlerContext ctx, ByteBuf buffer) {
int size = coords.size();
buffer.writeInt(size);
for (BlockCoord coord : coords) {
buffer.writeInt(coord.x);
buffer.writeInt(coord.y);
buffer.writeInt(coord.z);
}
}
@Override
public void decode(ChannelHandlerContext ctx, ByteBuf buffer) {
int size = buffer.readInt();
coords = new ArrayList<BlockCoord>(size);
for (int i = 0; i < size; i++) {
coords.add(new BlockCoord(buffer.readInt(), buffer.readInt(), buffer.readInt()));
}
}
@Override
public void handleClientSide(EntityPlayer player) {
for (BlockCoord bc : coords) {
for (int i = 0; i < 15; i++) {
double xOff = 0.5 + (rand.nextDouble() - 0.5);
double yOff = -0.5 + (rand.nextDouble() - 0.5) * 0.2;
double zOff = 0.5 + (rand.nextDouble() - 0.5);
player.worldObj.spawnParticle("portal", bc.x + xOff, bc.y + yOff, bc.z + zOff, 0, 0, 0);
}
}
System.out.println("FarmActionPacket.handleClientSide: !!!!!!!!!!!!!!!");
}
@Override
public void handleServerSide(EntityPlayer player) {
}
}
@@ -21,6 +21,7 @@ import net.minecraft.util.AxisAlignedBB;
import net.minecraftforge.common.util.FakePlayer;
import net.minecraftforge.common.util.FakePlayerFactory;
import net.minecraftforge.common.util.ForgeDirection;
import cpw.mods.fml.common.network.NetworkRegistry.TargetPoint;
import crazypants.enderio.EnderIO;
import crazypants.enderio.ModObject;
import crazypants.enderio.machine.AbstractPoweredTaskEntity;
@@ -37,7 +38,7 @@ public class TileFarmStation extends AbstractPoweredTaskEntity implements IEntit
private static final float ENERGY_PER_TICK = 1;
private crazypants.util.BlockCoord lastScanned;
private BlockCoord lastScanned;
private FakePlayer farmerJoe;
private int farmSize = 3;
@@ -98,8 +99,6 @@ public class TileFarmStation extends AbstractPoweredTaskEntity implements IEntit
}
}
public EntityPlayer getFakePlayer() {
return farmerJoe;
}
@@ -160,9 +159,9 @@ public class TileFarmStation extends AbstractPoweredTaskEntity implements IEntit
if(!redstoneCheckPassed || !hasPower()) {
return false;
}
if(worldObj.getWorldTime() % 4 != 0) {
return false;
}
// if(worldObj.getWorldTime() % 4 != 0) {
// return false;
// }
BlockCoord bc = getNextCoord();
if(bc == null) {
@@ -181,10 +180,14 @@ public class TileFarmStation extends AbstractPoweredTaskEntity implements IEntit
FarmersComune.instance.prepareBlock(this, bc, block, meta);
IHarvestResult harvest = FarmersComune.instance.harvestBlock(this, bc, block, meta);
if(harvest != null && harvest.getDrops() != null) {
for (EntityItem ei : harvest.getDrops()) {
if(ei != null) {
worldObj.spawnEntityInWorld(ei);
if(harvest != null) {
if(harvest.getDrops() != null) {
FarmActionPacket pkt = new FarmActionPacket(harvest.getHarvestedBlocks());
EnderIO.packetPipeline.sendToAllAround(pkt, new TargetPoint(worldObj.provider.dimensionId, bc.x, bc.y, bc.z, 64));
for (EntityItem ei : harvest.getDrops()) {
if(ei != null) {
worldObj.spawnEntityInWorld(ei);
}
}
}
}
@@ -432,6 +435,4 @@ public class TileFarmStation extends AbstractPoweredTaskEntity implements IEntit
}
}
}
@@ -80,7 +80,7 @@ public class TreeFarmer implements IFarmerJoe {
}
protected void harvestUp(TileFarmStation farm, BlockCoord bc, HarvestResult res) {
boolean foundWoodAtLevel = false;
if(wood == farm.getBlock(bc) && farm.hasAxe()) {
res.harvestedBlocks.add(bc);
ArrayList<ItemStack> drops = wood.getDrops(farm.getWorld(), bc.x, bc.y, bc.z, farm.getBlockMeta(bc), farm.geAxeLootingValue());
@@ -92,23 +92,32 @@ public class TreeFarmer implements IFarmerJoe {
}
farm.damageAxe();
farm.getWorld().setBlockToAir(bc.x, bc.y, bc.z);
foundWoodAtLevel = true;
} else {
//for new trees, check the sides
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
if(dir.offsetY == 0) {
foundWoodAtLevel |= wood == farm.getBlock(bc.getLocation(dir));
}
}
}
if(foundWoodAtLevel) {
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
if(dir != ForgeDirection.DOWN) {
harvestUp(farm, bc.getLocation(dir), res);
}
}
} else {
//for new trees, check the sides
for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
if(dir.offsetY == 0) {
if(wood == farm.getBlock(bc.getLocation(dir))) {
harvestUp(farm, bc.getLocation(dir), res);
}
}
}
}
//
// if(foundWoodAtLevel) {
// for (ForgeDirection dir : ForgeDirection.VALID_DIRECTIONS) {
// if(dir != ForgeDirection.DOWN) {
// harvestUp(farm, bc.getLocation(dir), res);
// }
// }
// }
}
@@ -5,7 +5,7 @@ import io.netty.channel.ChannelHandlerContext;
import net.minecraft.entity.player.EntityPlayer;
/**
* Created by brad on 27/02/14.
*
*/
public interface IPacketEio {