Skip to content
This repository has been archived by the owner on May 13, 2023. It is now read-only.

Commit

Permalink
Implement a functioning Blood Tank (WayofTime#969)
Browse files Browse the repository at this point in the history
Added a search bar to the Upgrade Tomes Creative Tab
Updated some Altar fluid code (remove deprecated stuff)
Moved Rendering classes into appropriate package
Fix the localization errors on the Demon Crystals
A few cleanups here and there
  • Loading branch information
Arcaratus authored and TehNut committed Dec 12, 2016
1 parent d1f4e95 commit aac2623
Show file tree
Hide file tree
Showing 40 changed files with 915 additions and 235 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ curse_id=224791

mappings_version=snapshot_20160518

jei_version=3.4.0.204
jei_version=3.6.8.225
waila_version=1.7.0-B3
thaumcraft_version=5.1.5
baubles_version=1.1.3.0
Expand Down
11 changes: 10 additions & 1 deletion src/main/java/WayofTime/bloodmagic/BloodMagic.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,12 @@ public Item getTabIconItem()
{
return ModItems.UPGRADE_TOME;
}

@Override
public boolean hasSearchBar()
{
return true;
}
};

@Getter
Expand All @@ -90,11 +96,14 @@ public Item getTabIconItem()

Class proxyClass = Class.forName(PROXY_MAP.get(mcVersion));
crossVersionProxy = (ICrossVersionProxy) proxyClass.newInstance();
} catch (Exception e)
}
catch (Exception e)
{
throw new IllegalArgumentException("Blood Magic could not find a cross version proxy!", e);
}

tabUpgradeTome.setNoTitle().setBackgroundImageName("upgrade_tomes.png");

FluidRegistry.enableUniversalBucket();
}

Expand Down
30 changes: 17 additions & 13 deletions src/main/java/WayofTime/bloodmagic/altar/BloodAltar.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import net.minecraft.world.World;
import net.minecraft.world.WorldServer;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;
import net.minecraftforge.fluids.FluidTank;
import net.minecraftforge.fluids.capability.FluidTankPropertiesWrapper;
Expand Down Expand Up @@ -53,7 +53,7 @@ public class BloodAltar implements IFluidHandler
protected FluidStack fluidInput = new FluidStack(BlockLifeEssence.getLifeEssence(), 0);
private EnumAltarTier altarTier = EnumAltarTier.ONE;
private AltarUpgrade upgrade;
private int capacity = FluidContainerRegistry.BUCKET_VOLUME * 10;
private int capacity = Fluid.BUCKET_VOLUME * 10;
private FluidStack fluid = new FluidStack(BloodMagicAPI.getLifeEssence(), 0);
private int liquidRequired; // mB
private boolean canBeFilled;
Expand All @@ -69,7 +69,7 @@ public class BloodAltar implements IFluidHandler
private int accelerationUpgrades;
private boolean isUpgraded;
private boolean isResultBlock;
private int bufferCapacity = FluidContainerRegistry.BUCKET_VOLUME;
private int bufferCapacity = Fluid.BUCKET_VOLUME;
private int progress;
private int lockdownDuration;
private int demonBloodDuration;
Expand Down Expand Up @@ -352,13 +352,15 @@ public void startCycle()
if (!isActive)
progress = 0;

if (tileAltar.getStackInSlot(0) != null)
ItemStack input = tileAltar.getStackInSlot(0);

if (input != null)
{
// Do recipes
AltarRecipe recipe = AltarRecipeRegistry.getRecipeForInput(tileAltar.getStackInSlot(0));
AltarRecipe recipe = AltarRecipeRegistry.getRecipeForInput(input);
if (recipe != null)
{
if (recipe.doesRequiredItemMatch(tileAltar.getStackInSlot(0), altarTier))
if (recipe.doesRequiredItemMatch(input, altarTier))
{
this.isActive = true;
this.recipe = recipe;
Expand Down Expand Up @@ -395,7 +397,7 @@ public void update()
{
BlockPos newPos = pos.offset(facing);
IBlockState block = world.getBlockState(newPos);
block.getBlock().neighborChanged(block, world, newPos, block.getBlock());
block.getBlock().onNeighborChange(world, pos, newPos);
}
}
if (internalCounter % (Math.max(20 - this.accelerationUpgrades, 1)) == 0)
Expand Down Expand Up @@ -438,7 +440,9 @@ private void updateAltar()
return;
}

if (tileAltar.getStackInSlot(0) == null)
ItemStack input = tileAltar.getStackInSlot(0);

if (input == null)
return;

World world = tileAltar.getWorld();
Expand All @@ -450,7 +454,7 @@ private void updateAltar()
if (!canBeFilled)
{
boolean hasOperated = false;
int stackSize = tileAltar.getStackInSlot(0).stackSize;
int stackSize = input.stackSize;

if (totalCharge > 0)
{
Expand Down Expand Up @@ -517,7 +521,7 @@ private void updateAltar()
{
ItemStack returnedItem = tileAltar.getStackInSlot(0);

if (!(returnedItem.getItem() instanceof IBloodOrb))
if (returnedItem == null || !(returnedItem.getItem() instanceof IBloodOrb))
return;

IBloodOrb item = (IBloodOrb) (returnedItem.getItem());
Expand Down Expand Up @@ -590,11 +594,11 @@ public void checkTier()
this.orbCapacityMultiplier = (float) (1 + 0.02 * upgrade.getOrbCapacityCount());
this.chargingFrequency = Math.max(20 - upgrade.getAccelerationCount(), 1);
this.chargingRate = (int) (10 * upgrade.getChargingCount() * (1 + consumptionMultiplier / 2));
this.maxCharge = (int) (FluidContainerRegistry.BUCKET_VOLUME * Math.max(0.5 * capacityMultiplier, 1) * upgrade.getChargingCount());
this.maxCharge = (int) (Fluid.BUCKET_VOLUME * Math.max(0.5 * capacityMultiplier, 1) * upgrade.getChargingCount());
}

this.capacity = (int) (FluidContainerRegistry.BUCKET_VOLUME * 10 * capacityMultiplier);
this.bufferCapacity = (int) (FluidContainerRegistry.BUCKET_VOLUME * 1 * capacityMultiplier);
this.capacity = (int) (Fluid.BUCKET_VOLUME * 10 * capacityMultiplier);
this.bufferCapacity = (int) (Fluid.BUCKET_VOLUME * 1 * capacityMultiplier);

if (this.fluid.amount > this.capacity)
this.fluid.amount = this.capacity;
Expand Down
3 changes: 3 additions & 0 deletions src/main/java/WayofTime/bloodmagic/api/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ public static class NBT
public static final String POTION_AUGMENT_LENGHT = "length:";
public static final String POTION_AUGMENT_STRENGTH = "strength:";
public static final String POTION_IMPURITY = "impurity";

public static final String TANK = "tank";
}

public static class Mod
Expand Down Expand Up @@ -161,6 +163,7 @@ public static class Compat
public static final String WAILA_CONFIG_TELEPOSER = Mod.MODID + ".teleposer";
public static final String WAILA_CONFIG_RITUAL = Mod.MODID + ".ritualController";
public static final String WAILA_CONFIG_ARRAY = Mod.MODID + ".array";
public static final String WAILA_CONFIG_BLOOD_TANK = Mod.MODID + ".bloodTank";

public static final Item THAUMCRAFT_GOGGLES = ForgeRegistries.ITEMS.getValue(new ResourceLocation("Thaumcraft", "goggles"));
}
Expand Down
153 changes: 119 additions & 34 deletions src/main/java/WayofTime/bloodmagic/block/BlockBloodTank.java
Original file line number Diff line number Diff line change
@@ -1,33 +1,43 @@
package WayofTime.bloodmagic.block;

import java.util.ArrayList;
import java.util.List;

import WayofTime.bloodmagic.BloodMagic;
import WayofTime.bloodmagic.api.Constants;
import WayofTime.bloodmagic.client.IVariantProvider;
import WayofTime.bloodmagic.tile.TileBloodTank;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.SoundType;
import net.minecraft.block.material.Material;
import net.minecraft.block.properties.IProperty;
import net.minecraft.block.properties.PropertyInteger;
import net.minecraft.block.state.BlockStateContainer;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityLivingBase;
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.BlockRenderLayer;
import net.minecraft.util.EnumBlockRenderType;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import net.minecraftforge.fluids.FluidContainerRegistry;
import net.minecraftforge.fluids.FluidStack;
import WayofTime.bloodmagic.BloodMagic;
import WayofTime.bloodmagic.api.Constants;
import WayofTime.bloodmagic.tile.TileBloodTank;
import WayofTime.bloodmagic.util.Utils;
import net.minecraftforge.fluids.FluidUtil;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import org.apache.commons.lang3.tuple.ImmutablePair;
import org.apache.commons.lang3.tuple.Pair;

public class BlockBloodTank extends BlockContainer
import java.util.ArrayList;
import java.util.List;

public class BlockBloodTank extends BlockContainer implements IVariantProvider
{
public static final PropertyInteger TIER = PropertyInteger.create("tier", 0, TileBloodTank.capacities.length - 1);

public BlockBloodTank()
{
super(Material.IRON);
Expand All @@ -38,12 +48,22 @@ public BlockBloodTank()
setSoundType(SoundType.GLASS);
setHarvestLevel("pickaxe", 1);
setCreativeTab(BloodMagic.tabBloodMagic);
setLightOpacity(0);

setDefaultState(blockState.getBaseState().withProperty(TIER, 0));
}

// This is important!!! - DON'T DELETE - idk why
@Override
public TileEntity createTileEntity(World worldIn, IBlockState blockState)
{
return new TileBloodTank(getMetaFromState(blockState));
}

@Override
public TileEntity createNewTileEntity(World worldIn, int meta)
{
return new TileBloodTank();
return new TileBloodTank(meta);
}

@Override
Expand All @@ -52,33 +72,71 @@ public EnumBlockRenderType getRenderType(IBlockState state)
return EnumBlockRenderType.MODEL;
}

@Override
@SideOnly(Side.CLIENT)
public BlockRenderLayer getBlockLayer()
{
return BlockRenderLayer.TRANSLUCENT;
}

@Override
public boolean isFullCube(IBlockState state)
{
return false;
}

@Override
public boolean isOpaqueCube(IBlockState state)
{
return false;
}

@Override
public IBlockState getStateFromMeta(int meta)
{
return this.getDefaultState().withProperty(TIER, meta);
}

@Override
public int getMetaFromState(IBlockState state)
{
return state.getValue(TIER);
}

@Override
public IBlockState getActualState(IBlockState state, IBlockAccess world, BlockPos pos)
{
if (world.getTileEntity(pos) == null)
return state;
return state.withProperty(TIER, world.getTileEntity(pos).getBlockMetadata());
}

@Override
protected BlockStateContainer createBlockState()
{
return new BlockStateContainer(this, new IProperty[] { TIER });
}

@Override
public boolean onBlockActivated(World world, BlockPos blockPos, IBlockState state, EntityPlayer player, EnumHand hand, ItemStack heldItem, EnumFacing side, float hitX, float hitY, float hitZ)
{
TileBloodTank fluidHandler = (TileBloodTank) world.getTileEntity(blockPos);
if (Utils.fillHandlerWithContainer(world, fluidHandler, player))
if (FluidUtil.interactWithFluidHandler(heldItem, fluidHandler.getTank(), player))
{
world.notifyBlockUpdate(blockPos, state, state, 3);
return true;
}
if (Utils.fillContainerFromHandler(world, fluidHandler, player, fluidHandler.tank.getFluid()))
{
world.notifyBlockUpdate(blockPos, state, state, 3);
return true;
}
if (FluidContainerRegistry.isContainer(heldItem))
{
world.notifyBlockUpdate(blockPos, state, state, 3);
world.checkLight(blockPos);
world.updateComparatorOutputLevel(blockPos, this);
world.markAndNotifyBlock(blockPos, world.getChunkFromBlockCoords(blockPos), state, state, 3);
return true;
}

return super.onBlockActivated(world, blockPos, state, player, hand, heldItem, side, hitX, hitY, hitZ);
return false;
}

@Override
public void onBlockHarvested(World worldIn, BlockPos pos, IBlockState state, EntityPlayer player)
{
this.dropBlockAsItem(worldIn, pos, state, 0);
if (!player.capabilities.isCreativeMode)
this.dropBlockAsItem(worldIn, pos, state, 0);
super.onBlockHarvested(worldIn, pos, state, player);
}

Expand All @@ -92,8 +150,9 @@ public List<ItemStack> getDrops(IBlockAccess world, BlockPos blockPos, IBlockSta
TileBloodTank bloodTank = (TileBloodTank) world.getTileEntity(blockPos);
ItemStack drop = new ItemStack(this);
NBTTagCompound tag = new NBTTagCompound();
bloodTank.writeToNBT(tag);
bloodTank.serialize(tag);
drop.setTagCompound(tag);
drop.setItemDamage(getMetaFromState(blockState));
list.add(drop);
}

Expand All @@ -108,31 +167,57 @@ public void onBlockPlacedBy(World world, BlockPos blockPos, IBlockState blockSta
NBTTagCompound tag = stack.getTagCompound();
if (tag != null)
{
world.getTileEntity(blockPos).readFromNBT(tag);
((TileBloodTank) world.getTileEntity(blockPos)).deserialize(tag);
blockState.withProperty(TIER, stack.getMetadata());
}
}

world.checkLight(blockPos);
world.updateComparatorOutputLevel(blockPos, this);
world.markAndNotifyBlock(blockPos, world.getChunkFromBlockCoords(blockPos), blockState, blockState, 3);
}

@Override
public int getLightValue(IBlockState state, IBlockAccess world, BlockPos pos)
{
TileEntity tile = world.getTileEntity(pos);

if (tile instanceof TileBloodTank)
{
TileBloodTank tank = (TileBloodTank) tile;
FluidStack fluid = tank.tank.getFluid();
if (fluid != null)
{
return fluid.getFluid().getLuminosity(fluid);
}
FluidStack fluidStack = ((TileBloodTank) tile).getTank().getFluid();
return fluidStack == null || fluidStack.amount <= 0 ? 0 : fluidStack.getFluid().getLuminosity(fluidStack);
}
return 0;

return super.getLightValue(state, world, pos);
}

@Override
public ItemStack getPickBlock(IBlockState state, RayTraceResult target, World world, BlockPos pos, EntityPlayer player)
{
return getDrops(world, pos, world.getBlockState(pos), 0).get(0);
}

@Override
public boolean hasComparatorInputOverride(IBlockState state)
{
return true;
}

@Override
public int getComparatorInputOverride(IBlockState state, World w, BlockPos pos)
{
TileEntity tile = w.getTileEntity(pos);
if (tile instanceof TileBloodTank)
return ((TileBloodTank) tile).getComparatorOutput();
return 0;
}

@Override
public List<Pair<Integer, String>> getVariants()
{
List<Pair<Integer, String>> ret = new ArrayList<Pair<Integer, String>>();
for (int i = 0; i < TileBloodTank.capacities.length; i++)
ret.add(new ImmutablePair<Integer, String>(i, "inventory"));

return ret;
}
}
Loading

0 comments on commit aac2623

Please sign in to comment.