diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockFarmer.java b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockFarmer.java index a65750164..fc20d840c 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockFarmer.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/blocks/BlockFarmer.java @@ -29,11 +29,12 @@ import net.minecraft.tileentity.TileEntity; import net.minecraft.util.EnumFacing; import net.minecraft.util.EnumHand; import net.minecraft.util.math.BlockPos; +import net.minecraft.util.math.MathHelper; import net.minecraft.world.World; public class BlockFarmer extends BlockContainerBase{ - private static final PropertyInteger META = PropertyInteger.create("meta", 0, 5); + private static final PropertyInteger META = PropertyInteger.create("meta", 0, 3); public BlockFarmer(String name){ super(Material.ROCK, name); @@ -68,8 +69,20 @@ public class BlockFarmer extends BlockContainerBase{ @Override public void onBlockPlacedBy(World world, BlockPos pos, IBlockState state, EntityLivingBase player, ItemStack stack){ - int rotation = BlockPistonBase.getFacingFromEntity(pos, player).ordinal(); - world.setBlockState(pos, this.getStateFromMeta(rotation), 2); + int rotation = MathHelper.floor_double((double)(player.rotationYaw*4.0F/360.0F)+0.5D) & 3; + + if(rotation == 0){ + world.setBlockState(pos, this.getStateFromMeta(0), 2); + } + if(rotation == 1){ + world.setBlockState(pos, this.getStateFromMeta(3), 2); + } + if(rotation == 2){ + world.setBlockState(pos, this.getStateFromMeta(1), 2); + } + if(rotation == 3){ + world.setBlockState(pos, this.getStateFromMeta(2), 2); + } super.onBlockPlacedBy(world, pos, state, player, stack); } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/InitBooklet.java b/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/InitBooklet.java index 88eec21b2..a6694c4be 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/InitBooklet.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/booklet/InitBooklet.java @@ -166,6 +166,7 @@ public final class InitBooklet{ new BookletChapter("rangedCollector", ActuallyAdditionsAPI.entryFunctionalNonRF, new ItemStack(InitBlocks.blockRangedCollector), new PageTextOnly(1).addTextReplacement("", TileEntityRangedCollector.RANGE), new PageCrafting(2, BlockCrafting.recipeRangedCollector).setNoText()); //RF Using Blocks + new BookletChapter("farmer", ActuallyAdditionsAPI.entryFunctionalRF, new ItemStack(InitBlocks.blockFarmer), new PageTextOnly(1).addTextReplacement("", TileEntityFarmer.USE_PER_OPERATION), new PageCrafting(2, BlockCrafting.recipeFarmer).setNoText().setPageStacksWildcard()).setImportant(); new BookletChapter("fireworkBox", ActuallyAdditionsAPI.entryFunctionalRF, new ItemStack(InitBlocks.blockFireworkBox), new PageTextOnly(1).addTextReplacement("", TileEntityFireworkBox.USE_PER_SHOT), new PageCrafting(2, BlockCrafting.recipeFireworkBox)).setSpecial(); new BookletChapter("laserRelays", ActuallyAdditionsAPI.entryFunctionalRF, new ItemStack(InitBlocks.blockLaserRelay), new PageTextOnly(1).addTextReplacement("", TileEntityLaserRelay.MAX_DISTANCE), new PageTextOnly(2).addTextReplacement("", TileEntityLaserRelayEnergy.CAP).addTextReplacement("", TileEntityLaserRelayEnergyAdvanced.CAP).addTextReplacement("", TileEntityLaserRelayEnergyExtreme.CAP), new PagePicture(3, "pageLaserRelay", 0).setNoText(), new PageCrafting(4, BlockCrafting.recipeLaserRelay).setNoText().setPageStacksWildcard(), new PageCrafting(5, BlockCrafting.recipeLaserRelayAdvanced).setNoText().setPageStacksWildcard(), new PageCrafting(6, BlockCrafting.recipeLaserRelayExtreme).setNoText().setPageStacksWildcard(), new PageCrafting(7, ItemCrafting.recipeLaserWrench)).setImportant(); new BookletChapter("miner", ActuallyAdditionsAPI.entryFunctionalRF, new ItemStack(InitBlocks.blockMiner), new PageTextOnly(1).addTextReplacement("", TileEntityMiner.ENERGY_USE_PER_BLOCK).addTextReplacement("", TileEntityMiner.DEFAULT_RANGE), new PageCrafting(2, BlockCrafting.recipeMiner)).setSpecial(); diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/config/values/ConfigCrafting.java b/src/main/java/de/ellpeck/actuallyadditions/mod/config/values/ConfigCrafting.java index 64039dae4..def7dbae3 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/config/values/ConfigCrafting.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/config/values/ConfigCrafting.java @@ -155,7 +155,8 @@ public enum ConfigCrafting{ BAG("Bag", ConfigCategories.ITEMS_CRAFTING), VOID_BAG("Void Bag", ConfigCategories.ITEMS_CRAFTING), EMPOWERER("Empowerer", ConfigCategories.BLOCKS_CRAFTING), - DISTRIBUTOR_ITEM("Item Distributor", ConfigCategories.BLOCKS_CRAFTING); + DISTRIBUTOR_ITEM("Item Distributor", ConfigCategories.BLOCKS_CRAFTING), + FARMER("Farmer", ConfigCategories.BLOCKS_CRAFTING); public final String name; public final String category; diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/BlockCrafting.java b/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/BlockCrafting.java index b1fbf76d6..7abc7b9b6 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/BlockCrafting.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/crafting/BlockCrafting.java @@ -98,9 +98,20 @@ public final class BlockCrafting{ public static IRecipe recipeFluidLaser; public static IRecipe recipeDistributorItem; public static IRecipe recipeBioReactor; + public static IRecipe recipeFarmer; public static void init(){ + //Farmer + if(ConfigCrafting.FARMER.isEnabled()){ + GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(InitBlocks.blockFarmer), + "ISI", "SCS", "ISI", + 'I', new ItemStack(InitBlocks.blockCrystal, 1, TheCrystals.IRON.ordinal()), + 'C', new ItemStack(InitBlocks.blockMisc, 1, TheMiscBlocks.IRON_CASING.ordinal()), + 'S', new ItemStack(Items.WHEAT_SEEDS))); + recipeFarmer = RecipeUtil.lastIRecipe(); + } + //Empowerer if(ConfigCrafting.EMPOWERER.isEnabled()){ GameRegistry.addRecipe(new ShapedOreRecipe(new ItemStack(InitBlocks.blockEmpowerer), diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/creative/CreativeTab.java b/src/main/java/de/ellpeck/actuallyadditions/mod/creative/CreativeTab.java index 65e9b3dad..2b775dd33 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/creative/CreativeTab.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/creative/CreativeTab.java @@ -84,6 +84,7 @@ public class CreativeTab extends CreativeTabs{ this.add(InitBlocks.blockDisplayStand); this.add(InitBlocks.blockDistributorItem); + this.add(InitBlocks.blockFarmer); this.add(InitBlocks.blockShockSuppressor); this.add(InitBlocks.blockMiner); this.add(InitBlocks.blockGreenhouseGlass); diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/ContainerFarmer.java b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/ContainerFarmer.java index 4f9635d5c..945981eea 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/ContainerFarmer.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/ContainerFarmer.java @@ -30,12 +30,12 @@ public class ContainerFarmer extends Container{ for(int i = 0; i < 3; i++){ for(int j = 0; j < 2; j++){ - this.addSlotToContainer(new Slot(this.farmer, j+i*2, 53+j*18, 21+i*18)); + this.addSlotToContainer(new Slot(this.farmer, j+i*2, 67+j*18, 21+i*18)); } } for(int i = 0; i < 3; i++){ for(int j = 0; j < 2; j++){ - this.addSlotToContainer(new Slot(this.farmer, 6+j+i*2, 91+j*18, 21+i*18)); + this.addSlotToContainer(new Slot(this.farmer, 6+j+i*2, 105+j*18, 21+i*18)); } } diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiFarmer.java b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiFarmer.java index 79bfadb98..c8b3ab1a1 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiFarmer.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/inventory/gui/GuiFarmer.java @@ -21,12 +21,16 @@ import net.minecraft.util.ResourceLocation; import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.SideOnly; +import java.io.IOException; + @SideOnly(Side.CLIENT) public class GuiFarmer extends GuiContainer{ private static final ResourceLocation RES_LOC = AssetUtil.getGuiLocation("guiFarmer"); private final TileEntityFarmer farmer; + private EnergyDisplay energy; + public GuiFarmer(InventoryPlayer inventory, TileEntityBase tile){ super(new ContainerFarmer(inventory, tile)); this.farmer = (TileEntityFarmer)tile; @@ -34,6 +38,13 @@ public class GuiFarmer extends GuiContainer{ this.ySize = 93+86; } + @Override + public void initGui(){ + super.initGui(); + + this.energy = new EnergyDisplay(this.guiLeft+33, this.guiTop+6, this.farmer.storage); + } + @Override public void drawGuiContainerForegroundLayer(int x, int y){ AssetUtil.displayNameString(this.fontRendererObj, this.xSize, -10, this.farmer); @@ -48,5 +59,21 @@ public class GuiFarmer extends GuiContainer{ this.mc.getTextureManager().bindTexture(RES_LOC); this.drawTexturedModalRect(this.guiLeft, this.guiTop, 0, 0, 176, 93); + + this.energy.draw(); + } + + + @Override + protected void mouseClicked(int mouseX, int mouseY, int mouseButton) throws IOException{ + super.mouseClicked(mouseX, mouseY, mouseButton); + this.energy.onMouseClick(mouseX, mouseY, mouseButton); + } + + + @Override + public void drawScreen(int x, int y, float f){ + super.drawScreen(x, y, f); + this.energy.drawOverlay(x, y); } } \ No newline at end of file diff --git a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityFarmer.java b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityFarmer.java index 910f8dfd1..6939797da 100644 --- a/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityFarmer.java +++ b/src/main/java/de/ellpeck/actuallyadditions/mod/tile/TileEntityFarmer.java @@ -10,6 +10,7 @@ package de.ellpeck.actuallyadditions.mod.tile; +import cofh.api.energy.EnergyStorage; import de.ellpeck.actuallyadditions.mod.config.values.ConfigBoolValues; import de.ellpeck.actuallyadditions.mod.util.WorldUtil; import net.minecraft.block.*; @@ -26,12 +27,17 @@ import net.minecraftforge.common.IPlantable; import java.util.List; -public class TileEntityFarmer extends TileEntityInventoryBase{ +public class TileEntityFarmer extends TileEntityInventoryBase implements ICustomEnergyReceiver{ + + public static final int USE_PER_OPERATION = 1500; + public final EnergyStorage storage = new EnergyStorage(100000); private int waitTime; private int checkX; private int checkY; + private int lastEnergy; + public TileEntityFarmer(){ super(12, "farmer"); } @@ -44,6 +50,7 @@ public class TileEntityFarmer extends TileEntityInventoryBase{ compound.setInteger("CheckX", this.checkX); compound.setInteger("CheckY", this.checkY); } + this.storage.writeToNBT(compound); } @Override @@ -54,70 +61,89 @@ public class TileEntityFarmer extends TileEntityInventoryBase{ this.checkX = compound.getInteger("CheckX"); this.checkY = compound.getInteger("CheckY"); } + this.storage.readFromNBT(compound); } @Override public void updateEntity(){ super.updateEntity(); - if(!this.worldObj.isRemote && !this.isRedstonePowered){ - if(this.waitTime > 0){ - this.waitTime--; + if(!this.worldObj.isRemote){ + if(!this.isRedstonePowered){ + if(this.waitTime > 0){ + this.waitTime--; - if(this.waitTime <= 0){ - int radiusAroundCenter = 4; + if(this.waitTime <= 0){ + if(this.storage.getEnergyStored() >= USE_PER_OPERATION){ + boolean didSomething = false; - IBlockState state = this.worldObj.getBlockState(this.pos); - EnumFacing side = WorldUtil.getDirectionByPistonRotation(state.getBlock().getMetaFromState(state)); - BlockPos center = this.pos.offset(side, radiusAroundCenter+1); + int radiusAroundCenter = 4; - BlockPos plant = center.add(this.checkX, 0, this.checkY); - IBlockState plantState = this.worldObj.getBlockState(plant); - Block plantBlock = plantState.getBlock(); + IBlockState state = this.worldObj.getBlockState(this.pos); + int meta = state.getBlock().getMetaFromState(state); + EnumFacing side = meta == 0 ? EnumFacing.NORTH : (meta == 1 ? EnumFacing.SOUTH : (meta == 2 ? EnumFacing.WEST : EnumFacing.EAST)); + BlockPos center = this.pos.offset(side, radiusAroundCenter+1); - if(plantBlock instanceof BlockCrops){ - if(((BlockCrops)plantBlock).isMaxAge(plantState)){ - List drops = plantBlock.getDrops(this.worldObj, plant, plantState, 0); + BlockPos plant = center.add(this.checkX, 0, this.checkY); + IBlockState plantState = this.worldObj.getBlockState(plant); + Block plantBlock = plantState.getBlock(); - if(WorldUtil.addToInventory(this, 6, 12, drops, EnumFacing.UP, false, true)){ - WorldUtil.addToInventory(this, 6, 12, drops, EnumFacing.UP, true, true); + if(plantBlock instanceof BlockCrops){ + if(((BlockCrops)plantBlock).isMaxAge(plantState)){ + List drops = plantBlock.getDrops(this.worldObj, plant, plantState, 0); - if(!ConfigBoolValues.LESS_BLOCK_BREAKING_EFFECTS.isEnabled()){ - this.worldObj.playEvent(2001, plant, Block.getStateId(plantState)); + if(WorldUtil.addToInventory(this, 6, 12, drops, EnumFacing.UP, false, true)){ + WorldUtil.addToInventory(this, 6, 12, drops, EnumFacing.UP, true, true); + + if(!ConfigBoolValues.LESS_BLOCK_BREAKING_EFFECTS.isEnabled()){ + this.worldObj.playEvent(2001, plant, Block.getStateId(plantState)); + } + this.worldObj.setBlockToAir(plant); + didSomething = true; + } } - this.worldObj.setBlockToAir(plant); } - } - } - else if(plantBlock.isReplaceable(this.worldObj, plant)){ - BlockPos farmland = plant.down(); - IBlockState farmlandState = this.worldObj.getBlockState(farmland); - Block farmlandBlock = farmlandState.getBlock(); + else if(plantBlock.isReplaceable(this.worldObj, plant)){ + BlockPos farmland = plant.down(); + IBlockState farmlandState = this.worldObj.getBlockState(farmland); + Block farmlandBlock = farmlandState.getBlock(); - if(farmlandBlock instanceof BlockFarmland){ - IBlockState toPlant = this.getFirstPlantFromSlots(plant); - if(toPlant != null){ - this.worldObj.setBlockState(plant, toPlant, 2); + if(farmlandBlock instanceof BlockFarmland){ + IBlockState toPlant = this.getFirstPlantFromSlots(plant); + if(toPlant != null){ + this.worldObj.setBlockState(plant, toPlant, 2); + didSomething = true; + } + } + else if(farmlandBlock instanceof BlockDirt || farmlandBlock instanceof BlockGrass){ + this.worldObj.setBlockState(farmland, Blocks.FARMLAND.getDefaultState(), 2); + this.worldObj.setBlockToAir(plant); + this.worldObj.playSound(null, farmland, SoundEvents.ITEM_HOE_TILL, SoundCategory.BLOCKS, 1.0F, 1.0F); + didSomething = true; + } } - } - else if(farmlandBlock instanceof BlockDirt || farmlandBlock instanceof BlockGrass){ - this.worldObj.setBlockState(farmland, Blocks.FARMLAND.getDefaultState(), 2); - this.worldObj.setBlockToAir(plant); - this.worldObj.playSound(null, farmland, SoundEvents.ITEM_HOE_TILL, SoundCategory.BLOCKS, 1.0F, 1.0F); - } - } - this.checkX++; - if(this.checkX > radiusAroundCenter){ - this.checkX = -radiusAroundCenter; - this.checkY++; - if(this.checkY > radiusAroundCenter){ - this.checkY = -radiusAroundCenter; + if(didSomething){ + this.storage.extractEnergy(USE_PER_OPERATION, false); + } + + this.checkX++; + if(this.checkX > radiusAroundCenter){ + this.checkX = -radiusAroundCenter; + this.checkY++; + if(this.checkY > radiusAroundCenter){ + this.checkY = -radiusAroundCenter; + } + } } } } + else{ + this.waitTime = 5; + } } - else{ - this.waitTime = 5; + + if(this.lastEnergy != this.storage.getEnergyStored() && this.sendUpdateWithInterval()){ + this.lastEnergy = this.storage.getEnergyStored(); } } } @@ -153,4 +179,24 @@ public class TileEntityFarmer extends TileEntityInventoryBase{ public boolean canExtractItem(int slot, ItemStack stack, EnumFacing side){ return slot >= 6; } + + @Override + public int receiveEnergy(EnumFacing from, int maxReceive, boolean simulate){ + return this.storage.receiveEnergy(maxReceive, simulate); + } + + @Override + public int getEnergyStored(EnumFacing from){ + return this.storage.getEnergyStored(); + } + + @Override + public int getMaxEnergyStored(EnumFacing from){ + return this.storage.getMaxEnergyStored(); + } + + @Override + public boolean canConnectEnergy(EnumFacing from){ + return true; + } } diff --git a/src/main/resources/assets/actuallyadditions/blockstates/blockFarmer.json b/src/main/resources/assets/actuallyadditions/blockstates/blockFarmer.json new file mode 100644 index 000000000..ce14b7668 --- /dev/null +++ b/src/main/resources/assets/actuallyadditions/blockstates/blockFarmer.json @@ -0,0 +1,26 @@ +{ + "forge_marker": 1, + "defaults": { + "model": "minecraft:cube", + "textures": { + "particle": "actuallyadditions:blocks/blockFarmer", + "down": "#particle", + "up": "actuallyadditions:blocks/blockFarmerTop", + "south": "#particle", + "north": "actuallyadditions:blocks/blockFarmerFront", + "east": "#particle", + "west": "#particle" + }, + "transform": "forge:default-block" + }, + "variants": { + "normal": [{}], + "inventory": [{}], + "meta": { + "0": { "y" : 0 }, + "1": { "y" : 180 }, + "2": { "y" : 270 }, + "3": { "y" : 90 } + } + } +} \ No newline at end of file diff --git a/src/main/resources/assets/actuallyadditions/lang/en_US.lang b/src/main/resources/assets/actuallyadditions/lang/en_US.lang index e8333053d..aa932d98d 100644 --- a/src/main/resources/assets/actuallyadditions/lang/en_US.lang +++ b/src/main/resources/assets/actuallyadditions/lang/en_US.lang @@ -1041,3 +1041,6 @@ booklet.actuallyadditions.chapter.distributorItem.text.1=The Item Distribu booklet.actuallyadditions.chapter.bioReactor.name=Bio Reactor booklet.actuallyadditions.chapter.bioReactor.text.1=The Bio Reactor uses all types of seeds, foodstuffs and plants to generate RF! To do this, just place the items in its GUI. If you try this out, you will notice that it doesn't generate that much power by default. However, the more different kinds of plants, seeds and foodstuffs it has, the more power it will generate! + +booklet.actuallyadditions.chapter.farmer.name=Farmer +booklet.actuallyadditions.chapter.farmer.text.1=The Farmer is a block that can, once placed in the world, plant and harvest crops like Wheat, Potatoes, Canola and more. The left side of its GUI is reserved for seeds, while the right side will contain the harvested goods. It will farm in a 9x9 area in front of it. For every operation, it uses RF. my fam \ No newline at end of file diff --git a/src/main/resources/assets/actuallyadditions/textures/blocks/blockFarmer.png b/src/main/resources/assets/actuallyadditions/textures/blocks/blockFarmer.png new file mode 100644 index 000000000..6e8f33296 Binary files /dev/null and b/src/main/resources/assets/actuallyadditions/textures/blocks/blockFarmer.png differ diff --git a/src/main/resources/assets/actuallyadditions/textures/blocks/blockFarmerFront.png b/src/main/resources/assets/actuallyadditions/textures/blocks/blockFarmerFront.png new file mode 100644 index 000000000..c6f964800 Binary files /dev/null and b/src/main/resources/assets/actuallyadditions/textures/blocks/blockFarmerFront.png differ diff --git a/src/main/resources/assets/actuallyadditions/textures/blocks/blockFarmerTop.png b/src/main/resources/assets/actuallyadditions/textures/blocks/blockFarmerTop.png new file mode 100644 index 000000000..1b0b4d804 Binary files /dev/null and b/src/main/resources/assets/actuallyadditions/textures/blocks/blockFarmerTop.png differ diff --git a/src/main/resources/assets/actuallyadditions/textures/gui/guiFarmer.png b/src/main/resources/assets/actuallyadditions/textures/gui/guiFarmer.png index 2aafa3562..eb0ce9f98 100644 Binary files a/src/main/resources/assets/actuallyadditions/textures/gui/guiFarmer.png and b/src/main/resources/assets/actuallyadditions/textures/gui/guiFarmer.png differ