Added nut. fluid. use to killer joe.

This commit is contained in:
CrazyPants committed 2014-08-12 15:48:39 +08:00
1 parent 3d09a6a3b4
commit 490f32c3de
6 files changed
+247 -14

No files matched your search

@@ -56,6 +56,7 @@ public final class Config {
public static final Section sectionMagnet = new Section("Magnet Settings", "magnet");
public static final Section sectionFluid = new Section("Fluid Settings", "fluid");
public static final Section sectionSpawner = new Section("PoweredSpawner Settings", "spawner");
public static final Section sectionKiller = new Section("Killer Joe Settings", "spawner");
static int BID = 700;
static int IID = 8524;
@@ -241,6 +242,8 @@ public final class Config {
public static float machineSoundVolume = 0.75f;
public static int killerJoeNutrientUsePerAttackMb = 10;
public static void load(FMLPreInitializationEvent event) {
FMLCommonHandler.instance().bus().register(new Config());
@@ -631,6 +634,9 @@ public final class Config {
"If true copper and tin will be used in recipes when registered in the ore dictionary").getBoolean(useModMetals);
nutrientFoodBoostDelay = config.get(sectionFluid.name, "nutrientFluidFoodBoostDelay", nutrientFoodBoostDelay, "The delay in ticks between when nutrient distillation boosts your food value.").getInt((int)nutrientFoodBoostDelay);
killerJoeNutrientUsePerAttackMb = config.get(sectionKiller.name, "killerJoeNutrientUsePerAttackMb", killerJoeNutrientUsePerAttackMb,
"The number of millibuckets of nutrient fluid used per attack.").getInt(killerJoeNutrientUsePerAttackMb);
}
private Config() {
@@ -17,6 +17,10 @@ public class NutrientTank extends FluidTank {
}
return super.fill(resource, doFill);
}
public float getFilledRatio() {
return (float) getFluidAmount() / getCapacity();
}
@@ -210,8 +210,11 @@ public class TileZombieGenerator extends AbstractMachineEntity implements IPower
if(resource == null || resource.getFluid() == null || !canFill(from, resource.getFluid())) {
return 0;
}
tanksDirty = true;
return fuelTank.fill(resource, doFill);
int res = fuelTank.fill(resource, doFill);
if(res > 0 && doFill) {
tanksDirty = true;
}
return res;
}
@Override
@@ -2,14 +2,22 @@ package crazypants.enderio.machine.killera;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.FluidStack;
import cpw.mods.fml.relauncher.Side;
import crazypants.enderio.ModObject;
import crazypants.enderio.machine.AbstractMachineBlock;
import crazypants.enderio.machine.generator.zombie.PacketZombieTank;
import crazypants.enderio.machine.generator.zombie.TileZombieGenerator;
import crazypants.enderio.machine.tank.BlockTank;
import crazypants.enderio.machine.tank.PacketTank;
import crazypants.enderio.machine.tank.TileTank;
import crazypants.enderio.network.PacketHandler;
import crazypants.util.FluidUtil;
import crazypants.util.Util;
/**
* Name proudly created by Xaw4
@@ -17,7 +25,7 @@ import crazypants.enderio.network.PacketHandler;
public class BlockKillerJoe extends AbstractMachineBlock<TileKillerJoe> {
public static BlockKillerJoe create() {
//PacketHandler.INSTANCE.registerMessage(PacketTank.class, PacketTank.class, PacketHandler.nextID(), Side.CLIENT);
PacketHandler.INSTANCE.registerMessage(PacketNutrientLevel.class, PacketNutrientLevel.class, PacketHandler.nextID(), Side.CLIENT);
BlockKillerJoe res = new BlockKillerJoe();
res.init();
return res;
@@ -27,6 +35,36 @@ public class BlockKillerJoe extends AbstractMachineBlock<TileKillerJoe> {
super(ModObject.blockKillerJoe, TileKillerJoe.class);
setStepSound(Block.soundTypeGlass);
}
@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer entityPlayer, int par6, float par7, float par8, float par9) {
TileEntity te = world.getTileEntity(x, y, z);
if(!(te instanceof TileKillerJoe)) {
return super.onBlockActivated(world, x, y, z, entityPlayer, par6, par7, par8, par9);
}
TileKillerJoe gen = (TileKillerJoe) te;
ItemStack item = entityPlayer.inventory.getCurrentItem();
if(item == null) {
return super.onBlockActivated(world, x, y, z, entityPlayer, par6, par7, par8, par9);
}
//check for filled fluid containers and see if we can empty them into our tank
FluidStack fluid = FluidUtil.getFluidFromItem(item);
if(fluid != null) {
int filled = gen.fill(ForgeDirection.UP, fluid, false);
if(filled >= fluid.amount) {
gen.fill(ForgeDirection.UP, fluid, true);
if(!entityPlayer.capabilities.isCreativeMode) {
entityPlayer.inventory.setInventorySlotContents(entityPlayer.inventory.currentItem, Util.consumeItem(item));
}
return true;
}
}
return super.onBlockActivated(world, x, y, z, entityPlayer, par6, par7, par8, par9);
}
@Override
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
@@ -0,0 +1,57 @@
package crazypants.enderio.machine.killera;
import io.netty.buffer.ByteBuf;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.nbt.NBTTagCompound;
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;
import crazypants.enderio.network.NetworkUtil;
public class PacketNutrientLevel extends MessageTileEntity<TileKillerJoe> implements IMessageHandler<PacketNutrientLevel, IMessage> {
private NBTTagCompound nbtRoot;
public PacketNutrientLevel() {
}
public PacketNutrientLevel(TileKillerJoe tile) {
super(tile);
nbtRoot = new NBTTagCompound();
if(tile.fuelTank.getFluidAmount() > 0) {
NBTTagCompound tankRoot = new NBTTagCompound();
tile.fuelTank.writeToNBT(tankRoot);
nbtRoot.setTag("tank", tankRoot);
}
}
@Override
public void toBytes(ByteBuf buf) {
super.toBytes(buf);
NetworkUtil.writeNBTTagCompound(nbtRoot, buf);
}
@Override
public void fromBytes(ByteBuf buf) {
super.fromBytes(buf);
nbtRoot = NetworkUtil.readNBTTagCompound(buf);
}
@Override
public IMessage onMessage(PacketNutrientLevel message, MessageContext ctx) {
EntityPlayer player = EnderIO.proxy.getClientPlayer();
TileKillerJoe tile = message.getTileEntity(player.worldObj);
if (tile != null) {
if(message.nbtRoot.hasKey("tank")) {
NBTTagCompound tankRoot = message.nbtRoot.getCompoundTag("tank");
tile.fuelTank.readFromNBT(tankRoot);
} else {
tile.fuelTank.setFluid(null);
}
}
return null;
}
}
@@ -19,32 +19,46 @@ import net.minecraft.entity.boss.EntityDragonPart;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemSword;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.server.MinecraftServer;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.DamageSource;
import net.minecraftforge.common.util.FakePlayer;
import net.minecraftforge.common.util.ForgeDirection;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTankInfo;
import net.minecraftforge.fluids.IFluidHandler;
import crazypants.enderio.EnderIO;
import crazypants.enderio.ModObject;
import crazypants.enderio.config.Config;
import crazypants.enderio.machine.AbstractMachineEntity;
import crazypants.enderio.machine.SlotDefinition;
import crazypants.enderio.machine.generator.zombie.NutrientTank;
import crazypants.enderio.machine.generator.zombie.PacketZombieTank;
import crazypants.enderio.network.PacketHandler;
import crazypants.enderio.power.BasicCapacitor;
import crazypants.enderio.power.PowerHandlerUtil;
import crazypants.render.BoundingBox;
import crazypants.util.BlockCoord;
import crazypants.util.FluidUtil;
import crazypants.util.ForgeDirectionOffsets;
import crazypants.vecmath.Vector3d;
public class TileKillerJoe extends AbstractMachineEntity /*
* implements
* IFluidHandler
*/{
public class TileKillerJoe extends AbstractMachineEntity implements IFluidHandler {
private static int IO_MB_TICK = 250;
protected AxisAlignedBB killBounds;
protected FakePlayer attackera;
final NutrientTank fuelTank = new NutrientTank(FluidContainerRegistry.BUCKET_VOLUME * 2);
int lastFluidLevelUpdate;
private boolean tanksDirty;
public TileKillerJoe() {
super(new SlotDefinition(1, 0, 0));
powerHandler = PowerHandlerUtil.createHandler(new BasicCapacitor(0, 0), this, Type.MACHINE);
@@ -79,6 +93,15 @@ public class TileKillerJoe extends AbstractMachineEntity /*
if(worldObj.getTotalWorldTime() % 10 != 0) {
return false;
}
if(tanksDirty) {
PacketHandler.sendToAllAround(new PacketNutrientLevel(this), this);
tanksDirty = false;
}
if(fuelTank.getFluidAmount() < fuelTank.getCapacity() * 0.7f) {
return false;
}
float baseDamage = getBaseDamage();
if(baseDamage <= 0) {
@@ -94,6 +117,7 @@ public class TileKillerJoe extends AbstractMachineEntity /*
boolean res = ent.attackEntityFrom(ds, baseDamage + enchDamage);
if(res) {
damageWeapon(ent);
useNutrient();
return false;
}
}
@@ -101,11 +125,16 @@ public class TileKillerJoe extends AbstractMachineEntity /*
return false;
}
private void useNutrient() {
fuelTank.drain(Config.killerJoeNutrientUsePerAttackMb, true);
tanksDirty = true;
}
private float getEnchantmentDamage(EntityLivingBase ent) {
ItemStack weaponStack = getStackInSlot(0);
if(weaponStack == null) {
return 0;
}
}
return EnchantmentHelper.func_152377_a(weaponStack, ent.getCreatureAttribute());
}
@@ -114,22 +143,22 @@ public class TileKillerJoe extends AbstractMachineEntity /*
if(weaponStack == null) {
return 0;
}
Multimap atMods = weaponStack.getAttributeModifiers();
Multimap atMods = weaponStack.getAttributeModifiers();
Collection ad = atMods.get("generic.attackDamage");
if(ad.isEmpty()) {
return 0;
}
float res = 0;
for (Object obj : ad) {
if(obj instanceof AttributeModifier) {
AttributeModifier am = (AttributeModifier) obj;
res += am.getAmount();
res += am.getAmount();
}
}
return res;
}
private void damageWeapon(EntityLivingBase ent) {
ItemStack weaponStack = getStackInSlot(0);
if(weaponStack == null) {
@@ -137,8 +166,8 @@ public class TileKillerJoe extends AbstractMachineEntity /*
}
weaponStack.hitEntity(ent, getAttackera());
if(weaponStack.stackSize <= 0) {
setInventorySlotContents(0, null);
}
setInventorySlotContents(0, null);
}
}
private FakePlayer getAttackera() {
@@ -188,5 +217,101 @@ public class TileKillerJoe extends AbstractMachineEntity /*
public boolean canConnectEnergy(ForgeDirection from) {
return false;
}
// Fluid Stuff
@Override
protected boolean doPull(ForgeDirection dir) {
boolean res = super.doPull(dir);
BlockCoord loc = getLocation().getLocation(dir);
IFluidHandler target = FluidUtil.getFluidHandler(worldObj, loc);
if(target != null) {
FluidTankInfo[] infos = target.getTankInfo(dir.getOpposite());
if(infos != null) {
for (FluidTankInfo info : infos) {
if(info.fluid != null && info.fluid.amount > 0) {
if(canFill(dir, info.fluid.getFluid())) {
FluidStack canPull = info.fluid.copy();
canPull.amount = Math.min(IO_MB_TICK, canPull.amount);
FluidStack drained = target.drain(dir.getOpposite(), canPull, false);
if(drained != null && drained.amount > 0) {
int filled = fill(dir, drained, false);
if(filled > 0) {
drained = target.drain(dir.getOpposite(), filled, true);
fill(dir, drained, true);
return res;
}
}
}
}
}
}
}
return res;
}
@Override
public int fill(ForgeDirection from, FluidStack resource, boolean doFill) {
if(resource == null || resource.getFluid() == null || !canFill(from, resource.getFluid())) {
return 0;
}
int res = fuelTank.fill(resource, doFill);
if(res > 0 && doFill) {
tanksDirty = true;
}
return res;
}
@Override
public boolean canFill(ForgeDirection from, Fluid fluid) {
return fluid != null && fluid.getID() == EnderIO.fluidNutrientDistillation.getID();
}
@Override
public FluidTankInfo[] getTankInfo(ForgeDirection from) {
return new FluidTankInfo[] { fuelTank.getInfo() };
}
@Override
public FluidStack drain(ForgeDirection from, FluidStack resource, boolean doDrain) {
return null;
}
@Override
public FluidStack drain(ForgeDirection from, int maxDrain, boolean doDrain) {
return null;
}
@Override
public boolean canDrain(ForgeDirection from, Fluid fluid) {
return false;
}
@Override
public void readCommon(NBTTagCompound nbtRoot) {
super.readCommon(nbtRoot);
if(nbtRoot.hasKey("fuelTank")) {
NBTTagCompound tankRoot = (NBTTagCompound) nbtRoot.getTag("fuelTank");
if(tankRoot != null) {
fuelTank.readFromNBT(tankRoot);
} else {
fuelTank.setFluid(null);
}
} else {
fuelTank.setFluid(null);
}
}
@Override
public void writeCommon(NBTTagCompound nbtRoot) {
super.writeCommon(nbtRoot);
if(fuelTank.getFluidAmount() > 0) {
NBTTagCompound tankRoot = new NBTTagCompound();
fuelTank.writeToNBT(tankRoot);
nbtRoot.setTag("fuelTank", tankRoot);
}
}
}