mirror of
https://github.com/GTNewHorizons/EnderIO.git
synced 2026-11-28 15:56:07 +00:00
Added support for Nutura Berry bushes to farm
This commit is contained in:
1 parent
ebe0d61e47
commit
dd26706383
6 files changed
+167
-20
No files matched your search
@@ -0,0 +1,77 @@
|
||||
package crazypants.enderio.machine.farm;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.network.play.client.C15PacketClientSettings;
|
||||
import net.minecraft.server.management.ItemInWorldManager;
|
||||
import net.minecraft.stats.StatBase;
|
||||
import net.minecraft.util.ChunkCoordinates;
|
||||
import net.minecraft.util.DamageSource;
|
||||
import net.minecraft.util.IChatComponent;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraft.world.WorldServer;
|
||||
|
||||
import com.mojang.authlib.GameProfile;
|
||||
|
||||
import cpw.mods.fml.common.FMLCommonHandler;
|
||||
|
||||
public class FakeFarmPlayer extends EntityPlayerMP {
|
||||
|
||||
private static GameProfile DUMMY_PROFILE = new GameProfile("EioFarmerID", "[EioFarmer]");
|
||||
|
||||
public FakeFarmPlayer(WorldServer world) {
|
||||
super(FMLCommonHandler.instance().getMinecraftServerInstance(), world, DUMMY_PROFILE, new ItemInWorldManager(world));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canCommandSenderUseCommand(int i, String s) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public ChunkCoordinates getPlayerCoordinates() {
|
||||
return new ChunkCoordinates(0, 0, 0);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addChatComponentMessage(IChatComponent chatmessagecomponent) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void addStat(StatBase par1StatBase, int par2) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void openGui(Object mod, int modGuiId, World world, int x, int y, int z) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isEntityInvulnerable() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canAttackPlayer(EntityPlayer player) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDeath(DamageSource source) {
|
||||
return;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdate() {
|
||||
return;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void travelToDimension(int dim) {
|
||||
return;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void func_147100_a(C15PacketClientSettings pkt) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -50,9 +50,9 @@ public class FarmersComune implements IFarmerJoe {
|
||||
|
||||
@Override
|
||||
public IHarvestResult harvestBlock(TileFarmStation farm, BlockCoord bc, Block block, int meta) {
|
||||
if(!block.canHarvestBlock(farm.getFakePlayer(), meta)) {
|
||||
return null;
|
||||
}
|
||||
// if(!block.canHarvestBlock(farm.getFakePlayer(), meta)) {
|
||||
// return null;
|
||||
// }
|
||||
for (IFarmerJoe joe : farmers) {
|
||||
if(joe.canHarvest(farm, bc, block, meta)) {
|
||||
return joe.harvestBlock(farm, bc, block, meta);
|
||||
|
||||
@@ -1,9 +1,15 @@
|
||||
package crazypants.enderio.machine.farm;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.item.EntityItem;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import crazypants.util.BlockCoord;
|
||||
|
||||
public final class ModdedCrops {
|
||||
|
||||
@@ -11,10 +17,10 @@ public final class ModdedCrops {
|
||||
|
||||
public static void addModdedFarmers() {
|
||||
String natura = "Natura";
|
||||
String cropsItem = "N Crops";
|
||||
String blockName = "N Crops";
|
||||
|
||||
Block natCropBlock = GameRegistry.findBlock(natura, cropsItem);
|
||||
if(natCropBlock != null) {
|
||||
Block natCropBlock = GameRegistry.findBlock(natura, blockName);
|
||||
if(natCropBlock != null) {
|
||||
Item natSeedItem = GameRegistry.findItem(natura, "barley.seed");
|
||||
if(natSeedItem != null) {
|
||||
//barley
|
||||
@@ -22,8 +28,19 @@ public final class ModdedCrops {
|
||||
// cotton
|
||||
FarmersComune.instance.joinComune(new PickableFarmer(natCropBlock, 4, 8, new ItemStack(natSeedItem, 1, 1)));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
blockName = "BerryBush";
|
||||
natCropBlock = GameRegistry.findBlock(natura, blockName);
|
||||
if(natCropBlock != null) {
|
||||
Item natSeedItem = GameRegistry.findItem(natura, blockName);
|
||||
if(natSeedItem != null) {
|
||||
for (int i = 0; i < 4; i++) {
|
||||
PickableFarmer farmer = new NaturaBerryFarmer(natCropBlock, i, 12 + i, new ItemStack(natSeedItem, 1, 12 + i));
|
||||
farmer.setRequiresFarmland(false);
|
||||
FarmersComune.instance.joinComune(farmer);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -31,4 +48,55 @@ public final class ModdedCrops {
|
||||
private ModdedCrops() {
|
||||
}
|
||||
|
||||
private static class NaturaBerryFarmer extends PickableFarmer {
|
||||
|
||||
public NaturaBerryFarmer(Block plantedBlock, int plantedBlockMeta, int grownBlockMeta, ItemStack seeds) {
|
||||
super(plantedBlock, plantedBlockMeta, grownBlockMeta, seeds);
|
||||
}
|
||||
|
||||
@Override
|
||||
public IHarvestResult harvestBlock(TileFarmStation farm, BlockCoord bc, Block block, int meta) {
|
||||
|
||||
if(block != getPlantedBlock()) {
|
||||
return null;
|
||||
}
|
||||
BlockCoord upLoc = bc.getLocation(ForgeDirection.UP);
|
||||
Block aboveBlock = farm.getBlock(upLoc);
|
||||
ArrayList<ItemStack> drops = null;
|
||||
|
||||
if(aboveBlock == getPlantedBlock()) {
|
||||
drops = block.getDrops(farm.getWorld(), upLoc.x, upLoc.y, upLoc.z, meta, farm.getMaxLootingValue());
|
||||
farm.damageMaxLootingItem();
|
||||
farm.actionPerformed();
|
||||
farm.getWorld().setBlockToAir(upLoc.x, upLoc.y, upLoc.z);
|
||||
|
||||
}
|
||||
IHarvestResult res = super.harvestBlock(farm, bc, block, meta);
|
||||
if(drops != null) {
|
||||
if(res == null) {
|
||||
res = new HarvestResult();
|
||||
}
|
||||
res.getHarvestedBlocks().add(upLoc);
|
||||
List<EntityItem> addToDrops = res.getDrops();
|
||||
for(ItemStack stack : drops) {
|
||||
addToDrops.add(new EntityItem(farm.getWorld(), upLoc.x + 0.5, upLoc.y + 1, upLoc.z + 0.5, stack.copy()));
|
||||
}
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean canHarvest(TileFarmStation farm, BlockCoord bc, Block block, int meta) {
|
||||
BlockCoord upLoc = bc.getLocation(ForgeDirection.UP);
|
||||
Block aboveBlock = farm.getBlock(upLoc);
|
||||
if(aboveBlock == getPlantedBlock()) {
|
||||
return true;
|
||||
}
|
||||
return super.canHarvest(farm, bc, block, meta);
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -13,7 +13,7 @@ import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public class PickableFarmer extends SeedFarmer {
|
||||
|
||||
|
||||
public PickableFarmer(Block plantedBlock, int plantedBlockMeta, int grownBlockMeta, ItemStack seeds) {
|
||||
super(plantedBlock, plantedBlockMeta, grownBlockMeta, seeds);
|
||||
}
|
||||
@@ -42,12 +42,9 @@ public class PickableFarmer extends SeedFarmer {
|
||||
for(int slot=0;slot < inv.length;slot++) {
|
||||
ItemStack stack = inv[slot];
|
||||
if(stack != null) {
|
||||
inv[slot] = null;
|
||||
float f = 0.7F;
|
||||
double d0 = world.rand.nextFloat() * f + (1.0F - f) * 0.5D;
|
||||
double d1 = world.rand.nextFloat() * f + (1.0F - f) * 0.5D;
|
||||
double d2 = world.rand.nextFloat() * f + (1.0F - f) * 0.5D;
|
||||
EntityItem entityitem = new EntityItem(world, bc.x + d0, bc.y + d1, bc.z + d2, stack);
|
||||
inv[slot] = null;
|
||||
|
||||
EntityItem entityitem = new EntityItem(world, bc.x + 0.5, bc.y + 1, bc.z + 0.5, stack);
|
||||
drops.add(entityitem);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -18,6 +18,7 @@ public class SeedFarmer implements IFarmerJoe {
|
||||
protected int plantedBlockMeta;
|
||||
protected int grownBlockMeta;
|
||||
protected ItemStack seeds;
|
||||
protected boolean requiresFarmland = true;
|
||||
|
||||
public SeedFarmer(Block plantedBlock, ItemStack seeds) {
|
||||
this(plantedBlock, 0, 7, seeds);
|
||||
@@ -83,8 +84,12 @@ public class SeedFarmer implements IFarmerJoe {
|
||||
return plantFromInvenetory(farm, bc);
|
||||
}
|
||||
|
||||
protected boolean requiresFarmland() {
|
||||
return true;
|
||||
public boolean requiresFarmland() {
|
||||
return requiresFarmland;
|
||||
}
|
||||
|
||||
public void setRequiresFarmland(boolean requiresFarmland) {
|
||||
this.requiresFarmland = requiresFarmland;
|
||||
}
|
||||
|
||||
protected boolean plantFromInvenetory(TileFarmStation farm, BlockCoord bc) {
|
||||
|
||||
@@ -42,7 +42,7 @@ public class TileFarmStation extends AbstractPoweredTaskEntity implements IEntit
|
||||
private static final float ENERGY_PER_TICK = Config.farmContinuousEnergyUse;
|
||||
|
||||
private BlockCoord lastScanned;
|
||||
private FakePlayer farmerJoe;
|
||||
private EntityPlayerMP farmerJoe;
|
||||
|
||||
private int farmSize = Config.farmDefaultSize;
|
||||
|
||||
@@ -211,7 +211,7 @@ public class TileFarmStation extends AbstractPoweredTaskEntity implements IEntit
|
||||
}
|
||||
int meta = worldObj.getBlockMetadata(bc.x, bc.y, bc.z);
|
||||
if(farmerJoe == null) {
|
||||
farmerJoe = FakePlayerFactory.getMinecraft(MinecraftServer.getServer().worldServerForDimension(worldObj.provider.dimensionId));
|
||||
farmerJoe = new FakeFarmPlayer(MinecraftServer.getServer().worldServerForDimension(worldObj.provider.dimensionId));
|
||||
}
|
||||
|
||||
if(block == Blocks.air) {
|
||||
@@ -291,7 +291,7 @@ public class TileFarmStation extends AbstractPoweredTaskEntity implements IEntit
|
||||
|
||||
for (EntityItem entity : interestingItems) {
|
||||
double x = (xCoord + 0.5D - entity.posX);
|
||||
double y = (yCoord + 0.5D - entity.posY);
|
||||
double y = (yCoord + 1D - entity.posY);
|
||||
double z = (zCoord + 0.5D - entity.posZ);
|
||||
|
||||
double distance = Math.sqrt(x * x + y * y + z * z);
|
||||
|
||||
Reference in new issue
Block a user