mirror of
https://github.com/Ellpeck/ActuallyAdditions.git
synced 2024-12-22 19:39:24 +01:00
Finished farmer
This commit is contained in:
parent
8828b9c8a9
commit
e538ab5cad
14 changed files with 180 additions and 51 deletions
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -166,6 +166,7 @@ public final class InitBooklet{
|
|||
new BookletChapter("rangedCollector", ActuallyAdditionsAPI.entryFunctionalNonRF, new ItemStack(InitBlocks.blockRangedCollector), new PageTextOnly(1).addTextReplacement("<range>", TileEntityRangedCollector.RANGE), new PageCrafting(2, BlockCrafting.recipeRangedCollector).setNoText());
|
||||
|
||||
//RF Using Blocks
|
||||
new BookletChapter("farmer", ActuallyAdditionsAPI.entryFunctionalRF, new ItemStack(InitBlocks.blockFarmer), new PageTextOnly(1).addTextReplacement("<energy>", 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("<rf>", TileEntityFireworkBox.USE_PER_SHOT), new PageCrafting(2, BlockCrafting.recipeFireworkBox)).setSpecial();
|
||||
new BookletChapter("laserRelays", ActuallyAdditionsAPI.entryFunctionalRF, new ItemStack(InitBlocks.blockLaserRelay), new PageTextOnly(1).addTextReplacement("<range>", TileEntityLaserRelay.MAX_DISTANCE), new PageTextOnly(2).addTextReplacement("<cap1>", TileEntityLaserRelayEnergy.CAP).addTextReplacement("<cap2>", TileEntityLaserRelayEnergyAdvanced.CAP).addTextReplacement("<cap3>", 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("<rf>", TileEntityMiner.ENERGY_USE_PER_BLOCK).addTextReplacement("<range>", TileEntityMiner.DEFAULT_RANGE), new PageCrafting(2, BlockCrafting.recipeMiner)).setSpecial();
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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),
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -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));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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);
|
||||
}
|
||||
}
|
|
@ -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<ItemStack> 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<ItemStack> 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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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 }
|
||||
}
|
||||
}
|
||||
}
|
|
@ -1041,3 +1041,6 @@ booklet.actuallyadditions.chapter.distributorItem.text.1=The <item>Item Distribu
|
|||
|
||||
booklet.actuallyadditions.chapter.bioReactor.name=Bio Reactor
|
||||
booklet.actuallyadditions.chapter.bioReactor.text.1=The <item>Bio Reactor<r> uses all types of <imp>seeds, foodstuffs and plants<r> to <imp>generate RF<r>! <n>To do this, just <imp>place<r> the items <imp>in its GUI<r>. If you try this out, you will notice that it doesn't generate that much power by default. However, the more <imp>different kinds<r> 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 <item>Farmer<r> is a block that can, once placed in the world, <imp>plant and harvest<r> crops like Wheat, Potatoes, Canola <imp>and more<r>. <n>The <imp>left side<r> of its GUI is reserved for <item>seeds<r>, while the <imp>right side<r> will contain the <imp>harvested goods<r>. <n>It will farm in a <imp>9x9 area<r> in front of it. <n>For every operation, it uses <imp><energy> RF<r>. <n><n><n><i>my fam
|
Binary file not shown.
After Width: | Height: | Size: 622 B |
Binary file not shown.
After Width: | Height: | Size: 585 B |
Binary file not shown.
After Width: | Height: | Size: 521 B |
Binary file not shown.
Before Width: | Height: | Size: 1.6 KiB After Width: | Height: | Size: 1.6 KiB |
Loading…
Reference in a new issue