Created
June 19, 2020 15:53
-
-
Save HexBugOrion/471d76ed57db5e3f1ee3ebe5d0dd3969 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package net.oriondev.discovery_core.blocks; | |
import net.minecraft.block.*; | |
import net.minecraft.fluid.FluidState; | |
import net.minecraft.fluid.Fluids; | |
import net.minecraft.item.ItemPlacementContext; | |
import net.minecraft.state.StateManager; | |
import net.minecraft.state.property.BooleanProperty; | |
import net.minecraft.state.property.Properties; | |
import net.minecraft.tag.FluidTags; | |
import net.minecraft.util.math.BlockPos; | |
import net.minecraft.util.math.Direction; | |
import net.minecraft.world.IWorld; | |
public class FlareBlock extends Block implements Waterloggable { | |
public static BooleanProperty WATERLOGGED; | |
public FlareBlock(Block.Settings settings) { | |
super(settings); | |
this.setDefaultState((BlockState)((BlockState)this.stateManager.getDefaultState()).with(WATERLOGGED, true)); | |
} | |
@Override | |
public BlockState getPlacementState(ItemPlacementContext ctx) { | |
final BlockState state = super.getPlacementState(ctx); | |
if (state.contains(Properties.WATERLOGGED)) { | |
final FluidState fluidState = ctx.getWorld().getFluidState(ctx.getBlockPos()); | |
final boolean source = fluidState.matches(FluidTags.WATER) && fluidState.getLevel() == 8; | |
return state.with(Properties.WATERLOGGED, source); | |
} | |
return state; | |
} | |
@Override | |
public BlockState getStateForNeighborUpdate(BlockState state, Direction facing, BlockState neighborState, IWorld world, BlockPos pos, BlockPos neighborPos) { | |
if ((Boolean)state.get(WATERLOGGED)) { | |
world.getFluidTickScheduler().schedule(pos, Fluids.WATER, Fluids.WATER.getTickRate(world)); | |
} | |
return super.getStateForNeighborUpdate(state, facing, neighborState, world, pos, neighborPos); | |
} | |
@Override | |
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) { | |
builder.add(Properties.WATERLOGGED); | |
} | |
@Override | |
public FluidState getFluidState(BlockState state) { | |
return state.contains(Properties.WATERLOGGED) && state.get(Properties.WATERLOGGED) ? Fluids.WATER.getStill(false) : super.getFluidState(state); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment