mirror of
https://github.com/GTNewHorizons/AE2FluidCraft-Rework.git
synced 2026-11-16 18:44:42 +00:00
add certus quartz tank
This commit is contained in:
1 parent
44ff338023
commit
bad29bfdc3
14 files changed
+411
-1
No files matched your search
@@ -0,0 +1,27 @@
|
||||
package com.glodblock.github.client.render;
|
||||
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.client.IItemRenderer;
|
||||
|
||||
public class ItemCertusQuartzTankRender implements IItemRenderer {
|
||||
|
||||
public ItemCertusQuartzTankRender() {
|
||||
|
||||
//
|
||||
// MinecraftForgeClient.registerItemRenderer(Item.getItemFromBlock(ItemAndBlockHolder.CERTUS_QUARTZ_TANK),
|
||||
// this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean handleRenderType(ItemStack item, ItemRenderType type) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean shouldUseRenderHelper(ItemRenderType type, ItemStack item, ItemRendererHelper helper) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderItem(ItemRenderType type, ItemStack item, Object... data) {}
|
||||
}
|
||||
@@ -0,0 +1,164 @@
|
||||
package com.glodblock.github.common.block;
|
||||
|
||||
import appeng.api.implementations.items.IAEWrench;
|
||||
import buildcraft.api.tools.IToolWrench;
|
||||
import buildcraft.factory.BlockTank;
|
||||
import com.glodblock.github.FluidCraft;
|
||||
import com.glodblock.github.common.item.ItemCertusQuartzTank;
|
||||
import com.glodblock.github.common.tabs.FluidCraftingTabs;
|
||||
import com.glodblock.github.common.tile.TileCertusQuartzTank;
|
||||
import com.glodblock.github.loader.IRegister;
|
||||
import com.glodblock.github.loader.ItemAndBlockHolder;
|
||||
import com.glodblock.github.util.NameConst;
|
||||
import cpw.mods.fml.common.registry.GameRegistry;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import extracells.tileentity.TileEntityCertusTank;
|
||||
import net.minecraft.client.renderer.texture.IIconRegister;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraft.util.IIcon;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.util.ForgeDirection;
|
||||
import net.minecraftforge.fluids.FluidContainerRegistry;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
|
||||
public class BlockCertusQuartzTank extends BlockTank implements IRegister<BlockTank> {
|
||||
|
||||
private IIcon textureStackedSide;
|
||||
|
||||
public BlockCertusQuartzTank() {
|
||||
setBlockName(NameConst.BLOCK_CERTUS_QUARTZ_TANK);
|
||||
setResistance(1.0F);
|
||||
setHardness(0.5F);
|
||||
setBlockBounds(0.0625F, 0.0F, 0.0625F, 0.9375F, 1.0F, 0.9375F);
|
||||
}
|
||||
|
||||
public ItemStack getDropWithNBT(World world, int x, int y, int z) {
|
||||
NBTTagCompound nbt = new NBTTagCompound();
|
||||
TileEntity te = world.getTileEntity(x, y, z);
|
||||
if (te instanceof TileCertusQuartzTank) {
|
||||
ItemStack dropStack = new ItemStack(ItemAndBlockHolder.CERTUS_QUARTZ_TANK, 1);
|
||||
((TileCertusQuartzTank) te).writeToNBTWithoutCoords(nbt);
|
||||
if (!nbt.getCompoundTag("tank").hasKey("Empty")) {
|
||||
dropStack.setTagCompound(nbt);
|
||||
}
|
||||
|
||||
return dropStack;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public TileEntity createNewTileEntity(World world, int metadata) {
|
||||
return new TileCertusQuartzTank();
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void registerBlockIcons(IIconRegister par1IconRegister) {
|
||||
super.registerBlockIcons(par1IconRegister);
|
||||
textureStackedSide = par1IconRegister.registerIcon(FluidCraft.MODID + ":certus_quartz_tank/side_stacked");
|
||||
}
|
||||
|
||||
@Override
|
||||
public IIcon getIconAbsolute(IBlockAccess iblockaccess, int x, int y, int z, int side, int metadata) {
|
||||
if (side >= 2 && (iblockaccess.getBlock(x, y - 1, z) instanceof BlockCertusQuartzTank)) {
|
||||
return textureStackedSide;
|
||||
} else {
|
||||
return super.getIconAbsolute(side, metadata);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onBlockActivated(
|
||||
World worldObj,
|
||||
int x,
|
||||
int y,
|
||||
int z,
|
||||
EntityPlayer p,
|
||||
int blockID,
|
||||
float offsetX,
|
||||
float offsetY,
|
||||
float offsetZ) {
|
||||
ItemStack current = p.inventory.getCurrentItem();
|
||||
|
||||
if (p.isSneaking() && current != null) {
|
||||
try {
|
||||
if (current.getItem() instanceof IToolWrench
|
||||
&& ((IToolWrench) current.getItem()).canWrench(p, x, y, z)) {
|
||||
dropBlockAsItem(worldObj, x, y, z, getDropWithNBT(worldObj, x, y, z));
|
||||
worldObj.setBlockToAir(x, y, z);
|
||||
((IToolWrench) current.getItem()).wrenchUsed(p, x, y, z);
|
||||
return true;
|
||||
}
|
||||
} catch (Throwable e) {
|
||||
// No IToolWrench
|
||||
}
|
||||
if (current.getItem() instanceof IAEWrench
|
||||
&& ((IAEWrench) current.getItem()).canWrench(current, p, x, y, z)) {
|
||||
dropBlockAsItem(worldObj, x, y, z, getDropWithNBT(worldObj, x, y, z));
|
||||
worldObj.setBlockToAir(x, y, z);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (current != null) {
|
||||
FluidStack liquid = FluidContainerRegistry.getFluidForFilledItem(current);
|
||||
TileEntityCertusTank tank = (TileEntityCertusTank) worldObj.getTileEntity(x, y, z);
|
||||
|
||||
if (liquid != null) {
|
||||
int amountFilled = tank.fill(ForgeDirection.UNKNOWN, liquid, true);
|
||||
|
||||
if (amountFilled != 0 && !p.capabilities.isCreativeMode) {
|
||||
if (current.stackSize > 1) {
|
||||
p.inventory.mainInventory[p.inventory.currentItem].stackSize -= 1;
|
||||
p.inventory.addItemStackToInventory(current.getItem().getContainerItem(current));
|
||||
} else {
|
||||
p.inventory.mainInventory[p.inventory.currentItem] =
|
||||
current.getItem().getContainerItem(current);
|
||||
}
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
// Handle empty containers
|
||||
} else {
|
||||
|
||||
FluidStack available = tank.getTankInfo(ForgeDirection.UNKNOWN)[0].fluid;
|
||||
if (available != null) {
|
||||
ItemStack filled = FluidContainerRegistry.fillFluidContainer(available, current);
|
||||
|
||||
liquid = FluidContainerRegistry.getFluidForFilledItem(filled);
|
||||
|
||||
if (liquid != null) {
|
||||
tank.drain(ForgeDirection.UNKNOWN, liquid.amount, true);
|
||||
if (!p.capabilities.isCreativeMode) {
|
||||
if (current.stackSize == 1) {
|
||||
p.inventory.mainInventory[p.inventory.currentItem] = filled;
|
||||
} else {
|
||||
p.inventory.mainInventory[p.inventory.currentItem].stackSize--;
|
||||
if (!p.inventory.addItemStackToInventory(filled)) p.entityDropItem(filled, 0);
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BlockCertusQuartzTank register() {
|
||||
GameRegistry.registerBlock(this, ItemCertusQuartzTank.class, NameConst.BLOCK_CERTUS_QUARTZ_TANK);
|
||||
GameRegistry.registerTileEntity(TileCertusQuartzTank.class, NameConst.BLOCK_CERTUS_QUARTZ_TANK);
|
||||
setCreativeTab(FluidCraftingTabs.INSTANCE);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ItemStack stack() {
|
||||
return new ItemStack(this, 1);
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,174 @@
|
||||
package com.glodblock.github.common.item;
|
||||
|
||||
import static com.glodblock.github.common.tile.TileCertusQuartzTank.CAPACITY;
|
||||
|
||||
import com.glodblock.github.common.tile.TileCertusQuartzTank;
|
||||
import com.glodblock.github.crossmod.waila.Tooltip;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import java.util.List;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemBlock;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.fluids.FluidStack;
|
||||
import net.minecraftforge.fluids.IFluidContainerItem;
|
||||
|
||||
public class ItemCertusQuartzTank extends ItemBlock implements IFluidContainerItem {
|
||||
private final String tagKey = "tank";
|
||||
|
||||
private final int capacity = CAPACITY;
|
||||
|
||||
public ItemCertusQuartzTank(Block block) {
|
||||
super(block);
|
||||
}
|
||||
|
||||
@SuppressWarnings({"rawtypes", "unchecked"})
|
||||
@Override
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean par4) {
|
||||
if (stack != null && stack.hasTagCompound()) {
|
||||
if (FluidStack.loadFluidStackFromNBT(stack.getTagCompound().getCompoundTag(tagKey)) != null) {
|
||||
FluidStack fs =
|
||||
FluidStack.loadFluidStackFromNBT(stack.getTagCompound().getCompoundTag(tagKey));
|
||||
list.add(Tooltip.fluidFormat(fs.getFluid().getLocalizedName(fs), fs.amount));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack drain(ItemStack container, int maxDrain, boolean doDrain) {
|
||||
if (container.stackTagCompound == null
|
||||
|| !container.stackTagCompound.hasKey(tagKey)
|
||||
|| container.stackTagCompound.getCompoundTag(tagKey).hasKey("Empty")) {
|
||||
return null;
|
||||
}
|
||||
|
||||
FluidStack stack = FluidStack.loadFluidStackFromNBT(container.stackTagCompound.getCompoundTag(tagKey));
|
||||
if (stack == null) {
|
||||
return null;
|
||||
}
|
||||
|
||||
int currentAmount = stack.amount;
|
||||
stack.amount = Math.min(stack.amount, maxDrain);
|
||||
if (doDrain) {
|
||||
if (currentAmount == stack.amount) {
|
||||
container.stackTagCompound.removeTag(tagKey);
|
||||
|
||||
if (container.stackTagCompound.hasNoTags()) {
|
||||
container.stackTagCompound = null;
|
||||
}
|
||||
return stack;
|
||||
}
|
||||
|
||||
NBTTagCompound fluidTag = container.stackTagCompound.getCompoundTag(tagKey);
|
||||
fluidTag.setInteger("Amount", currentAmount - stack.amount);
|
||||
container.stackTagCompound.setTag(tagKey, fluidTag);
|
||||
}
|
||||
return stack;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int fill(ItemStack container, FluidStack resource, boolean doFill) {
|
||||
if (resource == null) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (!doFill) {
|
||||
if (container.stackTagCompound == null || !container.stackTagCompound.hasKey(tagKey)) {
|
||||
return Math.min(this.capacity, resource.amount);
|
||||
}
|
||||
|
||||
FluidStack stack = FluidStack.loadFluidStackFromNBT(container.stackTagCompound.getCompoundTag(tagKey));
|
||||
|
||||
if (stack == null) {
|
||||
return Math.min(this.capacity, resource.amount);
|
||||
}
|
||||
|
||||
if (!stack.isFluidEqual(resource)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
return Math.min(this.capacity - stack.amount, resource.amount);
|
||||
}
|
||||
|
||||
if (container.stackTagCompound == null) {
|
||||
container.stackTagCompound = new NBTTagCompound();
|
||||
}
|
||||
|
||||
if (!container.stackTagCompound.hasKey(tagKey)
|
||||
|| container.stackTagCompound.getCompoundTag(tagKey).hasKey("Empty")) {
|
||||
NBTTagCompound fluidTag = resource.writeToNBT(new NBTTagCompound());
|
||||
|
||||
if (this.capacity < resource.amount) {
|
||||
fluidTag.setInteger("Amount", this.capacity);
|
||||
container.stackTagCompound.setTag(tagKey, fluidTag);
|
||||
return this.capacity;
|
||||
}
|
||||
|
||||
container.stackTagCompound.setTag(tagKey, fluidTag);
|
||||
return resource.amount;
|
||||
}
|
||||
|
||||
NBTTagCompound fluidTag = container.stackTagCompound.getCompoundTag(tagKey);
|
||||
FluidStack stack = FluidStack.loadFluidStackFromNBT(fluidTag);
|
||||
|
||||
if (!stack.isFluidEqual(resource)) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
int filled = this.capacity - stack.amount;
|
||||
if (resource.amount < filled) {
|
||||
stack.amount += resource.amount;
|
||||
filled = resource.amount;
|
||||
} else {
|
||||
stack.amount = this.capacity;
|
||||
}
|
||||
|
||||
container.stackTagCompound.setTag(tagKey, stack.writeToNBT(fluidTag));
|
||||
return filled;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCapacity(ItemStack container) {
|
||||
return this.capacity;
|
||||
}
|
||||
|
||||
@Override
|
||||
public FluidStack getFluid(ItemStack container) {
|
||||
if (container.stackTagCompound == null || !container.stackTagCompound.hasKey(tagKey)) {
|
||||
return null;
|
||||
}
|
||||
return FluidStack.loadFluidStackFromNBT(container.stackTagCompound.getCompoundTag(tagKey));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean placeBlockAt(
|
||||
ItemStack stack,
|
||||
EntityPlayer player,
|
||||
World world,
|
||||
int x,
|
||||
int y,
|
||||
int z,
|
||||
int side,
|
||||
float hitX,
|
||||
float hitY,
|
||||
float hitZ,
|
||||
int metadata) {
|
||||
if (!world.setBlock(x, y, z, this.field_150939_a, metadata, 3)) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if (world.getBlock(x, y, z) == this.field_150939_a) {
|
||||
this.field_150939_a.onBlockPlacedBy(world, x, y, z, player, stack);
|
||||
this.field_150939_a.onPostBlockPlaced(world, x, y, z, metadata);
|
||||
}
|
||||
|
||||
if (stack != null && stack.hasTagCompound()) {
|
||||
((TileCertusQuartzTank) world.getTileEntity(x, y, z)).readFromNBTWithoutCoords(stack.getTagCompound());
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
package com.glodblock.github.common.tile;
|
||||
|
||||
import buildcraft.factory.TileTank;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
import net.minecraftforge.fluids.FluidContainerRegistry;
|
||||
|
||||
public class TileCertusQuartzTank extends TileTank {
|
||||
public static final int CAPACITY = FluidContainerRegistry.BUCKET_VOLUME * 32;
|
||||
|
||||
public TileCertusQuartzTank() {
|
||||
super();
|
||||
this.setCapacity();
|
||||
}
|
||||
|
||||
public void readFromNBT(NBTTagCompound data) {
|
||||
super.readFromNBT(data);
|
||||
readFromNBTWithoutCoords(data);
|
||||
this.setCapacity();
|
||||
}
|
||||
|
||||
public void readFromNBTWithoutCoords(NBTTagCompound tag) {
|
||||
this.tank.readFromNBT(tag);
|
||||
}
|
||||
|
||||
public void writeToNBT(NBTTagCompound data) {
|
||||
super.writeToNBT(data);
|
||||
writeToNBTWithoutCoords(data);
|
||||
}
|
||||
|
||||
public void setCapacity() {
|
||||
this.tank.setCapacity(CAPACITY);
|
||||
}
|
||||
|
||||
public void writeToNBTWithoutCoords(NBTTagCompound tag) {
|
||||
this.tank.writeToNBT(tag);
|
||||
}
|
||||
}
|
||||
@@ -6,7 +6,7 @@ import com.glodblock.github.common.item.*;
|
||||
import com.glodblock.github.common.storage.CellType;
|
||||
|
||||
public class ItemAndBlockHolder {
|
||||
|
||||
public static BlockCertusQuartzTank CERTUS_QUARTZ_TANK = new BlockCertusQuartzTank().register();
|
||||
public static BlockFluidAutoFiller FLUID_AUTO_FILLER = new BlockFluidAutoFiller().register();
|
||||
public static BlockFluidDiscretizer DISCRETIZER = new BlockFluidDiscretizer().register();
|
||||
public static BlockLevelMaintainer LEVEL_MAINTAINER = new BlockLevelMaintainer().register();
|
||||
|
||||
@@ -81,6 +81,9 @@ public class RecipeLoader implements Runnable {
|
||||
AE2_INTERFACE));
|
||||
GameRegistry.addShapelessRecipe(FLUID_INTERFACE.stack(), INTERFACE.stack());
|
||||
GameRegistry.addShapelessRecipe(INTERFACE.stack(), FLUID_INTERFACE.stack());
|
||||
GameRegistry.addRecipe(
|
||||
new ShapedOreRecipe(CERTUS_QUARTZ_TANK.stack(), "GGG", "G G", "GGG", 'G', AE2_QUARTZ_GLASS));
|
||||
GameRegistry.addShapelessRecipe(FLUID_AUTO_FILLER.stack(), FLUID_TERMINAL, ENCODER);
|
||||
GameRegistry.addRecipe(new ShapedOreRecipe(
|
||||
DISCRETIZER.stack(),
|
||||
"IPI",
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package com.glodblock.github.loader;
|
||||
|
||||
import com.glodblock.github.client.render.ItemCertusQuartzTankRender;
|
||||
import com.glodblock.github.client.render.ItemDropRender;
|
||||
import com.glodblock.github.client.render.ItemPacketRender;
|
||||
import com.glodblock.github.client.render.ItemWalrusRender;
|
||||
@@ -11,5 +12,6 @@ public class RenderLoader implements Runnable {
|
||||
new ItemDropRender();
|
||||
new ItemPacketRender();
|
||||
new ItemWalrusRender();
|
||||
new ItemCertusQuartzTankRender();
|
||||
}
|
||||
}
|
||||
@@ -7,6 +7,7 @@ import net.minecraft.util.StatCollector;
|
||||
|
||||
public class NameConst {
|
||||
|
||||
public static final String BLOCK_CERTUS_QUARTZ_TANK = "certus_quartz_tank";
|
||||
public static final String BLOCK_FLUID_DISCRETIZER = "fluid_discretizer";
|
||||
public static final String BLOCK_FLUID_PATTERN_ENCODER = "fluid_pattern_encoder";
|
||||
public static final String BLOCK_FLUID_PACKET_DECODER = "fluid_packet_decoder";
|
||||
|
||||
Reference in new issue
Block a user