Skip to content

Commit

Permalink
Add a slight delay to faucet redstone activation
Browse files Browse the repository at this point in the history
Prevents faucets starting a fluid transfer in the middle of another blocks's update.
Appears to the the cause of #3297 and #3390, as the comparator logic from tanks causes a block update in the middle of fillInternal, which may drain the tank before the fill method empties
  • Loading branch information
KnightMiner committed May 26, 2019
1 parent 624a85c commit 1922710
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 12 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package slimeknights.tconstruct.smeltery.block;

import com.google.common.collect.ImmutableMap;

import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.SoundType;
Expand All @@ -22,12 +21,12 @@
import net.minecraft.world.World;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import slimeknights.tconstruct.library.TinkerRegistry;
import slimeknights.tconstruct.smeltery.tileentity.TileFaucet;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

import slimeknights.tconstruct.library.TinkerRegistry;
import slimeknights.tconstruct.smeltery.tileentity.TileFaucet;
import java.util.Random;

public class BlockFaucet extends BlockContainer {

Expand Down Expand Up @@ -95,13 +94,21 @@ public boolean canConnectRedstone(IBlockState state, IBlockAccess world, BlockPo
}

@Override
public void neighborChanged(IBlockState state, World worldIn, BlockPos pos, Block blockIn, BlockPos fromPos) {
if(worldIn.isRemote) {
public void neighborChanged(IBlockState state, World world, BlockPos pos, Block blockIn, BlockPos fromPos) {
if (world.isRemote) {
return;
}
TileEntity te = worldIn.getTileEntity(pos);
TileEntity te = world.getTileEntity(pos);
if (te instanceof TileFaucet) {
((TileFaucet) te).handleRedstone(world.isBlockPowered(pos));
}
}

@Override
public void updateTick(World world, BlockPos pos, IBlockState state, Random rand) {
TileEntity te = world.getTileEntity(pos);
if(te instanceof TileFaucet) {
((TileFaucet) te).handleRedstone(worldIn.isBlockPowered(pos));
((TileFaucet) te).activate();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,13 @@
import net.minecraftforge.fluids.capability.IFluidHandler;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;

import javax.annotation.Nonnull;

import slimeknights.tconstruct.common.TinkerNetwork;
import slimeknights.tconstruct.library.materials.Material;
import slimeknights.tconstruct.smeltery.block.BlockFaucet;
import slimeknights.tconstruct.smeltery.network.FaucetActivationPacket;

import javax.annotation.Nonnull;

public class TileFaucet extends TileEntity implements ITickable {

public static final int LIQUID_TRANSFER = 6; // how much liquid is transferred per operation
Expand Down Expand Up @@ -62,7 +61,7 @@ public void handleRedstone(boolean hasSignal) {
if(hasSignal != lastRedstoneState) {
lastRedstoneState = hasSignal;
if(hasSignal) {
activate();
world.scheduleUpdate(pos, this.getBlockType(), 2);
}
}
}
Expand Down

0 comments on commit 1922710

Please sign in to comment.