This commit is contained in:
Ellpeck 2016-10-31 18:03:18 +01:00
parent 508ae87bdf
commit 8828b9c8a9
9 changed files with 415 additions and 1 deletions

View file

@ -0,0 +1,87 @@
/*
* This file ("BlockFarmer.java") is part of the Actually Additions mod for Minecraft.
* It is created and owned by Ellpeck and distributed
* under the Actually Additions License to be found at
* http://ellpeck.de/actaddlicense
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
* © 2015-2016 Ellpeck
*/
package de.ellpeck.actuallyadditions.mod.blocks;
import de.ellpeck.actuallyadditions.mod.ActuallyAdditions;
import de.ellpeck.actuallyadditions.mod.blocks.base.BlockContainerBase;
import de.ellpeck.actuallyadditions.mod.inventory.GuiHandler;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityBreaker;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityFarmer;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityPlacer;
import net.minecraft.block.BlockPistonBase;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.PropertyInteger;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
public class BlockFarmer extends BlockContainerBase{
private static final PropertyInteger META = PropertyInteger.create("meta", 0, 5);
public BlockFarmer(String name){
super(Material.ROCK, name);
this.setHarvestLevel("pickaxe", 0);
this.setHardness(1.5F);
this.setResistance(10.0F);
this.setSoundType(SoundType.STONE);
}
@Override
public TileEntity createNewTileEntity(World world, int par2){
return new TileEntityFarmer();
}
@Override
public boolean onBlockActivated(World world, BlockPos pos, IBlockState state, EntityPlayer player, EnumHand hand, ItemStack stack, EnumFacing par6, float par7, float par8, float par9){
if(!world.isRemote){
TileEntityFarmer farmer = (TileEntityFarmer)world.getTileEntity(pos);
if(farmer != null){
player.openGui(ActuallyAdditions.instance, GuiHandler.GuiTypes.FARMER.ordinal(), world, pos.getX(), pos.getY(), pos.getZ());
}
return true;
}
return true;
}
@Override
public EnumRarity getRarity(ItemStack stack){
return EnumRarity.RARE;
}
@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);
super.onBlockPlacedBy(world, pos, state, player, stack);
}
@Override
protected PropertyInteger getMetaProperty(){
return META;
}
@Override
public void breakBlock(World world, BlockPos pos, IBlockState state){
this.dropInventory(world, pos);
super.breakBlock(world, pos, state);
}
}

View file

@ -108,10 +108,12 @@ public final class InitBlocks{
public static Block blockDistributorItem;
public static Block blockBioReactor;
public static Block blockTinyTorch;
public static Block blockFarmer;
public static void init(){
ModUtil.LOGGER.info("Initializing Blocks...");
blockFarmer = new BlockFarmer("blockFarmer");
blockBioReactor = new BlockBioReactor("blockBioReactor");
blockDistributorItem = new BlockDistributorItem("blockDistributorItem");
blockEmpowerer = new BlockEmpowerer("blockEmpowerer");

View file

@ -0,0 +1,109 @@
/*
* This file ("ContainerFarmer.java") is part of the Actually Additions mod for Minecraft.
* It is created and owned by Ellpeck and distributed
* under the Actually Additions License to be found at
* http://ellpeck.de/actaddlicense
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
* © 2015-2016 Ellpeck
*/
package de.ellpeck.actuallyadditions.mod.inventory;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityBase;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityFarmer;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityFurnaceDouble;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.inventory.Container;
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;
import net.minecraftforge.common.IPlantable;
public class ContainerFarmer extends Container{
private final TileEntityFarmer farmer;
public ContainerFarmer(InventoryPlayer inventory, TileEntityBase tile){
this.farmer = (TileEntityFarmer)tile;
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));
}
}
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));
}
}
for(int i = 0; i < 3; i++){
for(int j = 0; j < 9; j++){
this.addSlotToContainer(new Slot(inventory, j+i*9+9, 8+j*18, 97+i*18));
}
}
for(int i = 0; i < 9; i++){
this.addSlotToContainer(new Slot(inventory, i, 8+i*18, 155));
}
}
@Override
public ItemStack transferStackInSlot(EntityPlayer player, int slot){
int inventoryStart = 12;
int inventoryEnd = inventoryStart+26;
int hotbarStart = inventoryEnd+1;
int hotbarEnd = hotbarStart+8;
Slot theSlot = this.inventorySlots.get(slot);
if(theSlot != null && theSlot.getHasStack()){
ItemStack newStack = theSlot.getStack();
ItemStack currentStack = newStack.copy();
//Other Slots in Inventory excluded
if(slot >= inventoryStart){
//Shift from Inventory
if(newStack.getItem() instanceof IPlantable){
if(!this.mergeItemStack(newStack, 0, 6, false)){
return null;
}
}
//
else if(slot >= inventoryStart && slot <= inventoryEnd){
if(!this.mergeItemStack(newStack, hotbarStart, hotbarEnd+1, false)){
return null;
}
}
else if(slot >= inventoryEnd+1 && slot < hotbarEnd+1 && !this.mergeItemStack(newStack, inventoryStart, inventoryEnd+1, false)){
return null;
}
}
else if(!this.mergeItemStack(newStack, inventoryStart, hotbarEnd+1, false)){
return null;
}
if(newStack.stackSize <= 0){
theSlot.putStack(null);
}
else{
theSlot.onSlotChanged();
}
if(newStack.stackSize == currentStack.stackSize){
return null;
}
theSlot.onPickupFromSlot(player, newStack);
return currentStack;
}
return null;
}
@Override
public boolean canInteractWith(EntityPlayer player){
return this.farmer.isUseableByPlayer(player);
}
}

View file

@ -102,6 +102,8 @@ public class GuiHandler implements IGuiHandler{
return new ContainerBag(player.inventory, true);
case BIO_REACTOR:
return new ContainerBioReactor(player.inventory, tile);
case FARMER:
return new ContainerFarmer(player.inventory, tile);
default:
return null;
}
@ -184,6 +186,8 @@ public class GuiHandler implements IGuiHandler{
return new GuiBag(player.inventory, true);
case BIO_REACTOR:
return new GuiBioReactor(player.inventory, tile);
case FARMER:
return new GuiFarmer(player.inventory, tile);
default:
return null;
}
@ -224,7 +228,8 @@ public class GuiHandler implements IGuiHandler{
FILTER(false),
BAG(false),
VOID_BAG(false),
BIO_REACTOR;
BIO_REACTOR,
FARMER;
public final boolean checkTileEntity;

View file

@ -0,0 +1,52 @@
/*
* This file ("GuiFarmer.java") is part of the Actually Additions mod for Minecraft.
* It is created and owned by Ellpeck and distributed
* under the Actually Additions License to be found at
* http://ellpeck.de/actaddlicense
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
* © 2015-2016 Ellpeck
*/
package de.ellpeck.actuallyadditions.mod.inventory.gui;
import de.ellpeck.actuallyadditions.mod.inventory.ContainerFarmer;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityBase;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityFarmer;
import de.ellpeck.actuallyadditions.mod.util.AssetUtil;
import net.minecraft.client.gui.inventory.GuiContainer;
import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.entity.player.InventoryPlayer;
import net.minecraft.util.ResourceLocation;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class GuiFarmer extends GuiContainer{
private static final ResourceLocation RES_LOC = AssetUtil.getGuiLocation("guiFarmer");
private final TileEntityFarmer farmer;
public GuiFarmer(InventoryPlayer inventory, TileEntityBase tile){
super(new ContainerFarmer(inventory, tile));
this.farmer = (TileEntityFarmer)tile;
this.xSize = 176;
this.ySize = 93+86;
}
@Override
public void drawGuiContainerForegroundLayer(int x, int y){
AssetUtil.displayNameString(this.fontRendererObj, this.xSize, -10, this.farmer);
}
@Override
public void drawGuiContainerBackgroundLayer(float f, int x, int y){
GlStateManager.color(1.0F, 1.0F, 1.0F, 1.0F);
this.mc.getTextureManager().bindTexture(AssetUtil.GUI_INVENTORY_LOCATION);
this.drawTexturedModalRect(this.guiLeft, this.guiTop+93, 0, 0, 176, 86);
this.mc.getTextureManager().bindTexture(RES_LOC);
this.drawTexturedModalRect(this.guiLeft, this.guiTop, 0, 0, 176, 93);
}
}

View file

@ -109,6 +109,7 @@ public abstract class TileEntityBase extends TileEntity implements ITickable{
register(TileEntityLaserRelayFluids.class);
register(TileEntityDistributorItem.class);
register(TileEntityBioReactor.class);
register(TileEntityFarmer.class);
}
private static void register(Class<? extends TileEntityBase> tileClass){

View file

@ -0,0 +1,156 @@
/*
* This file ("TileEntityFarmer.java") is part of the Actually Additions mod for Minecraft.
* It is created and owned by Ellpeck and distributed
* under the Actually Additions License to be found at
* http://ellpeck.de/actaddlicense
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
* © 2015-2016 Ellpeck
*/
package de.ellpeck.actuallyadditions.mod.tile;
import de.ellpeck.actuallyadditions.mod.config.values.ConfigBoolValues;
import de.ellpeck.actuallyadditions.mod.util.WorldUtil;
import net.minecraft.block.*;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks;
import net.minecraft.init.SoundEvents;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.SoundCategory;
import net.minecraft.util.math.BlockPos;
import net.minecraftforge.common.IPlantable;
import java.util.List;
public class TileEntityFarmer extends TileEntityInventoryBase{
private int waitTime;
private int checkX;
private int checkY;
public TileEntityFarmer(){
super(12, "farmer");
}
@Override
public void writeSyncableNBT(NBTTagCompound compound, NBTType type){
super.writeSyncableNBT(compound, type);
if(type != NBTType.SAVE_BLOCK){
compound.setInteger("WaitTime", this.waitTime);
compound.setInteger("CheckX", this.checkX);
compound.setInteger("CheckY", this.checkY);
}
}
@Override
public void readSyncableNBT(NBTTagCompound compound, NBTType type){
super.readSyncableNBT(compound, type);
if(type != NBTType.SAVE_BLOCK){
this.waitTime = compound.getInteger("WaitTime");
this.checkX = compound.getInteger("CheckX");
this.checkY = compound.getInteger("CheckY");
}
}
@Override
public void updateEntity(){
super.updateEntity();
if(!this.worldObj.isRemote && !this.isRedstonePowered){
if(this.waitTime > 0){
this.waitTime--;
if(this.waitTime <= 0){
int radiusAroundCenter = 4;
IBlockState state = this.worldObj.getBlockState(this.pos);
EnumFacing side = WorldUtil.getDirectionByPistonRotation(state.getBlock().getMetaFromState(state));
BlockPos center = this.pos.offset(side, radiusAroundCenter+1);
BlockPos plant = center.add(this.checkX, 0, this.checkY);
IBlockState plantState = this.worldObj.getBlockState(plant);
Block plantBlock = plantState.getBlock();
if(plantBlock instanceof BlockCrops){
if(((BlockCrops)plantBlock).isMaxAge(plantState)){
List<ItemStack> drops = plantBlock.getDrops(this.worldObj, plant, plantState, 0);
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);
}
}
}
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);
}
}
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;
}
}
}
}
else{
this.waitTime = 5;
}
}
}
private IBlockState getFirstPlantFromSlots(BlockPos pos){
for(int i = 0; i < 6; i++){
ItemStack stack = this.slots[i];
if(stack != null){
Item item = stack.getItem();
if(item instanceof IPlantable){
IBlockState state = ((IPlantable)item).getPlant(this.worldObj, pos);
if(state != null){
this.decrStackSize(i, 1);
return state;
}
}
}
}
return null;
}
@Override
public boolean isItemValidForSlot(int i, ItemStack stack){
return i < 6 && stack != null && stack.getItem() instanceof IPlantable;
}
@Override
public boolean canInsertItem(int slot, ItemStack stack, EnumFacing side){
return this.isItemValidForSlot(slot, stack);
}
@Override
public boolean canExtractItem(int slot, ItemStack stack, EnumFacing side){
return slot >= 6;
}
}

View file

@ -229,6 +229,7 @@ tile.actuallyadditions.blockTinyTorch.name=Tiny Torch
tile.actuallyadditions.blockEmpowerer.name=Empowerer
tile.actuallyadditions.blockDistributorItem.name=Item Distributor
tile.actuallyadditions.blockBioReactor.name=Bio Reactor
tile.actuallyadditions.blockFarmer.name=Farmer
#ESD
tile.actuallyadditions.blockInputter.name=ESD
@ -635,6 +636,7 @@ container.actuallyadditions.filter.name=Item Filter
container.actuallyadditions.bag.name=Traveler's Sack
container.actuallyadditions.voidBag.name=Void Sack
container.actuallyadditions.bioReactor.name=Bio Reactor
container.actuallyadditions.farmer.name=Farmer
#Update Information
info.actuallyadditions.update.generic=[{"text":"There is an Update for "},{"text":"Actually Additions ","color":"dark_green"},{"text":"available!","color":"none"}]

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.6 KiB