Skip to content

Commit

Permalink
Added Food Drain
Browse files Browse the repository at this point in the history
  • Loading branch information
HenryLoenwind committed Dec 28, 2015
1 parent 4488822 commit c19c4e1
Show file tree
Hide file tree
Showing 22 changed files with 235 additions and 39 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ minecraft_version=1.7.10
forge_version=10.13.4.1492-1.7.10
forgeDep_version=10.13.4

mod_version=0.9.14
mod_version=0.10.0

#Comment out this line to get rid of the appendix
mod_appendix=beta
Expand Down
Binary file added src/main/images/blockFoodDrain.pspimage
Binary file not shown.
Binary file added src/main/images/blockFoodDrainBottom.pspimage
Binary file not shown.
Binary file added src/main/images/blockFoodDrainSide.pspimage
Binary file not shown.
15 changes: 9 additions & 6 deletions src/main/java/info/loenwind/enderioaddons/config/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,17 @@

public enum Config {

drainContinuousEnergyUseRF(Section.DRAIN, 10, "The amount of power used by a drain per tick.", true, false), //
drainPerBucketEnergyUseRF(Section.DRAIN, 400, "The amount of power used by a drain per 1000mB of liquid collected."), //
drainPerSourceBlockMoveEnergyUseRF(Section.DRAIN, 250,
"The amount of power used by a drain to move a source block by one meter."), //
drainAllowOnDedicatedServer(Section.DRAIN, false, "Allow the use of the drain on a dedicated server.", true, true), //
drainCollectsMilkFromCows(Section.DRAIN, true, "Allows the drain to collect milk from cows."), //
drainContinuousEnergyUseRF(Section.DRAIN, 10, "The amount of power used by a (food) drain per tick", true, false), //
drainPerBucketEnergyUseRF(Section.DRAIN, 400, "The amount of power used by a (food) drain per 1000mB of liquid collected"), //
drainPerSourceBlockMoveEnergyUseRF(Section.DRAIN, 250, "The amount of power used by a (food) drain to move a source block by one mete."), //
drainAllowOnDedicatedServer(Section.DRAIN, false, "Allow the use of the drain on a dedicated server. This does not effect the food drain", true, true), //
drainEnabled(Section.RECIPES, true, "Enable the crafting recipe for the drain", true, true), //

foodDrainCollectsMilkFromCows(Section.DRAIN, true, "Allows the food drain to collect milk from cows."), //
foodDrainCollectsFlowingMilk(Section.DRAIN, true, "Allows the food drain to pick up flowing milk."), //
foodDrainRange(Section.DRAIN, 3d, "Distance from the food drain that is searched for cows."), //
foodDrainEnabled(Section.RECIPES, true, "Enable the crafting recipe for the food drain", true, true), //

cobbleWorksRfPerCobblestone(Section.COBBLEWORKS, 100, "RF used per generated cobblestone", true, false), //

cobbleWorksRfDiscountForCrafting(Section.COBBLEWORKS, 10,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ public int damageDropped(int par1) {
@SideOnly(Side.CLIENT)
public void getSubBlocks(Item item, CreativeTabs p_149666_2_, List list) {
list.add(new ItemStack(this, 1, 0));
list.add(new ItemStack(this, 1, 1));
}

@Override
Expand Down Expand Up @@ -142,6 +143,10 @@ protected int getGuiId() {
return GuiIds.GUI_ID_DRAIN;
}

public static boolean isFoodDrain(IBlockAccess world, int x, int y, int z) {
return world.getBlockMetadata(x, y, z) == 1;
}

@Override
@SideOnly(Side.CLIENT)
public IIcon getIcon(IBlockAccess world, int x, int y, int z, int blockSide) {
Expand All @@ -153,12 +158,18 @@ public IIcon getIcon(IBlockAccess world, int x, int y, int z, int blockSide) {
AbstractMachineEntity me = (AbstractMachineEntity) te;
facing = me.facing;
}
int side = blockSide;
int meta = world.getBlockMetadata(x, y, z);
meta = MathHelper.clamp_int(meta, 0, 1);
if (blockSide == 6) {
side = 0;
} else if (blockSide == 0) {
meta = 0;
}
if (meta == 1) {
return iconBuffer[0][ClientProxy.sideAndFacingToSpriteOffset[blockSide][facing] + 6];
return iconBuffer[0][ClientProxy.sideAndFacingToSpriteOffset[side][facing] + 6];
} else {
return iconBuffer[0][ClientProxy.sideAndFacingToSpriteOffset[blockSide][facing]];
return iconBuffer[0][ClientProxy.sideAndFacingToSpriteOffset[side][facing]];
}
}

Expand All @@ -171,7 +182,7 @@ public IIcon getIcon(int blockSide, int blockMeta) {

@Override
protected String getMachineFrontIconKey(boolean active) {
return EnderIOAddons.DOMAIN + ":blockDrainSide";
return active ? EnderIOAddons.DOMAIN + ":blockFoodDrainSide" : EnderIOAddons.DOMAIN + ":blockDrainSide";
}

@Override
Expand All @@ -186,12 +197,12 @@ protected String getBackIconKey(boolean active) {

@Override
protected String getTopIconKey(boolean active) {
return EnderIOAddons.DOMAIN + ":blockDrain";
return active ? EnderIOAddons.DOMAIN + ":blockFoodDrain" : EnderIOAddons.DOMAIN + ":blockDrain";
}

@Override
protected String getBottomIconKey(boolean active) {
return "enderio:machineTemplate";
return active ? EnderIOAddons.DOMAIN + ":blockFoodDrainBottom" : "enderio:machineTemplate";
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@
import java.util.List;

import net.minecraft.block.Block;
import net.minecraft.creativetab.CreativeTabs;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item;
import net.minecraft.item.ItemBlockWithMetadata;
import net.minecraft.item.ItemStack;

Expand All @@ -19,10 +21,26 @@ public BlockItemDrain() {

public BlockItemDrain(Block block) {
super(block, block);
setHasSubtypes(false);
setHasSubtypes(true);
setCreativeTab(EnderIOTab.tabEnderIO);
}

@Override
public String getUnlocalizedName(ItemStack par1ItemStack) {
int meta = par1ItemStack.getItemDamage();
String result = super.getUnlocalizedName(par1ItemStack);
if (meta == 1) {
result += ".food";
}
return result;
}

@Override
public void getSubItems(Item p_150895_1_, CreativeTabs p_150895_2_, List p_150895_3_) {
p_150895_3_.add(new ItemStack(p_150895_1_, 1, 0));
p_150895_3_.add(new ItemStack(p_150895_1_, 1, 1));
}

@Override
public void addCommonEntries(ItemStack itemstack, EntityPlayer entityplayer, List list, boolean flag) {
BlockDrain.blockDrain.addCommonEntries(itemstack, entityplayer, list, flag);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ public boolean renderWorldBlock(IBlockAccess world, int x, int y, int z, Block b
return true;
}

final IIcon icon_sides = BlockDrain.blockDrain.getIcon(2, 0);
final IIcon icon_bottom = BlockDrain.blockDrain.getIcon(0, 0);
final IIcon icon_sides = BlockDrain.blockDrain.getIcon(world, x, y, z, 2);
final IIcon icon_bottom = BlockDrain.blockDrain.getIcon(world, x, y, z, 6);

Tessellator.instance.addTranslation(x, y, z);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import static info.loenwind.enderioaddons.common.NullHelper.notnull;
import static info.loenwind.enderioaddons.common.NullHelper.notnullF;
import info.loenwind.enderioaddons.fluid.FluidType;
import info.loenwind.enderioaddons.machine.drain.filter.FluidFilter;

import java.util.HashSet;
import java.util.Set;
Expand Down Expand Up @@ -88,12 +89,12 @@ public static boolean isSourceBlock(@Nonnull World world, @Nonnull BlockCoord bc
ForgeDirection.EAST };

@Nullable
public static FluidHelper getInstance(@Nonnull World world, @Nonnull BlockCoord bc) {
public static FluidHelper getInstance(@Nonnull World world, @Nonnull BlockCoord bc, @Nonnull FluidFilter whitelist, @Nonnull FluidFilter blacklist) {
for (ForgeDirection forgeDirection : DIRECTIONS_INIT) {
BlockCoord direction = getLocation(bc, forgeDirection);
if (isSourceBlock(world, direction)) {
Fluid fluidForBlock = FluidRegistry.lookupFluidForBlock(direction.getBlock(world));
if (fluidForBlock != null) {
if (fluidForBlock != null && whitelist.isFluid(fluidForBlock) && !blacklist.isFluid(fluidForBlock)) {
FluidHelper result = getInstance(world, new FluidStack(fluidForBlock, 1000), direction);
if (result != null) {
return result;
Expand All @@ -104,7 +105,7 @@ public static FluidHelper getInstance(@Nonnull World world, @Nonnull BlockCoord
for (ForgeDirection forgeDirection : DIRECTIONS_INIT) {
BlockCoord direction = getLocation(bc, forgeDirection);
Fluid fluidForBlock = FluidRegistry.lookupFluidForBlock(direction.getBlock(world));
if (fluidForBlock != null) {
if (fluidForBlock != null && whitelist.isFluid(fluidForBlock) && !blacklist.isFluid(fluidForBlock)) {
FluidHelper result = getInstance(world, new FluidStack(fluidForBlock, 1000), direction);
if (result != null) {
return result;
Expand Down Expand Up @@ -158,6 +159,10 @@ public boolean isSameLiquid(@Nonnull BlockCoord bc) {
return bc.getBlock(world) == block;
}

public boolean isSameLiquid(Fluid otherFluid) {
return fluid == otherFluid;
}

public static boolean isSameLiquid(@Nonnull FluidStack fs, @Nonnull World world, @Nonnull BlockCoord bc) {
return bc.getBlock(world) == fs.getFluid().getBlock();
}
Expand Down Expand Up @@ -374,5 +379,9 @@ && isSameLiquid(getLocation(bc, downflowDirection)) && !isSourceBlock(getLocatio
}
return false;
}

public FluidStack getFluidStack() {
return stack;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
import info.loenwind.enderioaddons.config.Config;
import info.loenwind.enderioaddons.fluid.Fluids;
import info.loenwind.enderioaddons.machine.drain.FluidHelper.ReturnObject;
import info.loenwind.enderioaddons.machine.drain.filter.FoodFluidFilter;
import info.loenwind.enderioaddons.machine.drain.filter.NoFilter;
import info.loenwind.enderioaddons.machine.drain.filter.TankFilter;

import java.util.HashSet;
import java.util.List;
Expand Down Expand Up @@ -52,6 +55,8 @@ public class TileDrain extends TileEnderIOAddons implements IFluidHandler, IWate

private static final int ONE_BLOCK_OF_LIQUID = 1000;

private final static @Nonnull FoodFluidFilter filter = new FoodFluidFilter();

private static int IO_MB_TICK = 100;

@Nonnull
Expand All @@ -70,6 +75,10 @@ public TileDrain() {
super(new SlotDefinition(1, 1, 1));
}

public boolean isFoodDrain() {
return worldObj.getBlockMetadata(xCoord, yCoord, zCoord) == 1;
}

@Override
protected boolean doPush(@Nullable ForgeDirection dir) {

Expand Down Expand Up @@ -241,14 +250,26 @@ protected boolean doTick() {
}

if (shouldDoWorkThisTick(modulo) && tank.getAvailableSpace() >= ONE_BLOCK_OF_LIQUID) {
FluidHelper instance;
FluidHelper instance = null;
final FluidStack tankfluid = tank.getFluid();
if (tankfluid != null) {
instance = FluidHelper.getInstance(notnull(worldObj, "Invalid game state: World is missing"),
notnull(getLocation(), "Invalid game state: TE location is missing"), tankfluid);
if (isFoodDrain()) {
if (Config.foodDrainCollectsFlowingMilk.getBoolean()) {
if (tankfluid != null) {
instance = FluidHelper.getInstance(notnull(worldObj, "Invalid game state: World is missing"),
notnull(getLocation(), "Invalid game state: TE location is missing"), new TankFilter(tank), new NoFilter(false));
} else {
instance = FluidHelper.getInstance(notnull(worldObj, "Invalid game state: World is missing"),
notnull(getLocation(), "Invalid game state: TE location is missing"), filter, new NoFilter(false));
}
}
} else {
instance = FluidHelper.getInstance(notnull(worldObj, "Invalid game state: World is missing"),
notnull(getLocation(), "Invalid game state: TE location is missing"));
if (tankfluid != null) {
instance = FluidHelper.getInstance(notnull(worldObj, "Invalid game state: World is missing"),
notnull(getLocation(), "Invalid game state: TE location is missing"), new TankFilter(tank), filter);
} else {
instance = FluidHelper.getInstance(notnull(worldObj, "Invalid game state: World is missing"),
notnull(getLocation(), "Invalid game state: TE location is missing"), new NoFilter(true), filter);
}
}
if (instance != null) {
instance.setDrainingCallback(this);
Expand All @@ -263,17 +284,16 @@ protected boolean doTick() {
dryruncount = 0;
return true;
} else {
if (info.loenwind.enderioaddons.config.Config.drainCollectsMilkFromCows.getBoolean()) {
if (tank.getFluid() == null || tank.getFluid().getFluid() == Fluids.MILK.getFluid()) {
AxisAlignedBB bb = getBlockType().getCollisionBoundingBoxFromPool(worldObj, xCoord, yCoord, zCoord).expand(3, 1.5f, 3);
List cowsInRange = worldObj.getEntitiesWithinAABB(EntityCow.class, bb);
for (EntityCow cow : (List<EntityCow>) cowsInRange) {
if (cow.getClass() == EntityCow.class) {
fillInternal(new FluidStack(Fluids.MILK.getFluid(), 2), true);
return true;
} else {
// TODO: MooCows and other modded cows
}
if (Config.foodDrainCollectsMilkFromCows.getBoolean() && isFoodDrain() && (tankfluid == null || tankfluid.getFluid() == Fluids.MILK.getFluid())) {
AxisAlignedBB bb = getBlockType().getCollisionBoundingBoxFromPool(worldObj, xCoord, yCoord, zCoord).expand(Config.foodDrainRange.getFloat(), 1.5f,
Config.foodDrainRange.getFloat());
List cowsInRange = worldObj.getEntitiesWithinAABB(EntityCow.class, bb);
for (EntityCow cow : (List<EntityCow>) cowsInRange) {
if (cow.getClass() == EntityCow.class) {
fillInternal(new FluidStack(Fluids.MILK.getFluid(), 2), true);
return true;
} else {
// TODO: Mooshrooms, MooCows and other modded cows
}
}
}
Expand Down Expand Up @@ -348,7 +368,7 @@ public void onCapacitorTypeChange() {
@Override
public void setWorldObj(@Nullable World p_145834_1_) {
super.setWorldObj(p_145834_1_);
if (!worldObj.isRemote && !nowater.isEmpty() && !registered) {
if (!worldObj.isRemote && !nowater.isEmpty() && !registered && !isFoodDrain()) {
// actually part of readCommon(nbt), but the world object is not yet set
// when that is called
InfiniteWaterSourceStopper.getInstance().register(notnull(worldObj, "Invalid game state: World is missing"), this);
Expand All @@ -363,7 +383,7 @@ public boolean preventInfiniteWaterForming(@Nonnull World world, @Nonnull BlockC

@Override
public void onWaterDrain(@Nonnull World world, @Nonnull BlockCoord bc) {
if (!worldObj.isRemote && !registered) {
if (!worldObj.isRemote && !registered && !isFoodDrain()) {
InfiniteWaterSourceStopper.getInstance().register(notnull(worldObj, "Invalid game state: World is missing"), this);
registered = true;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package info.loenwind.enderioaddons.machine.drain.filter;

import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;

public interface FluidFilter {

boolean isFluid(FluidStack fluid);

boolean isFluid(Fluid fluid);

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package info.loenwind.enderioaddons.machine.drain.filter;

import info.loenwind.enderioaddons.fluid.Fluids;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;

public class FoodFluidFilter implements FluidFilter {
private FluidStack[] foodFluids;

public FoodFluidFilter() {
}

public FluidStack[] getFluids() {
if (foodFluids == null) {
// delay this to allow fluids to be initialized
foodFluids = new FluidStack[] { new FluidStack(Fluids.MILK.getFluid(), 0) };
}
return foodFluids;
}

@Override
public boolean isFluid(FluidStack fluid) {
if (fluid == null || fluid.getFluid() == null) {
return false;
}
for (FluidStack fluidStack : getFluids()) {
if (fluidStack.isFluidEqual(fluid)) {
return true;
}
}
return false;
}

@Override
public boolean isFluid(Fluid fluid) {
if (fluid == null) {
return false;
}
for (FluidStack fluidStack : getFluids()) {
if (fluidStack.getFluid() == fluid) {
return true;
}
}
return false;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package info.loenwind.enderioaddons.machine.drain.filter;

import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;

public class NoFilter implements FluidFilter {

private final boolean value;

public NoFilter(boolean value) {
this.value = value;
}

@Override
public boolean isFluid(FluidStack fluid) {
return value;
}

@Override
public boolean isFluid(Fluid fluid) {
return value;
}

}
Loading

0 comments on commit c19c4e1

Please sign in to comment.