Add basic farm notifications, never wonder why your farm is stuck again!

This commit is contained in:
tterrag1098 committed 2014-08-28 01:52:29 -04:00
1 parent fa75db00f3
commit a8c59bf2f9
21 files changed
+315 -110

No files matched your search

@@ -56,6 +56,8 @@ import crazypants.enderio.machine.enchanter.EnchanterModelRenderer;
import crazypants.enderio.machine.enchanter.TileEnchanter;
import crazypants.enderio.machine.farm.BlockFarmStation;
import crazypants.enderio.machine.farm.FarmingStationRenderer;
import crazypants.enderio.machine.farm.FarmingStationSpecialRenderer;
import crazypants.enderio.machine.farm.TileFarmStation;
import crazypants.enderio.machine.generator.combustion.BlockCombustionGenerator;
import crazypants.enderio.machine.generator.combustion.CombustionGeneratorModelRenderer;
import crazypants.enderio.machine.generator.combustion.CombustionGeneratorRenderer;
@@ -193,6 +195,7 @@ public class ClientProxy extends CommonProxy {
BlockFarmStation.renderId = RenderingRegistry.getNextAvailableRenderId();
RenderingRegistry.registerBlockHandler(new FarmingStationRenderer());
ClientRegistry.bindTileEntitySpecialRenderer(TileFarmStation.class, new FarmingStationSpecialRenderer());
// BlockWirelessCharger.renderId = RenderingRegistry.getNextAvailableRenderId();
// RenderingRegistry.registerBlockHandler(new WirelessChargerRenderer());
@@ -205,6 +205,7 @@ public final class Config {
public static int farmDefaultSize = 3;
public static boolean farmAxeDamageOnLeafBreak = false;
public static float farmToolTakeDamageChance = 1;
public static boolean disableFarmNotification = false;
public static int magnetPowerUsePerSecondRF = 1;
public static int magnetPowerCapacityRF = 100000;
@@ -599,7 +600,8 @@ public final class Config {
"Should axes in a farm take damage when breaking leaves?").getBoolean(farmAxeDamageOnLeafBreak);
farmToolTakeDamageChance = (float) config.get(sectionFarm.name, "farmToolTakeDamageChance", farmToolTakeDamageChance,
"The chance that a tool in the farm will take damage.").getDouble(farmToolTakeDamageChance);
disableFarmNotification = config.get(sectionFarm.name, "disableFarmNotifications", disableFarmNotification, "Disable the notification text above the farm block.").getBoolean();
combustionGeneratorUseOpaqueModel = config.get(sectionAesthetic.name, "combustionGeneratorUseOpaqueModel", combustionGeneratorUseOpaqueModel,
"If set to true: fluid will not be shown in combustion generator tanks. Improves FPS. ").getBoolean(combustionGeneratorUseOpaqueModel);
@@ -19,6 +19,7 @@ public class BlockFarmStation extends AbstractMachineBlock<TileFarmStation> {
public static BlockFarmStation create() {
PacketHandler.INSTANCE.registerMessage(PacketFarmAction.class, PacketFarmAction.class, PacketHandler.nextID(), Side.CLIENT);
PacketHandler.INSTANCE.registerMessage(PacketUpdateNotification.class, PacketUpdateNotification.class, PacketHandler.nextID(), Side.CLIENT);
BlockFarmStation result = new BlockFarmStation();
result.init();
return result;
@@ -9,6 +9,16 @@ import net.minecraft.item.ItemStack;
import net.minecraftforge.common.IPlantable;
import cpw.mods.fml.common.registry.GameRegistry;
import crazypants.enderio.Log;
import crazypants.enderio.machine.farm.farmers.CustomSeedFarmer;
import crazypants.enderio.machine.farm.farmers.FarmersCommune;
import crazypants.enderio.machine.farm.farmers.MelonFarmer;
import crazypants.enderio.machine.farm.farmers.NaturaBerryFarmer;
import crazypants.enderio.machine.farm.farmers.NetherWartFarmer;
import crazypants.enderio.machine.farm.farmers.PickableFarmer;
import crazypants.enderio.machine.farm.farmers.PlantableFarmer;
import crazypants.enderio.machine.farm.farmers.RubberTreeFarmerIC2;
import crazypants.enderio.machine.farm.farmers.StemFarmer;
import crazypants.enderio.machine.farm.farmers.TreeFarmer;
public final class FarmersRegistry {
@@ -23,17 +33,17 @@ public final class FarmersRegistry {
addIC2();
addMFR();
FarmersCommune.instance.joinCommune(new StemFarmer(Blocks.reeds, new ItemStack(Items.reeds)));
FarmersCommune.instance.joinCommune(new StemFarmer(Blocks.cactus, new ItemStack(Blocks.cactus)));
FarmersCommune.instance.joinCommune(new TreeFarmer(Blocks.sapling, Blocks.log));
FarmersCommune.instance.joinCommune(new TreeFarmer(Blocks.sapling, Blocks.log2));
FarmersCommune.joinCommune(new StemFarmer(Blocks.reeds, new ItemStack(Items.reeds)));
FarmersCommune.joinCommune(new StemFarmer(Blocks.cactus, new ItemStack(Blocks.cactus)));
FarmersCommune.joinCommune(new TreeFarmer(Blocks.sapling, Blocks.log));
FarmersCommune.joinCommune(new TreeFarmer(Blocks.sapling, Blocks.log2));
//special case of plantables to get spacing correct
FarmersCommune.instance.joinCommune(new MelonFarmer(Blocks.melon_stem, Blocks.melon_block, new ItemStack(Items.melon_seeds)));
FarmersCommune.instance.joinCommune(new MelonFarmer(Blocks.pumpkin_stem, Blocks.pumpkin, new ItemStack(Items.pumpkin_seeds)));
FarmersCommune.joinCommune(new MelonFarmer(Blocks.melon_stem, Blocks.melon_block, new ItemStack(Items.melon_seeds)));
FarmersCommune.joinCommune(new MelonFarmer(Blocks.pumpkin_stem, Blocks.pumpkin, new ItemStack(Items.pumpkin_seeds)));
//'BlockNetherWart' is not an IGrowable
FarmersCommune.instance.joinCommune(new NetherWartFarmer());
FarmersCommune.joinCommune(new NetherWartFarmer());
//Handles all 'vanilla' style crops
FarmersCommune.instance.joinCommune(DEFAULT_FARMER);
FarmersCommune.joinCommune(DEFAULT_FARMER);
}
public static void addPickable(String mod, String blockName, String itemName) {
@@ -41,7 +51,7 @@ public final class FarmersRegistry {
if(cropBlock != null) {
Item seedItem = GameRegistry.findItem(mod, itemName);
if(seedItem != null) {
FarmersCommune.instance.joinCommune(new PickableFarmer(cropBlock, new ItemStack(seedItem)));
FarmersCommune.joinCommune(new PickableFarmer(cropBlock, new ItemStack(seedItem)));
}
}
}
@@ -59,7 +69,7 @@ public final class FarmersRegistry {
}
}
}
FarmersCommune.instance.joinCommune(farmer);
FarmersCommune.joinCommune(farmer);
return farmer;
}
}
@@ -77,7 +87,7 @@ public final class FarmersRegistry {
for (int i = 0; i < 2; i++) {
PickableFarmer farmer = new NaturaBerryFarmer(cropBlock, i, 12 + i, new ItemStack(seedItem, 1, 8 + i));
farmer.setRequiresFarmland(false);
FarmersCommune.instance.joinCommune(farmer);
FarmersCommune.joinCommune(farmer);
}
}
}
@@ -90,7 +100,7 @@ public final class FarmersRegistry {
for (int i = 0; i < 4; i++) {
PickableFarmer farmer = new NaturaBerryFarmer(cropBlock, i, 12 + i, new ItemStack(seedItem, 1, 8 + i));
farmer.setRequiresFarmland(false);
FarmersCommune.instance.joinCommune(farmer);
FarmersCommune.joinCommune(farmer);
}
}
}
@@ -107,9 +117,9 @@ public final class FarmersRegistry {
Item seedItem = GameRegistry.findItem(mod, "barley.seed");
if(seedItem != null) {
//barley
FarmersCommune.instance.joinCommune(new CustomSeedFarmer(cropBlock, 3, new ItemStack(seedItem)));
FarmersCommune.joinCommune(new CustomSeedFarmer(cropBlock, 3, new ItemStack(seedItem)));
// cotton
FarmersCommune.instance.joinCommune(new PickableFarmer(cropBlock, 4, 8, new ItemStack(seedItem, 1, 1)));
FarmersCommune.joinCommune(new PickableFarmer(cropBlock, 4, 8, new ItemStack(seedItem, 1, 1)));
}
}
@@ -121,7 +131,7 @@ public final class FarmersRegistry {
for (int i = 0; i < 4; i++) {
PickableFarmer farmer = new NaturaBerryFarmer(cropBlock, i, 12 + i, new ItemStack(seedItem, 1, 12 + i));
farmer.setRequiresFarmland(false);
FarmersCommune.instance.joinCommune(farmer);
FarmersCommune.joinCommune(farmer);
}
}
}
@@ -129,7 +139,7 @@ public final class FarmersRegistry {
blockName = "florasapling";
Block saplingBlock = GameRegistry.findBlock(mod, blockName);
if(saplingBlock != null) {
FarmersCommune.instance.joinCommune(new TreeFarmer(saplingBlock,
FarmersCommune.joinCommune(new TreeFarmer(saplingBlock,
GameRegistry.findBlock(mod, "tree"),
GameRegistry.findBlock(mod, "willow"),
GameRegistry.findBlock(mod, "Dark Tree")));
@@ -137,7 +147,7 @@ public final class FarmersRegistry {
blockName = "Rare Sapling";
saplingBlock = GameRegistry.findBlock(mod, blockName);
if(saplingBlock != null) {
FarmersCommune.instance.joinCommune(new TreeFarmer(saplingBlock, GameRegistry.findBlock(mod, "Rare Tree")));
FarmersCommune.joinCommune(new TreeFarmer(saplingBlock, GameRegistry.findBlock(mod, "Rare Tree")));
}
}
@@ -147,7 +157,7 @@ public final class FarmersRegistry {
String blockName = "tile.mfr.rubberwood.sapling";
Block saplingBlock = GameRegistry.findBlock(mod, blockName);
if(saplingBlock != null) {
FarmersCommune.instance.joinCommune(new TreeFarmer(saplingBlock, GameRegistry.findBlock(mod, "tile.mfr.rubberwood.log")));
FarmersCommune.joinCommune(new TreeFarmer(saplingBlock, GameRegistry.findBlock(mod, "tile.mfr.rubberwood.log")));
}
}
@@ -155,7 +165,7 @@ public final class FarmersRegistry {
private static void addIC2() {
RubberTreeFarmerIC2 rtf = new RubberTreeFarmerIC2();
if(rtf.isValid()) {
FarmersCommune.instance.joinCommune(rtf);
FarmersCommune.joinCommune(rtf);
}
}
@@ -0,0 +1,86 @@
package crazypants.enderio.machine.farm;
import crazypants.enderio.config.Config;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.renderer.OpenGlHelper;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.client.renderer.tileentity.TileEntitySpecialRenderer;
import net.minecraft.tileentity.TileEntity;
import static org.lwjgl.opengl.GL11.*;
public class FarmingStationSpecialRenderer extends TileEntitySpecialRenderer{
private void renderFarmStationAt(TileFarmStation tile, double x, double y, double z, float partialTickTime) {
Minecraft mc = Minecraft.getMinecraft();
FontRenderer fnt = mc.fontRenderer;
Tessellator tessellator = Tessellator.instance;
String toRender = tile.notification;
if ("".equals(toRender) || Config.disableFarmNotification) {
return;
}
glPushMatrix();
glTranslated(x + 0.5, y + 1.5, z + 0.5); // center of block and 1 block up
glRotatef(180, 1, 0, 0); // text is upside-down by default (idk)
float scale = 0.025f;
glScalef(scale, scale, scale); // text is huge!
glDisable(GL_LIGHTING);
rotateToPlayer();
glPushMatrix();
glTranslatef(-fnt.getStringWidth(toRender) / 2, 0, 0);
renderBackground(tessellator, fnt, toRender);
fnt.drawString(toRender, 0, 0, 0xFFFFFF);
glTranslatef(0.5f, 0.5f, 0.1f);
fnt.drawString(toRender, 0, 0, 0x555555); // manual shadow
glPopMatrix();
glPopMatrix();
}
private void rotateToPlayer()
{
glRotatef(RenderManager.instance.playerViewY + 180, 0.0F, 1.0F, 0.0F);
glRotatef(-RenderManager.instance.playerViewX, 1.0F, 0.0F, 0.0F);
}
private void renderBackground(Tessellator tessellator, FontRenderer fnt, String toRender) {
glPushAttrib(GL_ALL_ATTRIB_BITS);
glDisable(GL_TEXTURE_2D);
glEnable(GL_BLEND);
glShadeModel(GL_SMOOTH);
glDisable(GL_ALPHA_TEST);
glDisable(GL_CULL_FACE);
glDepthMask(false);
RenderHelper.disableStandardItemLighting();
OpenGlHelper.glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA, GL_ONE, GL_ZERO); // stop random disappearing
float width = (float) fnt.getStringWidth(toRender);
float height = (float) fnt.FONT_HEIGHT;
float padding = 2f;
tessellator.startDrawingQuads();
tessellator.setColorRGBA(70, 20, 100, 200);
tessellator.addVertex(-padding, -padding, 0);
tessellator.addVertex(-padding, height + padding, 0);
tessellator.addVertex(width + padding, height + padding, 0);
tessellator.addVertex(width + padding, -padding, 0);
tessellator.draw();
glPopAttrib();
}
@Override
public void renderTileEntityAt(TileEntity tile, double x, double y, double z, float partialTickTime) {
if (tile instanceof TileFarmStation) {
renderFarmStationAt((TileFarmStation) tile, x, y, z, partialTickTime);
}
}
}
@@ -0,0 +1,43 @@
package crazypants.enderio.machine.farm;
import io.netty.buffer.ByteBuf;
import cpw.mods.fml.common.network.ByteBufUtils;
import cpw.mods.fml.common.network.simpleimpl.IMessage;
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
import crazypants.enderio.EnderIO;
import crazypants.enderio.network.MessageTileEntity;
public class PacketUpdateNotification extends MessageTileEntity<TileFarmStation> implements IMessage, IMessageHandler<PacketUpdateNotification, IMessage> {
private String notification;
public PacketUpdateNotification() {
}
public PacketUpdateNotification(TileFarmStation tile, String notification) {
super(tile);
this.notification = notification;
}
@Override
public void fromBytes(ByteBuf buf) {
super.fromBytes(buf);
notification = ByteBufUtils.readUTF8String(buf);
}
@Override
public void toBytes(ByteBuf buf) {
super.toBytes(buf);
ByteBufUtils.writeUTF8String(buf, notification);
}
@Override
public IMessage onMessage(PacketUpdateNotification message, MessageContext ctx) {
TileFarmStation te = message.getTileEntity(EnderIO.proxy.getClientWorld());
if(te != null) {
te.notification = message.notification;
}
return null;
}
}
@@ -1,8 +1,5 @@
package crazypants.enderio.machine.farm;
import java.util.ArrayList;
import java.util.List;
import net.minecraft.block.Block;
import net.minecraft.enchantment.Enchantment;
import net.minecraft.enchantment.EnchantmentHelper;
@@ -10,13 +7,11 @@ import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.item.ItemAxe;
import net.minecraft.item.ItemHoe;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.server.MinecraftServer;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import buildcraft.api.power.PowerHandler.Type;
import cpw.mods.fml.common.network.NetworkRegistry.TargetPoint;
@@ -29,15 +24,21 @@ import crazypants.enderio.machine.IMachineRecipe.ResultStack;
import crazypants.enderio.machine.IPoweredTask;
import crazypants.enderio.machine.MachineRecipeInput;
import crazypants.enderio.machine.SlotDefinition;
import crazypants.enderio.machine.farm.farmers.FarmersCommune;
import crazypants.enderio.machine.farm.farmers.IHarvestResult;
import crazypants.enderio.network.PacketHandler;
import crazypants.enderio.power.BasicCapacitor;
import crazypants.enderio.power.Capacitors;
import crazypants.enderio.power.ICapacitor;
import crazypants.enderio.power.PowerHandlerUtil;
import crazypants.util.BlockCoord;
import crazypants.util.Lang;
import crazypants.util.Util;
public class TileFarmStation extends AbstractPoweredTaskEntity /*implements IEntitySelector*/ {
public class TileFarmStation extends AbstractPoweredTaskEntity /*
* implements
* IEntitySelector
*/{
private static final float ENERGY_PER_TICK = Config.farmContinuousEnergyUse;
@@ -51,20 +52,23 @@ public class TileFarmStation extends AbstractPoweredTaskEntity /*implements IEnt
private int minSupSlot = maxToolSlot + 1;
private int maxSupSlot = minSupSlot + 4;
private final int upgradeBonusSize = 2;
private static final DummyTask TASK = new DummyTask();
private ICapacitor cap = new BasicCapacitor(200,25000);
private ICapacitor cap = new BasicCapacitor(200, 25000);
public int tier = 1;
public String notification = "";
public boolean sendNotification = false;
public TileFarmStation() {
super(new SlotDefinition(6, 4, 1));
currentTask = TASK;
powerHandler = PowerHandlerUtil.createHandler(cap, this, Type.MACHINE);
}
public int getFarmSize() {
@@ -78,8 +82,8 @@ public class TileFarmStation extends AbstractPoweredTaskEntity /*implements IEnt
public void actionPerformed() {
usePower(Config.farmActionEnergyUse * (getUpgradeDist() * upgradeBonusSize));
}
public boolean tillBlock(BlockCoord plantingLocation) {
public boolean tillBlock(BlockCoord plantingLocation) {
BlockCoord dirtLoc = plantingLocation.getLocation(ForgeDirection.DOWN);
Block dirtBlock = getBlock(dirtLoc);
if((dirtBlock == Blocks.dirt || dirtBlock == Blocks.grass) && hasHoe()) {
@@ -94,7 +98,7 @@ public class TileFarmStation extends AbstractPoweredTaskEntity /*implements IEnt
}
return false;
}
public int getMaxLootingValue() {
int result = 0;
for (int i = minToolSlot; i <= maxToolSlot; i++) {
@@ -107,12 +111,12 @@ public class TileFarmStation extends AbstractPoweredTaskEntity /*implements IEnt
}
return result;
}
private int getUpgradeDist() {
int upg = slotDefinition.getMaxUpgradeSlot();
if (inventory[upg] == null) {
if(inventory[upg] == null) {
return 0;
} else {
} else {
return upgradeBonusSize * inventory[upg].getItemDamage();
}
}
@@ -137,12 +141,12 @@ public class TileFarmStation extends AbstractPoweredTaskEntity /*implements IEnt
public boolean hasHoe() {
return hasTool(ItemHoe.class);
}
public boolean hasAxe() {
return hasTool(ItemAxe.class);
}
public boolean hasDefaultHarvestTool() {
public boolean hasDefaultHarvestTool() {
return hasAxe() || hasHoe();
}
@@ -154,7 +158,6 @@ public class TileFarmStation extends AbstractPoweredTaskEntity /*implements IEnt
return getLooting(tool);
}
public void damageAxe(Block blk, BlockCoord bc) {
damageTool(ItemAxe.class, blk, bc, 1);
}
@@ -177,16 +180,16 @@ public class TileFarmStation extends AbstractPoweredTaskEntity /*implements IEnt
}
public void damageTool(Class<?> class1, Block blk, BlockCoord bc, int damage) {
float rand = worldObj.rand.nextFloat();
if (rand >= Config.farmToolTakeDamageChance)
if(rand >= Config.farmToolTakeDamageChance)
return;
ItemStack tool = getTool(class1);
if(tool == null) {
return;
}
if(tool.getItem() instanceof ItemAxe) {
tool.getItem().onBlockDestroyed(tool, worldObj, blk, bc.x, bc.y, bc.z, farmerJoe);
} else if(tool.getItem() instanceof ItemHoe) {
@@ -199,7 +202,7 @@ public class TileFarmStation extends AbstractPoweredTaskEntity /*implements IEnt
destroyTool(class1);
}
}
private void destroyTool(Class<?> class1) {
for (int i = minToolSlot; i <= maxToolSlot; i++) {
if(Util.isType(inventory[i], class1)) {
@@ -209,8 +212,8 @@ public class TileFarmStation extends AbstractPoweredTaskEntity /*implements IEnt
}
}
}
private int getLooting(ItemStack stack) {
private int getLooting(ItemStack stack) {
return Math.max(
EnchantmentHelper.getEnchantmentLevel(Enchantment.looting.effectId, stack),
EnchantmentHelper.getEnchantmentLevel(Enchantment.fortune.effectId, stack));
@@ -223,7 +226,7 @@ public class TileFarmStation extends AbstractPoweredTaskEntity /*implements IEnt
public Block getBlock(BlockCoord bc) {
return worldObj.getBlock(bc.x, bc.y, bc.z);
}
public Block getBlock(int x, int y, int z) {
return worldObj.getBlock(x, y, z);
}
@@ -231,19 +234,42 @@ public class TileFarmStation extends AbstractPoweredTaskEntity /*implements IEnt
public int getBlockMeta(BlockCoord bc) {
return worldObj.getBlockMetadata(bc.x, bc.y, bc.z);
}
public boolean isOpen(BlockCoord bc) {
Block block = worldObj.getBlock(bc.x, bc.y, bc.z);
return block.isAir(worldObj, bc.x, bc.y, bc.z) || block.isReplaceable(worldObj, bc.x, bc.y, bc.z);
}
public void setNotification(String unloc) {
String newNote = Lang.localize("farm.note." + unloc);
if(!newNote.equals(notification)) {
notification = newNote;
sendNotification = true;
}
}
public void clearNotification() {
if(hasNotification()) {
notification = "";
sendNotification = true;
}
}
public boolean hasNotification() {
return !"".equals(notification);
}
private void sendNotification() {
PacketHandler.INSTANCE.sendToAll(new PacketUpdateNotification(this, notification));
}
@Override
protected boolean isMachineItemValidForSlot(int i, ItemStack stack) {
if(stack == null) {
return false;
}
if(i < 2) {
for(Class<?> toolType : FarmersCommune.instance.getToolTypes()) {
for (Class<?> toolType : FarmersCommune.instance.getToolTypes()) {
if(getTool(stack.getItem().getClass()) == null && (Util.isType(stack, toolType) || getLooting(stack) > 0)) {
return true;
}
@@ -260,12 +286,19 @@ public class TileFarmStation extends AbstractPoweredTaskEntity /*implements IEnt
protected boolean doTick(boolean redstoneCheckPassed) {
if (sendNotification) {
sendNotification = false;
sendNotification();
}
if(!redstoneCheckPassed || !hasPower()) {
return false;
}
if(worldObj.getTotalWorldTime() % 2 != 0) {
return false;
}
clearNotification();
BlockCoord bc = getNextCoord();
if(bc != null && bc.equals(getLocation())) { //don't try and harvest ourselves
@@ -285,16 +318,16 @@ public class TileFarmStation extends AbstractPoweredTaskEntity /*implements IEnt
farmerJoe = new FakeFarmPlayer(MinecraftServer.getServer().worldServerForDimension(worldObj.provider.dimensionId));
}
if(isOpen(bc)) {
FarmersCommune.instance.prepareBlock(this, bc, block, meta);
block = worldObj.getBlock(bc.x, bc.y, bc.z);
}
if(isOutputFull()) {
setNotification("outputFull");
return false;
}
if(!isOpen(bc) && hasPower()) {
IHarvestResult harvest = FarmersCommune.instance.harvestBlock(this, bc, block, meta);
if(harvest != null) {
@@ -302,7 +335,7 @@ public class TileFarmStation extends AbstractPoweredTaskEntity /*implements IEnt
PacketFarmAction pkt = new PacketFarmAction(harvest.getHarvestedBlocks());
PacketHandler.INSTANCE.sendToAllAround(pkt, new TargetPoint(worldObj.provider.dimensionId, bc.x, bc.y, bc.z, 64));
for (EntityItem ei : harvest.getDrops()) {
if(ei != null) {
if(ei != null) {
insertHarvestDrop(ei);
if(!ei.isDead) {
worldObj.spawnEntityInWorld(ei);
@@ -321,7 +354,7 @@ public class TileFarmStation extends AbstractPoweredTaskEntity /*implements IEnt
if(curStack == null || curStack.stackSize < curStack.getMaxStackSize()) {
return false;
}
}
}
return true;
}
@@ -359,11 +392,11 @@ public class TileFarmStation extends AbstractPoweredTaskEntity /*implements IEnt
}
return null;
}
public ItemStack takeSeedFromSupplies(BlockCoord bc) {
return takeSeedFromSupplies(getSeedTypeInSuppliesFor(bc), bc);
}
public ItemStack getSeedTypeInSuppliesFor(BlockCoord bc) {
int slot = getSupplySlotForCoord(bc);
ItemStack inv = inventory[slot];
@@ -402,7 +435,6 @@ public class TileFarmStation extends AbstractPoweredTaskEntity /*implements IEnt
}
private int insertResult(ItemStack stack) {
int origSize = stack.stackSize;
@@ -426,7 +458,7 @@ public class TileFarmStation extends AbstractPoweredTaskEntity /*implements IEnt
if(inserted >= origSize) {
return origSize;
}
ResultStack[] in = new ResultStack[] { new ResultStack(stack) };
mergeResults(in);
return origSize - (in[0].item == null ? 0 : in[0].item.stackSize);
@@ -436,7 +468,7 @@ public class TileFarmStation extends AbstractPoweredTaskEntity /*implements IEnt
private BlockCoord getNextCoord() {
int size = getFarmSize();
BlockCoord loc = getLocation();
if(lastScanned == null) {
lastScanned = new BlockCoord(loc.x - size, loc.y, loc.z - size);
@@ -478,23 +510,23 @@ public class TileFarmStation extends AbstractPoweredTaskEntity /*implements IEnt
@Override
public void setCapacitor(Capacitors capacitorType) {
switch(capacitorType.ordinal()) {
switch (capacitorType.ordinal()) {
case 1:
cap = new BasicCapacitor(400,50000);
cap = new BasicCapacitor(400, 50000);
break;
case 2:
cap = new BasicCapacitor(1000,250000,20);
cap = new BasicCapacitor(1000, 250000, 20);
break;
default:
cap = new BasicCapacitor(200,25000,50);
cap = new BasicCapacitor(200, 25000, 50);
break;
}
tier = capacitorType.ordinal();
powerHandler.configure(cap.getMinEnergyReceived(), cap.getMaxEnergyReceived(), cap.getMinActivationEnergy(), cap.getMaxEnergyStored());
}
@Override
public ICapacitor getCapacitor() {
public ICapacitor getCapacitor() {
return cap;
}
@@ -1,4 +1,4 @@
package crazypants.enderio.machine.farm;
package crazypants.enderio.machine.farm.farmers;
import java.util.ArrayList;
import java.util.List;
@@ -10,6 +10,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.common.IPlantable;
import net.minecraftforge.common.util.ForgeDirection;
import crazypants.enderio.machine.farm.TileFarmStation;
import crazypants.util.BlockCoord;
public class CustomSeedFarmer implements IFarmerJoe {
@@ -1,4 +1,4 @@
package crazypants.enderio.machine.farm;
package crazypants.enderio.machine.farm.farmers;
import java.util.ArrayList;
import java.util.HashSet;
@@ -9,7 +9,9 @@ import net.minecraft.block.Block;
import net.minecraft.item.ItemAxe;
import net.minecraft.item.ItemHoe;
import net.minecraft.item.ItemStack;
import crazypants.enderio.machine.farm.TileFarmStation;
import crazypants.util.BlockCoord;
import crazypants.util.Lang;
public class FarmersCommune implements IFarmerJoe {
@@ -1,4 +1,4 @@
package crazypants.enderio.machine.farm;
package crazypants.enderio.machine.farm.farmers;
import java.util.ArrayList;
import java.util.List;
@@ -1,8 +1,9 @@
package crazypants.enderio.machine.farm;
package crazypants.enderio.machine.farm.farmers;
import net.minecraft.block.Block;
import net.minecraft.item.ItemStack;
import crazypants.enderio.machine.farm.TileFarmStation;
import crazypants.util.BlockCoord;
public interface IFarmerJoe {
@@ -1,4 +1,4 @@
package crazypants.enderio.machine.farm;
package crazypants.enderio.machine.farm.farmers;
import java.util.List;
@@ -1,5 +1,6 @@
package crazypants.enderio.machine.farm;
package crazypants.enderio.machine.farm.farmers;
import crazypants.enderio.machine.farm.TileFarmStation;
import crazypants.util.BlockCoord;
import net.minecraft.block.Block;
import net.minecraft.item.ItemStack;
@@ -1,4 +1,4 @@
package crazypants.enderio.machine.farm;
package crazypants.enderio.machine.farm.farmers;
import java.util.List;
@@ -6,6 +6,7 @@ import net.minecraft.block.Block;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.util.ForgeDirection;
import crazypants.enderio.machine.farm.TileFarmStation;
import crazypants.util.BlockCoord;
public class NaturaBerryFarmer extends PickableFarmer {
@@ -1,4 +1,4 @@
package crazypants.enderio.machine.farm;
package crazypants.enderio.machine.farm.farmers;
import net.minecraft.block.Block;
import net.minecraft.init.Blocks;
@@ -6,6 +6,7 @@ import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import crazypants.enderio.machine.farm.TileFarmStation;
import crazypants.util.BlockCoord;
public class NetherWartFarmer extends CustomSeedFarmer {
@@ -1,4 +1,4 @@
package crazypants.enderio.machine.farm;
package crazypants.enderio.machine.farm.farmers;
import java.util.ArrayList;
import java.util.List;
@@ -8,6 +8,7 @@ import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import crazypants.enderio.machine.farm.TileFarmStation;
import crazypants.util.BlockCoord;
public class PickableFarmer extends CustomSeedFarmer {
@@ -1,4 +1,4 @@
package crazypants.enderio.machine.farm;
package crazypants.enderio.machine.farm.farmers;
import static net.minecraftforge.common.EnumPlantType.Cave;
import static net.minecraftforge.common.EnumPlantType.Crop;
@@ -23,16 +23,17 @@ import net.minecraft.world.World;
import net.minecraftforge.common.EnumPlantType;
import net.minecraftforge.common.IPlantable;
import net.minecraftforge.common.util.ForgeDirection;
import crazypants.enderio.machine.farm.TileFarmStation;
import crazypants.util.BlockCoord;
public class PlantableFarmer implements IFarmerJoe {
private Set<Block> harvestExcludes = new HashSet<Block>();
public void addHarvestExlude(Block block) {
harvestExcludes.add(block);
}
@Override
public boolean canPlant(ItemStack stack) {
if(stack == null) {
@@ -40,7 +41,7 @@ public class PlantableFarmer implements IFarmerJoe {
}
return stack.getItem() instanceof IPlantable;
}
@Override
public boolean prepareBlock(TileFarmStation farm, BlockCoord bc, Block block, int meta) {
if(block == null) {
@@ -49,12 +50,14 @@ public class PlantableFarmer implements IFarmerJoe {
ItemStack seedStack = farm.getSeedTypeInSuppliesFor(bc);
if(seedStack == null) {
farm.setNotification("noSeeds");
return false;
}
if(!(seedStack.getItem() instanceof IPlantable)) {
return false;
}
IPlantable plantable = (IPlantable) seedStack.getItem();
EnumPlantType type = plantable.getPlantType(farm.getWorld(), bc.x, bc.y, bc.z);
if(type == null) {
@@ -70,6 +73,9 @@ public class PlantableFarmer implements IFarmerJoe {
if(type == EnumPlantType.Crop) {
if(!farm.tillBlock(bc)) {
if(!farm.hasHoe()) {
farm.setNotification("noHoe");
}
return false;
}
return plantFromInventory(farm, bc, plantable);
@@ -77,27 +83,28 @@ public class PlantableFarmer implements IFarmerJoe {
return false;
}
// From BlockBush, as a reference
// @Override
// public EnumPlantType getPlantType(IBlockAccess world, int x, int y, int z)
// {
// if (this == Blocks.wheat) return Crop;
// if (this == Blocks.carrots) return Crop;
// if (this == Blocks.potatoes) return Crop;
// if (this == Blocks.melon_stem) return Crop;
// if (this == Blocks.pumpkin_stem) return Crop;
// if (this == Blocks.deadbush) return Desert;
// if (this == Blocks.waterlily) return Water;
// if (this == Blocks.red_mushroom) return Cave;
// if (this == Blocks.brown_mushroom) return Cave;
// if (this == Blocks.nether_wart) return Nether;
// if (this == Blocks.sapling) return Plains;
// if (this == Blocks.tallgrass) return Plains;
// if (this == Blocks.double_plant) return Plains;
// if (this == Blocks.red_flower) return Plains;
// if (this == Blocks.yellow_flower) return Plains;
// return Plains;
// }
// From BlockBush, as a reference
// @Override
// public EnumPlantType getPlantType(IBlockAccess world, int x, int y, int z)
// {
// if (this == Blocks.wheat) return Crop;
// if (this == Blocks.carrots) return Crop;
// if (this == Blocks.potatoes) return Crop;
// if (this == Blocks.melon_stem) return Crop;
// if (this == Blocks.pumpkin_stem) return Crop;
// if (this == Blocks.deadbush) return Desert;
// if (this == Blocks.waterlily) return Water;
// if (this == Blocks.red_mushroom) return Cave;
// if (this == Blocks.brown_mushroom) return Cave;
// if (this == Blocks.nether_wart) return Nether;
// if (this == Blocks.sapling) return Plains;
// if (this == Blocks.tallgrass) return Plains;
// if (this == Blocks.double_plant) return Plains;
// if (this == Blocks.red_flower) return Plains;
// if (this == Blocks.yellow_flower) return Plains;
// return Plains;
// }
protected boolean plantFromInventory(TileFarmStation farm, BlockCoord bc, IPlantable plantable) {
World worldObj = farm.getWorldObj();
@@ -110,7 +117,7 @@ public class PlantableFarmer implements IFarmerJoe {
protected boolean plant(TileFarmStation farm, World worldObj, BlockCoord bc, IPlantable plantable) {
worldObj.setBlock(bc.x, bc.y, bc.z, Blocks.air, 0, 1 | 2);
Block target = plantable.getPlant(null, 0, 0, 0);
int meta = plantable.getPlantMetadata(null, 0, 0, 0);
int meta = plantable.getPlantMetadata(null, 0, 0, 0);
worldObj.setBlock(bc.x, bc.y, bc.z, target, meta, 1 | 2);
farm.actionPerformed();
return true;
@@ -130,7 +137,7 @@ public class PlantableFarmer implements IFarmerJoe {
@Override
public boolean canHarvest(TileFarmStation farm, BlockCoord bc, Block block, int meta) {
if(!harvestExcludes.contains(block) && block instanceof IGrowable && !(block instanceof BlockStem)) {
return !((IGrowable)block).func_149851_a(farm.getWorldObj(), bc.x, bc.y, bc.z, true);
return !((IGrowable) block).func_149851_a(farm.getWorldObj(), bc.x, bc.y, bc.z, true);
}
return false;
}
@@ -145,7 +152,7 @@ public class PlantableFarmer implements IFarmerJoe {
List<EntityItem> result = new ArrayList<EntityItem>();
ItemStack removedPlantable = null;
ArrayList<ItemStack> drops = block.getDrops(worldObj, bc.x, bc.y, bc.z, meta, farm.getMaxLootingValue());
farm.damageMaxLootingItem(1, bc, block);
farm.actionPerformed();
@@ -166,7 +173,7 @@ public class PlantableFarmer implements IFarmerJoe {
}
if(removed) {
if(!plant(farm, worldObj, bc, (IPlantable)removedPlantable.getItem())) {
if(!plant(farm, worldObj, bc, (IPlantable) removedPlantable.getItem())) {
result.add(new EntityItem(worldObj, bc.x + 0.5, bc.y + 0.5, bc.z + 0.5, removedPlantable.copy()));
worldObj.setBlock(bc.x, bc.y, bc.z, Blocks.air, 0, 1 | 2);
}
@@ -181,7 +188,7 @@ public class PlantableFarmer implements IFarmerJoe {
if(!(stack.getItem() instanceof IPlantable)) {
return false;
}
IPlantable plantable = (IPlantable)stack.getItem();
IPlantable plantable = (IPlantable) stack.getItem();
return plantable.getPlant(null, 0, 0, 0) == block;
}
@@ -1,9 +1,10 @@
package crazypants.enderio.machine.farm;
package crazypants.enderio.machine.farm.farmers;
import java.util.ArrayList;
import java.util.List;
import cpw.mods.fml.common.registry.GameRegistry;
import crazypants.enderio.machine.farm.TileFarmStation;
import crazypants.util.BlockCoord;
import net.minecraft.block.Block;
import net.minecraft.entity.item.EntityItem;
@@ -1,4 +1,4 @@
package crazypants.enderio.machine.farm;
package crazypants.enderio.machine.farm.farmers;
import java.util.ArrayList;
@@ -7,6 +7,7 @@ import net.minecraft.entity.item.EntityItem;
import net.minecraft.item.ItemStack;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import crazypants.enderio.machine.farm.TileFarmStation;
import crazypants.util.BlockCoord;
public class StemFarmer extends CustomSeedFarmer {
@@ -1,4 +1,4 @@
package crazypants.enderio.machine.farm;
package crazypants.enderio.machine.farm.farmers;
import java.util.ArrayList;
import java.util.Collections;
@@ -17,6 +17,7 @@ import net.minecraft.world.World;
import net.minecraftforge.common.IPlantable;
import net.minecraftforge.common.util.ForgeDirection;
import crazypants.enderio.config.Config;
import crazypants.enderio.machine.farm.TileFarmStation;
import crazypants.util.BlockCoord;
public class TreeFarmer implements IFarmerJoe {
@@ -133,6 +134,11 @@ public class TreeFarmer implements IFarmerJoe {
farm.getWorldObj().setBlockToAir(coord.x, coord.y, coord.z);
actualHarvests.add(coord);
}
if (!farm.hasAxe()) {
farm.setNotification("noAxe");
}
res.harvestedBlocks.clear();
res.harvestedBlocks.addAll(actualHarvests);