Skip to content

Commit

Permalink
Add particles to the alloy tank when active
Browse files Browse the repository at this point in the history
  • Loading branch information
KnightMiner committed May 17, 2019
1 parent 04ca965 commit 00d6901
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 12 deletions.
Expand Up @@ -27,6 +27,7 @@
import net.minecraft.util.BlockRenderLayer;
import net.minecraft.util.EnumFacing;
import net.minecraft.util.EnumHand;
import net.minecraft.util.EnumParticleTypes;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
Expand Down Expand Up @@ -116,13 +117,12 @@ public boolean onBlockActivated(World worldIn, BlockPos pos, IBlockState state,
}

IFluidHandler fluidHandler = te.getCapability(CapabilityFluidHandler.FLUID_HANDLER_CAPABILITY, facing);
ItemStack heldItem = playerIn.getHeldItem(hand);
if(FluidUtil.interactWithFluidHandler(playerIn, hand, fluidHandler)) {
return true; // return true as we did something
}

// prevent interaction so stuff like buckets and other things don't place the liquid block
return FluidUtil.getFluidHandler(heldItem) != null;
return FluidUtil.getFluidHandler(playerIn.getHeldItem(hand)) != null;
}


Expand Down Expand Up @@ -213,6 +213,47 @@ public int getLightValue(@Nonnull IBlockState state, IBlockAccess world, @Nonnul
return tank.getBrightness();
}

@Override
public void randomDisplayTick(IBlockState state, World world, BlockPos pos, Random rand) {
TileEntity te = world.getTileEntity(pos);
if(te instanceof TileAlloyTank && ((TileAlloyTank)te).isActive()) {
// offset position to center of block
double x = pos.getX() + 0.5D;
double y = pos.getY() + 0.5D;
double z = pos.getZ() + 0.5D;
// just beyond the face
double front = 0.52D;

// normally used for X and Z
double side = rand.nextDouble() * 0.8D - 0.4D;
// normally used for Y
double top = rand.nextDouble() * 0.8D - 0.4D;

// choose a random side (or the top) to offset
switch(rand.nextInt(5)) {
case 0:
spawnFireParticle(world, x - front, y + top, z + side);
break;
case 1:
spawnFireParticle(world, x + front, y + top, z + side);
break;
case 2:
spawnFireParticle(world, x + side, y + top, z - front);
break;
case 3:
spawnFireParticle(world, x + side, y + top, z + front);
break;
case 4:
spawnFireParticle(world, x + side, y + front, z + top);
}
}
}

private static void spawnFireParticle(World world, double x, double y, double z) {
world.spawnParticle(EnumParticleTypes.SMOKE_NORMAL, x, y, z, 0.0D, 0.0D, 0.0D);
world.spawnParticle(EnumParticleTypes.FLAME, x, y, z, 0.0D, 0.0D, 0.0D);
}

@Nonnull
@Override
@SideOnly(Side.CLIENT)
Expand Down
Expand Up @@ -57,6 +57,10 @@ public boolean shouldRefresh(World world, BlockPos pos, IBlockState oldState, IB
return oldState.getBlock() != newSate.getBlock();
}

public boolean isActive() {
return active;
}

@Override
public void update() {
if(world == null || world.isRemote) {
Expand Down Expand Up @@ -268,23 +272,30 @@ public <T> T getCapability(@Nonnull Capability<T> capability, @Nullable EnumFaci
* Validates the alloy tank structure
*/
public void checkTanks() {
// client does not need anything more
if(world.isRemote) {
return;
}

// if powered, just clear active and exit
if((this.getBlockMetadata() & 8) > 0) {
active = false;
tanks.clear();
alloyTank = null;
// if powered or not an alloy tank, just clear active and exit
if((this.getBlockMetadata() & 8) > 0 || !(this.getBlockType() instanceof BlockAlloyTank)) {
makeInactive();
return;
}

// needs to be an alloy tank so we have the block check callback
if(!(this.getBlockType() instanceof BlockAlloyTank)) {
// set active flag if this combo is valid
BlockAlloyTank tankBlock = (BlockAlloyTank)this.blockType;
if(!tankBlock.isHeater(world.getBlockState(pos.down()))) {
makeInactive();
return;
}
BlockAlloyTank tankBlock = (BlockAlloyTank)this.blockType;

if (!active) {
active = true;
// mark for update so the block model updates
IBlockState state = world.getBlockState(pos);
this.getWorld().notifyBlockUpdate(getPos(), state, state, 3);
}

// get a list of adjecent tanks
BlockPos offset;
Expand All @@ -306,9 +317,18 @@ public void checkTanks() {

// remake alloy tank
alloyTank = null;
}

// set active flag if this combo is valid
active = tankBlock.isHeater(world.getBlockState(pos.down()));
private void makeInactive() {
// if it was active, make it not so
if(active) {
// mark for update so the block model updates
IBlockState state = world.getBlockState(pos);
this.getWorld().notifyBlockUpdate(getPos(), state, state, 3);
active = false;
tanks.clear();
alloyTank = null;
}
}

@Override
Expand Down

0 comments on commit 00d6901

Please sign in to comment.