made use of IFillableItem, persistent fluid tanks

This commit is contained in:
Boblet 2022-08-18 16:16:14 +02:00
parent c7ded454bc
commit a35236ce14
16 changed files with 407 additions and 274 deletions

View File

@ -7,6 +7,7 @@ import java.util.Random;
import com.hbm.handler.MultiblockHandlerXR;
import com.hbm.handler.ThreeInts;
import com.hbm.main.MainRegistry;
import com.hbm.tileentity.IPersistentNBT;
import cpw.mods.fml.common.network.internal.FMLNetworkHandler;
import net.minecraft.block.Block;
@ -199,6 +200,7 @@ public abstract class BlockDummyable extends BlockContainer {
int meta = getMetaForCore(world, x + dir.offsetX * o, y + dir.offsetY * o, z + dir.offsetZ * o, (EntityPlayer) player, dir.ordinal() + offset);
//lastCore = new BlockPos(x + dir.offsetX * o, y + dir.offsetY * o, z + dir.offsetZ * o);
world.setBlock(x + dir.offsetX * o, y + dir.offsetY * o, z + dir.offsetZ * o, this, meta, 3);
IPersistentNBT.restoreData(world, x + dir.offsetX * o, y + dir.offsetY * o, z + dir.offsetZ * o, itemStack);
fillSpace(world, x, y, z, dir, o);
}
y -= getHeightOffset();

View File

@ -134,21 +134,11 @@ public class NukeMike extends BlockContainer implements IBomb {
world.spawnEntityInWorld(EntityNukeExplosionMK4.statFac(world, BombConfig.mikeRadius, x + 0.5, y + 0.5, z + 0.5));
if(GeneralConfig.enableNukeClouds) {
EntityNukeCloudSmall entity2 = new EntityNukeCloudSmall(world, 1000, r * 0.005F);
entity2.posX = x;
entity2.posY = y;
entity2.posZ = z;
world.spawnEntityInWorld(entity2);
} else {
EntityNukeCloudSmall entity2 = new EntityNukeCloudNoShroom(world, 1000);
entity2.posX = x;
entity2.posY = y - (r / 10);
entity2.posZ = z;
world.spawnEntityInWorld(entity2);
}
// ExplosionNukeAdvanced.mush(world, x, y, z);
EntityNukeCloudSmall entity2 = new EntityNukeCloudSmall(world, 1000, r * 0.005F);
entity2.posX = x;
entity2.posY = y;
entity2.posZ = z;
world.spawnEntityInWorld(entity2);
}
return false;

View File

@ -1,9 +1,11 @@
package com.hbm.blocks.machine;
import java.util.ArrayList;
import java.util.Random;
import com.hbm.blocks.ModBlocks;
import com.hbm.main.MainRegistry;
import com.hbm.tileentity.IPersistentNBT;
import com.hbm.tileentity.machine.storage.TileEntityBarrel;
import cpw.mods.fml.client.registry.RenderingRegistry;
@ -11,11 +13,13 @@ import cpw.mods.fml.common.network.internal.FMLNetworkHandler;
import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.stats.StatList;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.world.IBlockAccess;
@ -125,4 +129,31 @@ public class BlockFluidBarrel extends BlockContainer {
super.breakBlock(p_149749_1_, p_149749_2_, p_149749_3_, p_149749_4_, p_149749_5_, p_149749_6_);
}
@Override
public void onBlockPlacedBy(World world, int x, int y, int z, EntityLivingBase player, ItemStack stack) {
super.onBlockPlacedBy(world, x, y, z, player, stack);
IPersistentNBT.restoreData(world, x, y, z, stack);
}
@Override
public ArrayList<ItemStack> getDrops(World world, int x, int y, int z, int metadata, int fortune) {
return IPersistentNBT.getDrops(world, x, y, z, this);
}
@Override
public void onBlockHarvested(World world, int x, int y, int z, int meta, EntityPlayer player) {
if(!player.capabilities.isCreativeMode) {
harvesters.set(player);
this.dropBlockAsItem(world, x, y, z, meta, 0);
harvesters.set(null);
}
}
@Override
public void harvestBlock(World world, EntityPlayer player, int x, int y, int z, int meta) {
player.addStat(StatList.mineBlockStatArray[getIdFromBlock(this)], 1);
player.addExhaustion(0.025F);
}
}

View File

@ -1,15 +1,19 @@
package com.hbm.blocks.machine;
import java.util.ArrayList;
import com.hbm.blocks.BlockDummyable;
import com.hbm.blocks.ModBlocks;
import com.hbm.handler.MultiblockHandlerXR;
import com.hbm.main.MainRegistry;
import com.hbm.tileentity.IPersistentNBT;
import com.hbm.tileentity.TileEntityProxyCombo;
import com.hbm.tileentity.machine.storage.TileEntityMachineBAT9000;
import cpw.mods.fml.common.network.internal.FMLNetworkHandler;
import net.minecraft.block.material.Material;
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;
@ -82,4 +86,9 @@ public class MachineBigAssTank9000 extends BlockDummyable {
return true;
}
}
@Override
public ArrayList<ItemStack> getDrops(World world, int x, int y, int z, int metadata, int fortune) {
return IPersistentNBT.getDrops(world, x, y, z, this);
}
}

View File

@ -7,6 +7,7 @@ import com.hbm.blocks.BlockDummyable;
import com.hbm.blocks.ILookOverlay;
import com.hbm.blocks.ModBlocks;
import com.hbm.main.MainRegistry;
import com.hbm.tileentity.IPersistentNBT;
import com.hbm.tileentity.machine.storage.TileEntityMachineBattery;
import com.hbm.tileentity.machine.storage.TileEntityMachineFENSU;
import com.hbm.util.BobMathUtil;
@ -15,6 +16,7 @@ import com.hbm.util.I18nUtil;
import cpw.mods.fml.common.network.internal.FMLNetworkHandler;
import net.minecraft.block.material.Material;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
import net.minecraftforge.client.event.RenderGameOverlayEvent.Pre;

View File

@ -1,11 +1,13 @@
package com.hbm.blocks.machine;
import java.util.ArrayList;
import java.util.Random;
import com.hbm.blocks.ModBlocks;
import com.hbm.handler.MultiblockHandler;
import com.hbm.interfaces.IMultiblock;
import com.hbm.main.MainRegistry;
import com.hbm.tileentity.IPersistentNBT;
import com.hbm.tileentity.machine.TileEntityDummy;
import com.hbm.tileentity.machine.storage.TileEntityMachineFluidTank;
@ -20,6 +22,7 @@ import net.minecraft.inventory.ISidedInventory;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.stats.StatList;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.MathHelper;
import net.minecraft.world.World;
@ -257,6 +260,8 @@ public class MachineFluidTank extends BlockContainer implements IMultiblock {
} else
world.func_147480_a(x, y, z, true);
}
IPersistentNBT.restoreData(world, x, y, z, itemStack);
}
private final Random field_149933_a = new Random();
@ -313,4 +318,28 @@ public class MachineFluidTank extends BlockContainer implements IMultiblock {
super.breakBlock(p_149749_1_, p_149749_2_, p_149749_3_, p_149749_4_, p_149749_5_, p_149749_6_);
}
@Override
public ArrayList<ItemStack> getDrops(World world, int x, int y, int z, int metadata, int fortune) {
return IPersistentNBT.getDrops(world, x, y, z, this);
}
@Override
public void onBlockHarvested(World world, int x, int y, int z, int meta, EntityPlayer player) {
if(!player.capabilities.isCreativeMode) {
harvesters.set(player);
this.dropBlockAsItem(world, x, y, z, meta, 0);
harvesters.set(null);
}
}
/*
* Called after the block and TE are already gone, so this method is of no use to us.
*/
@Override
public void harvestBlock(World world, EntityPlayer player, int x, int y, int z, int meta) {
player.addStat(StatList.mineBlockStatArray[getIdFromBlock(this)], 1);
player.addExhaustion(0.025F);
}
}

View File

@ -12,7 +12,6 @@ public class GeneralConfig {
public static boolean enableMines = true;
public static boolean enableRad = true;
public static boolean enableNITAN = true;
public static boolean enableNukeClouds = true;
public static boolean enableBomberShortMode = false;
public static boolean enableVaults = true;
public static boolean enableCataclysm = false;
@ -54,20 +53,19 @@ public class GeneralConfig {
final String CATEGORY_GENERAL = CommonConfig.CATEGORY_GENERAL;
enableDebugMode = config.get(CATEGORY_GENERAL, "1.00_enableDebugMode", false, "Enable debugging mode").getBoolean(false);
enableMycelium = config.get(CATEGORY_GENERAL, "1.01_enableMyceliumSpread", false, "Allows mycelium to spread").getBoolean(false);
enableMycelium = config.get(CATEGORY_GENERAL, "1.01_enableMyceliumSpread", false, "Allows glowing mycelium to spread").getBoolean(false);
enablePlutoniumOre = config.get(CATEGORY_GENERAL, "1.02_enablePlutoniumNetherOre", false, "Enables plutonium ore generation in the nether").getBoolean(false);
enableDungeons = config.get(CATEGORY_GENERAL, "1.03_enableDungeonSpawn", true, "Allows custom generation like meteor dungeons and whatnot to spawn").getBoolean(true);
enableDungeons = config.get(CATEGORY_GENERAL, "1.03_enableDungeonSpawn", true, "Allows structures and dungeons to spawn").getBoolean(true);
enableMDOres = config.get(CATEGORY_GENERAL, "1.04_enableOresInModdedDimensions", true, "Allows NTM ores to generate in modded dimensions").getBoolean(true);
enableMines = config.get(CATEGORY_GENERAL, "1.05_enableLandmineSpawn", true, "Allows landmines to generate").getBoolean(true);
enableRad = config.get(CATEGORY_GENERAL, "1.06_enableRadHotspotSpawn", true, "Allows radiation hotspots to generate").getBoolean(true);
enableNITAN = config.get(CATEGORY_GENERAL, "1.07_enableNITANChestSpawn", true, "Allows chests to spawn at specific coordinates full of powders").getBoolean(true);
enableNukeClouds = config.get(CATEGORY_GENERAL, "1.08_enableMushroomClouds", true, "Allow these green clouds after nuke explosions").getBoolean(true);
enableBomberShortMode = config.get(CATEGORY_GENERAL, "1.14_enableBomberShortMode", false, "Has bomber planes spawn in closer to the target for use with smaller render distances").getBoolean(false);
enableVaults = config.get(CATEGORY_GENERAL, "1.15_enableVaultSpawn", true, "Allows vaults to spawn").getBoolean(true);
enableVaults = config.get(CATEGORY_GENERAL, "1.15_enableVaultSpawn", true, "Allows locked safes to spawn").getBoolean(true);
enableCataclysm = config.get(CATEGORY_GENERAL, "1.17_enableCataclysm", false, "Causes satellites to fall whenever a mob dies").getBoolean(false);
enableExtendedLogging = config.get(CATEGORY_GENERAL, "1.18_enableExtendedLogging", false, "Allows logs about nuke, grenade explosions, detonators activated, missiles launched, etc.").getBoolean(false);
enableExtendedLogging = config.get(CATEGORY_GENERAL, "1.18_enableExtendedLogging", false, "Logs uses of the detonator, nuclear explosions, missile launches, grenades, etc.").getBoolean(false);
enableHardcoreTaint = config.get(CATEGORY_GENERAL, "1.19_enableHardcoreTaint", false, "Allows tainted mobs to spread taint").getBoolean(false);
enableGuns = config.get(CATEGORY_GENERAL, "1.20_enableGuns", true, "Allows guns to be obtainable").getBoolean(true);
enableGuns = config.get(CATEGORY_GENERAL, "1.20_enableGuns", true, "Prevents new system guns to be fired").getBoolean(true);
enableVirus = config.get(CATEGORY_GENERAL, "1.21_enableVirus", false, "Allows virus blocks to spread").getBoolean(false);
enableCrosshairs = config.get(CATEGORY_GENERAL, "1.22_enableCrosshairs", true, "Shows custom crosshairs when an NTM gun is being held").getBoolean(true);
enableReflectorCompat = config.get(CATEGORY_GENERAL, "1.24_enableReflectorCompat", false, "Enable old reflector oredict name (\"plateDenseLead\") instead of new \"plateTungCar\"").getBoolean(false);

View File

@ -78,13 +78,7 @@ public class ToolRecipes {
CraftingManager.addRecipeAuto(new ItemStack(ModItems.mese_pickaxe, 1), new Object[] { " SD", "APS", "FA ", 'S', ModItems.blades_desh, 'D', ModItems.powder_dineutronium, 'A', ModItems.plate_paa, 'P', ModItems.chlorophyte_pickaxe, 'F', ModItems.shimmer_handle });
//Chainsaws
CraftingManager.addRecipeAuto(new ItemStack(ModItems.chainsaw, 1), new Object[] { " H", "BBP", " C", 'H', ModItems.hull_small_steel, 'B', ModItems.blades_steel, 'P', ModItems.piston_selenium, 'C', Fluids.DIESEL.getDict(1000) });
CraftingManager.addRecipeAuto(new ItemStack(ModItems.chainsaw, 1), new Object[] { " H", "BBP", " C", 'H', ModItems.hull_small_steel, 'B', ModItems.blades_steel, 'P', ModItems.piston_selenium, 'C', Fluids.DIESEL_CRACK.getDict(1000) });
CraftingManager.addRecipeAuto(new ItemStack(ModItems.chainsaw, 1), new Object[] { " H", "BBP", " C", 'H', ModItems.hull_small_steel, 'B', ModItems.blades_steel, 'P', ModItems.piston_selenium, 'C', Fluids.PETROIL.getDict(1000) });
CraftingManager.addRecipeAuto(new ItemStack(ModItems.chainsaw, 1), new Object[] { " H", "BBP", " C", 'H', ModItems.hull_small_steel, 'B', ModItems.blades_steel, 'P', ModItems.piston_selenium, 'C', Fluids.PETROIL_LEADED.getDict(1000) });
CraftingManager.addRecipeAuto(new ItemStack(ModItems.chainsaw, 1), new Object[] { " H", "BBP", " C", 'H', ModItems.hull_small_steel, 'B', ModItems.blades_steel, 'P', ModItems.piston_selenium, 'C', Fluids.GASOLINE.getDict(1000) });
CraftingManager.addRecipeAuto(new ItemStack(ModItems.chainsaw, 1), new Object[] { " H", "BBP", " C", 'H', ModItems.hull_small_steel, 'B', ModItems.blades_steel, 'P', ModItems.piston_selenium, 'C', Fluids.GASOLINE_LEADED.getDict(1000) });
CraftingManager.addRecipeAuto(new ItemStack(ModItems.chainsaw, 1), new Object[] { " H", "BBP", " C", 'H', ModItems.hull_small_steel, 'B', ModItems.blades_steel, 'P', ModItems.piston_selenium, 'C', Fluids.BIOFUEL.getDict(1000) });
CraftingManager.addRecipeAuto(new ItemStack(ModItems.chainsaw, 1), new Object[] { " H", "BBP", " C", 'H', ModItems.hull_small_steel, 'B', ModItems.blades_steel, 'P', ModItems.piston_selenium, 'C', ModItems.canister_empty });
//Misc
CraftingManager.addRecipeAuto(new ItemStack(ModItems.euphemium_stopper, 1), new Object[] { "I", "S", "S", 'I', EUPH.ingot(), 'S', KEY_STICK });

View File

@ -5,30 +5,31 @@ import java.util.List;
import org.lwjgl.opengl.GL11;
import com.hbm.handler.ArmorModHandler;
import com.hbm.interfaces.IPartiallyFillable;
import com.hbm.inventory.FluidContainerRegistry;
import com.hbm.inventory.fluid.FluidType;
import com.hbm.inventory.fluid.Fluids;
import com.hbm.inventory.gui.GuiInfoContainer;
import com.hbm.items.ModItems;
import com.hbm.items.armor.ItemArmorMod;
import com.hbm.items.machine.IItemFluidIdentifier;
import com.hbm.packet.PacketDispatcher;
import com.hbm.packet.TEFluidPacket;
import api.hbm.fluid.IFillableItem;
import cpw.mods.fml.common.network.NetworkRegistry.TargetPoint;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.resources.I18n;
import net.minecraft.item.ItemArmor;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
public class FluidTank {
public static final List<FluidLoadingHandler> loadingHandlers = new ArrayList();
static {
loadingHandlers.add(new FluidLoaderStandard());
loadingHandlers.add(new FluidLoaderFillableItem());
}
FluidType type;
int fluid;
int maxFluid;
@ -94,143 +95,44 @@ public class FluidTank {
//Fills tank from canisters
public boolean loadTank(int in, int out, ItemStack[] slots) {
FluidType inType = Fluids.NONE;
if(slots[in] != null) {
//TODO: add IPartiallyFillable case for unloading, useful for infinite tanks so they don't need to be hardcoded
inType = FluidContainerRegistry.getFluidType(slots[in]);
if(slots[in].getItem() == ModItems.fluid_barrel_infinite && type != Fluids.NONE) {
this.fluid = this.maxFluid;
return true;
}
if(slots[in].getItem() == ModItems.inf_water && this.type == Fluids.WATER) {
this.fluid += 50;
if(this.fluid > this.maxFluid)
this.fluid = this.maxFluid;
return true;
}
if(slots[in].getItem() == ModItems.inf_water_mk2 && this.type == Fluids.WATER) {
this.fluid += 500;
if(this.fluid > this.maxFluid)
this.fluid = this.maxFluid;
return true;
}
if(FluidContainerRegistry.getFluidContent(slots[in], type) <= 0)
return false;
} else {
if(slots[in] == null)
return false;
}
if(slots[in] != null && inType.getName().equals(type.getName()) && fluid + FluidContainerRegistry.getFluidContent(slots[in], type) <= maxFluid) {
ItemStack emptyContainer = FluidContainerRegistry.getEmptyContainer(slots[in]);
if(slots[out] == null) {
fluid += FluidContainerRegistry.getFluidContent(slots[in], type);
slots[out] = emptyContainer;
slots[in].stackSize--;
if(slots[in].stackSize <= 0)
slots[in] = null;
} else if(slots[out] != null && (emptyContainer == null || (slots[out].getItem() == emptyContainer.getItem() && slots[out].getItemDamage() == emptyContainer.getItemDamage() && slots[out].stackSize < slots[out].getMaxStackSize()))) {
fluid += FluidContainerRegistry.getFluidContent(slots[in], type);
if(emptyContainer != null)
slots[out].stackSize++;
slots[in].stackSize--;
if(slots[in].stackSize <= 0)
slots[in] = null;
}
if(slots[in].getItem() == ModItems.fluid_barrel_infinite && type != Fluids.NONE) {
this.fluid = this.maxFluid;
return true;
}
if(slots[in].getItem() == ModItems.inf_water && this.type == Fluids.WATER) {
this.fluid += 50;
if(this.fluid > this.maxFluid)
this.fluid = this.maxFluid;
return true;
}
if(slots[in].getItem() == ModItems.inf_water_mk2 && this.type == Fluids.WATER) {
this.fluid += 500;
if(this.fluid > this.maxFluid)
this.fluid = this.maxFluid;
return true;
}
return false;
int prev = this.getFill();
for(FluidLoadingHandler handler : loadingHandlers) {
if(handler.emptyItem(slots, in, out, this)) {
break;
}
}
return this.getFill() > prev;
}
//Fills canisters from tank
public void unloadTank(int in, int out, ItemStack[] slots) {
ItemStack full = null;
if(slots[in] != null) {
if(this.handleFillableUnload(slots, in))
return;
if(this.handleInfiniteUnload(slots, in))
return;
if(this.handleNewFillableUnload(slots[in]))
return;
full = FluidContainerRegistry.getFullContainer(slots[in], type);
}
public boolean unloadTank(int in, int out, ItemStack[] slots) {
if(full == null)
return;
if(slots[in] != null && fluid - FluidContainerRegistry.getFluidContent(full, type) >= 0) {
ItemStack fullContainer = FluidContainerRegistry.getFullContainer(slots[in], type);
if(slots[out] == null) {
fluid -= FluidContainerRegistry.getFluidContent(full, type);
slots[out] = full.copy();
slots[in].stackSize--;
if(slots[in].stackSize <= 0)
slots[in] = null;
} else if(slots[out] != null && slots[out].getItem() == fullContainer.getItem() && slots[out].getItemDamage() == fullContainer.getItemDamage() && slots[out].stackSize < slots[out].getMaxStackSize()) {
fluid -= FluidContainerRegistry.getFluidContent(full, type);
slots[in].stackSize--;
if(slots[in].stackSize <= 0)
slots[in] = null;
slots[out].stackSize++;
}
}
}
public boolean handleFillableUnload(ItemStack[] slots, int in) {
ItemStack partial = slots[in];
if(partial.getItem() instanceof ItemArmor && ArmorModHandler.hasMods(partial)) {
partial = ArmorModHandler.pryMods(partial)[ArmorModHandler.plate_only];
if(partial == null)
partial = slots[in];
}
if(partial.getItem() instanceof IPartiallyFillable) {
IPartiallyFillable fillable = (IPartiallyFillable)partial.getItem();
int speed = fillable.getLoadSpeed(partial);
if(fillable.getType(partial) == this.type && speed > 0) {
int toLoad = Math.min(this.fluid, speed);
int fill = fillable.getFill(partial);
toLoad = Math.min(toLoad, fillable.getMaxFill(partial) - fill);
if(toLoad > 0) {
this.fluid -= toLoad;
fillable.setFill(partial, fill + toLoad);
}
}
if(slots[in].getItem() instanceof ItemArmor && partial.getItem() instanceof ItemArmorMod) {
ArmorModHandler.applyMod(slots[in], partial);
}
return true;
}
return false;
}
public boolean handleInfiniteUnload(ItemStack[] slots, int in) {
if(slots[in] == null)
return false;
if(slots[in].getItem() == ModItems.fluid_barrel_infinite) {
this.fluid = 0;
@ -251,29 +153,15 @@ public class FluidTank {
return true;
}
return false;
}
public boolean handleNewFillableUnload(ItemStack stack) {
int prev = this.getFill();
if(stack.getItem() instanceof ItemArmor && ArmorModHandler.hasMods(stack)) {
for(ItemStack mod : ArmorModHandler.pryMods(stack)) {
if(mod != null && mod.getItem() instanceof IFillableItem) {
handleNewFillableUnload(mod);
}
for(FluidLoadingHandler handler : loadingHandlers) {
if(handler.fillItem(slots, in, out, this)) {
break;
}
}
if(!(stack.getItem() instanceof IFillableItem)) return false;
IFillableItem fillable = (IFillableItem) stack.getItem();
if(fillable.acceptsFluid(getTankType(), stack)) {
this.setFill(fillable.tryFill(type, this.getFill(), stack));
}
return true;
return this.getFill() < prev;
}
public boolean setType(int in, ItemStack[] slots) {

View File

@ -870,17 +870,17 @@ public class ModItems {
public static Item canister_empty;
public static Item canister_full;
public static Item canister_smear;
public static Item canister_canola;
public static Item canister_oil;
public static Item canister_fuel;
public static Item canister_kerosene;
public static Item canister_reoil;
public static Item canister_petroil;
@Deprecated public static Item canister_smear;
@Deprecated public static Item canister_canola;
@Deprecated public static Item canister_oil;
@Deprecated public static Item canister_fuel;
@Deprecated public static Item canister_kerosene;
@Deprecated public static Item canister_reoil;
@Deprecated public static Item canister_petroil;
public static Item canister_napalm;
public static Item canister_gasoline;
public static Item canister_NITAN;
public static Item canister_fracksol;
@Deprecated public static Item canister_gasoline;
@Deprecated public static Item canister_NITAN;
@Deprecated public static Item canister_fracksol;
public static Item canister_heavyoil;
public static Item canister_bitumen;
@ -5180,7 +5180,8 @@ public class ModItems {
jackt = new ModArmor(MainRegistry.aMatSteel, 7, 1).setUnlocalizedName("jackt").setTextureName(RefStrings.MODID + ":jackt");
jackt2 = new ModArmor(MainRegistry.aMatSteel, 7, 1).setUnlocalizedName("jackt2").setTextureName(RefStrings.MODID + ":jackt2");
chainsaw = new ItemToolAbility(25, -0.05, MainRegistry.tMatChainsaw, EnumToolType.AXE)
chainsaw = new ItemToolAbilityFueled(25, -0.05, MainRegistry.tMatChainsaw, EnumToolType.AXE, 5000, 1, 250,
Fluids.DIESEL, Fluids.DIESEL_CRACK, Fluids.KEROSENE, Fluids.BIOFUEL, Fluids.GASOLINE, Fluids.GASOLINE_LEADED, Fluids.PETROIL, Fluids.PETROIL_LEADED, Fluids.COALGAS, Fluids.COALGAS_LEADED)
.addBreakAbility(new ToolAbility.SilkAbility())
.addBreakAbility(new ToolAbility.RecursionAbility(5))
.addHitAbility(new WeaponAbility.ChainsawAbility(4))

View File

@ -4,6 +4,7 @@ import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap;
import com.hbm.handler.ArmorModHandler;
import com.hbm.inventory.fluid.FluidType;
import com.hbm.inventory.fluid.Fluids;
import com.hbm.items.ModItems;
import com.hbm.packet.AuxParticlePacketNT;
import com.hbm.packet.PacketDispatcher;
@ -63,4 +64,9 @@ public class ArmorDiesel extends ArmorFSBFueled {
PacketDispatcher.wrapper.sendToAllAround(new AuxParticlePacketNT(data, player.posX, player.posY, player.posZ), new TargetPoint(world.provider.dimensionId, player.posX, player.posY, player.posZ, 100));
}
}
@Override
public boolean acceptsFluid(FluidType type, ItemStack stack) {
return type == Fluids.DIESEL || type == Fluids.DIESEL_CRACK;
}
}

View File

@ -0,0 +1,116 @@
package com.hbm.items.tool;
import java.util.HashSet;
import java.util.List;
import com.hbm.inventory.fluid.FluidType;
import com.hbm.util.I18nUtil;
import api.hbm.fluid.IFillableItem;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumChatFormatting;
public class ItemToolAbilityFueled extends ItemToolAbility implements IFillableItem {
protected int fillRate;
protected int consumption;
protected int maxFuel;
protected HashSet<FluidType> acceptedFuels = new HashSet();
public ItemToolAbilityFueled(float damage, double movement, ToolMaterial material, EnumToolType type, int maxFuel, int consumption, int fillRate, FluidType... acceptedFuels) {
super(damage, movement, material, type);
this.maxFuel = maxFuel;
this.consumption = consumption;
this.fillRate = fillRate;
this.setMaxDamage(1);
for(FluidType fuel : acceptedFuels) this.acceptedFuels.add(fuel);
}
@Override
@SideOnly(Side.CLIENT)
public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean ext) {
list.add(EnumChatFormatting.GOLD + "Fuel: " + this.getFill(stack) + "/" + this.maxFuel + "mB");
for(FluidType type : acceptedFuels) {
list.add(EnumChatFormatting.YELLOW + "- " + I18nUtil.resolveKey(type.getUnlocalizedName()));
}
super.addInformation(stack, player, list, ext);
}
@Override
public boolean showDurabilityBar(ItemStack stack) {
return getFill(stack) < maxFuel;
}
@Override
public double getDurabilityForDisplay(ItemStack stack) {
return 1 - (double) getFill(stack) / (double) maxFuel;
}
@Override
protected boolean canOperate(ItemStack stack) {
return getFill(stack) >= this.consumption;
}
@Override
public void setDamage(ItemStack stack, int damage) {
this.setFill(stack, Math.max(this.getFill(stack) - damage * consumption, 0));
}
@Override
public boolean isDamageable() {
return true;
}
public int getFill(ItemStack stack) {
if(stack.stackTagCompound == null) {
stack.stackTagCompound = new NBTTagCompound();
setFill(stack, maxFuel);
return maxFuel;
}
return stack.stackTagCompound.getInteger("fuel");
}
public void setFill(ItemStack stack, int fill) {
if(stack.stackTagCompound == null) {
stack.stackTagCompound = new NBTTagCompound();
}
stack.stackTagCompound.setInteger("fuel", fill);
}
@Override
public boolean acceptsFluid(FluidType type, ItemStack stack) {
return this.acceptedFuels.contains(type);
}
@Override
public int tryFill(FluidType type, int amount, ItemStack stack) {
if(!acceptsFluid(type, stack))
return amount;
int toFill = Math.min(amount, this.fillRate);
toFill = Math.min(toFill, this.maxFuel - this.getFill(stack));
this.setFill(stack, this.getFill(stack) + toFill);
return amount - toFill;
}
@Override
public boolean providesFluid(FluidType type, ItemStack stack) {
return false;
}
@Override
public int tryEmpty(FluidType type, int amount, ItemStack stack) {
return amount;
}
}

View File

@ -26,94 +26,90 @@ public class ItemToolAbilityPower extends ItemToolAbility implements IBatteryIte
}
@Override
public void chargeBattery(ItemStack stack, long i) {
if(stack.getItem() instanceof ItemToolAbilityPower) {
if(stack.hasTagCompound()) {
stack.stackTagCompound.setLong("charge", stack.stackTagCompound.getLong("charge") + i);
} else {
stack.stackTagCompound = new NBTTagCompound();
stack.stackTagCompound.setLong("charge", i);
}
}
}
public void chargeBattery(ItemStack stack, long i) {
if(stack.getItem() instanceof ItemToolAbilityPower) {
if(stack.hasTagCompound()) {
stack.stackTagCompound.setLong("charge", stack.stackTagCompound.getLong("charge") + i);
} else {
stack.stackTagCompound = new NBTTagCompound();
stack.stackTagCompound.setLong("charge", i);
}
}
}
@Override
public void setCharge(ItemStack stack, long i) {
if(stack.getItem() instanceof ItemToolAbilityPower) {
if(stack.hasTagCompound()) {
stack.stackTagCompound.setLong("charge", i);
} else {
stack.stackTagCompound = new NBTTagCompound();
stack.stackTagCompound.setLong("charge", i);
}
}
}
public void setCharge(ItemStack stack, long i) {
if(stack.getItem() instanceof ItemToolAbilityPower) {
if(stack.hasTagCompound()) {
stack.stackTagCompound.setLong("charge", i);
} else {
stack.stackTagCompound = new NBTTagCompound();
stack.stackTagCompound.setLong("charge", i);
}
}
}
@Override
public void dischargeBattery(ItemStack stack, long i) {
if(stack.getItem() instanceof ItemToolAbilityPower) {
if(stack.hasTagCompound()) {
stack.stackTagCompound.setLong("charge", stack.stackTagCompound.getLong("charge") - i);
} else {
stack.stackTagCompound = new NBTTagCompound();
stack.stackTagCompound.setLong("charge", this.maxPower - i);
}
if(stack.stackTagCompound.getLong("charge") < 0)
stack.stackTagCompound.setLong("charge", 0);
}
}
public void dischargeBattery(ItemStack stack, long i) {
if(stack.getItem() instanceof ItemToolAbilityPower) {
if(stack.hasTagCompound()) {
stack.stackTagCompound.setLong("charge", stack.stackTagCompound.getLong("charge") - i);
} else {
stack.stackTagCompound = new NBTTagCompound();
stack.stackTagCompound.setLong("charge", this.maxPower - i);
}
if(stack.stackTagCompound.getLong("charge") < 0)
stack.stackTagCompound.setLong("charge", 0);
}
}
@Override
public long getCharge(ItemStack stack) {
if(stack.getItem() instanceof ItemToolAbilityPower) {
if(stack.hasTagCompound()) {
return stack.stackTagCompound.getLong("charge");
} else {
stack.stackTagCompound = new NBTTagCompound();
stack.stackTagCompound.setLong("charge", ((ItemToolAbilityPower)stack.getItem()).maxPower);
return stack.stackTagCompound.getLong("charge");
}
}
return 0;
}
@SideOnly(Side.CLIENT)
public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean ext) {
list.add("Charge: " + BobMathUtil.getShortNumber(getCharge(stack)) + " / " + BobMathUtil.getShortNumber(maxPower));
super.addInformation(stack, player, list, ext);
}
public long getCharge(ItemStack stack) {
if(stack.getItem() instanceof ItemToolAbilityPower) {
if(stack.hasTagCompound()) {
return stack.stackTagCompound.getLong("charge");
} else {
stack.stackTagCompound = new NBTTagCompound();
stack.stackTagCompound.setLong("charge", ((ItemToolAbilityPower) stack.getItem()).maxPower);
return stack.stackTagCompound.getLong("charge");
}
}
return 0;
}
@SideOnly(Side.CLIENT)
public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean ext) {
list.add("Charge: " + BobMathUtil.getShortNumber(getCharge(stack)) + " / " + BobMathUtil.getShortNumber(maxPower));
super.addInformation(stack, player, list, ext);
}
@Override
public boolean showDurabilityBar(ItemStack stack) {
return getCharge(stack) < maxPower;
}
public boolean showDurabilityBar(ItemStack stack) {
return getCharge(stack) < maxPower;
}
@Override
public double getDurabilityForDisplay(ItemStack stack) {
return 1 - (double)getCharge(stack) / (double)maxPower;
}
public double getDurabilityForDisplay(ItemStack stack) {
return 1 - (double) getCharge(stack) / (double) maxPower;
}
@Override
protected boolean canOperate(ItemStack stack) {
return getCharge(stack) >= this.consumption;
}
protected boolean canOperate(ItemStack stack) {
return getCharge(stack) >= this.consumption;
}
@Override
public long getMaxCharge() {
return maxPower;
}
public long getMaxCharge() {
return maxPower;
}
@Override
public long getChargeRate() {
return chargeRate;
}
public long getChargeRate() {
return chargeRate;
}
@Override
public long getDischargeRate() {
@ -121,13 +117,12 @@ public class ItemToolAbilityPower extends ItemToolAbility implements IBatteryIte
}
@Override
public void setDamage(ItemStack stack, int damage)
{
this.dischargeBattery(stack, damage * consumption);
}
public void setDamage(ItemStack stack, int damage) {
this.dischargeBattery(stack, damage * consumption);
}
@Override
public boolean isDamageable() {
return true;
}
public boolean isDamageable() {
return true;
}
}

View File

@ -0,0 +1,40 @@
package com.hbm.tileentity;
import java.util.ArrayList;
import net.minecraft.block.Block;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;
public interface IPersistentNBT {
public void writeNBT(NBTTagCompound nbt);
public void readNBT(NBTTagCompound nbt);
public default ArrayList<ItemStack> getDrops(Block b) {
ArrayList<ItemStack> list = new ArrayList();
ItemStack stack = new ItemStack(b);
stack.stackTagCompound = new NBTTagCompound();
writeNBT(stack.stackTagCompound);
list.add(stack);
return list;
}
public static ArrayList<ItemStack> getDrops(World world, int x, int y, int z, Block b) {
TileEntity tile = world.getTileEntity(x, y, z);
if(tile instanceof IPersistentNBT) {
return ((IPersistentNBT) tile).getDrops(b);
}
return new ArrayList();
}
public static void restoreData(World world, int x, int y, int z, ItemStack stack) {
if(!stack.hasTagCompound()) return;
IPersistentNBT tile = (IPersistentNBT) world.getTileEntity(x, y, z);
tile.readNBT(stack.stackTagCompound);
}
}

View File

@ -12,6 +12,7 @@ import com.hbm.inventory.fluid.Fluids;
import com.hbm.inventory.fluid.tank.FluidTank;
import com.hbm.lib.Library;
import com.hbm.main.ModEventHandler;
import com.hbm.tileentity.IPersistentNBT;
import com.hbm.tileentity.TileEntityMachineBase;
import api.hbm.fluid.IFluidStandardTransceiver;
@ -20,7 +21,7 @@ import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.world.EnumSkyBlock;
public class TileEntityBarrel extends TileEntityMachineBase implements IFluidAcceptor, IFluidSource, IFluidStandardTransceiver {
public class TileEntityBarrel extends TileEntityMachineBase implements IFluidAcceptor, IFluidSource, IFluidStandardTransceiver, IPersistentNBT {
public FluidTank tank;
public short mode = 0;
@ -220,4 +221,19 @@ public class TileEntityBarrel extends TileEntityMachineBase implements IFluidAcc
public FluidTank[] getReceivingTanks() {
return (mode == 0 || mode == 1) ? new FluidTank[] {tank} : new FluidTank[0];
}
@Override
public void writeNBT(NBTTagCompound nbt) {
NBTTagCompound data = new NBTTagCompound();
this.tank.writeToNBT(data, "tank");
data.getShort("mode");
nbt.setTag("persistent", data);
}
@Override
public void readNBT(NBTTagCompound nbt) {
NBTTagCompound data = nbt.getCompoundTag("persistent");
this.tank.readFromNBT(data, "tank");
this.mode = data.getShort("nbt");
}
}

View File

@ -11,6 +11,7 @@ import com.hbm.inventory.fluid.trait.FT_Corrosive;
import com.hbm.inventory.fluid.Fluids;
import com.hbm.inventory.fluid.tank.FluidTank;
import com.hbm.lib.Library;
import com.hbm.tileentity.IPersistentNBT;
import com.hbm.tileentity.TileEntityMachineBase;
import api.hbm.fluid.IFluidUser;
@ -20,7 +21,7 @@ import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
public class TileEntityMachineFluidTank extends TileEntityMachineBase implements IFluidContainer, IFluidSource, IFluidAcceptor, IFluidUser {
public class TileEntityMachineFluidTank extends TileEntityMachineBase implements IFluidContainer, IFluidSource, IFluidAcceptor, IFluidUser, IPersistentNBT {
public FluidTank tank;
public short mode = 0;
@ -207,4 +208,19 @@ public class TileEntityMachineFluidTank extends TileEntityMachineBase implements
return type == tank.getTankType() ? tank.getMaxFill() - tank.getFill() : 0;
}
@Override
public void writeNBT(NBTTagCompound nbt) {
NBTTagCompound data = new NBTTagCompound();
this.tank.writeToNBT(data, "tank");
data.setShort("mode", mode);
nbt.setTag("persistent", data);
}
@Override
public void readNBT(NBTTagCompound nbt) {
NBTTagCompound data = nbt.getCompoundTag("persistent");
this.tank.readFromNBT(data, "tank");
this.mode = data.getShort("mode");
}
}