-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
cbda407
commit 4e0094a
Showing
1 changed file
with
58 additions
and
27 deletions.
There are no files selected for viewing
85 changes: 58 additions & 27 deletions
85
src/main/java/com/mmodding/mmodding_lib/library/blocks/CustomLilyPadBlock.java
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,48 +1,79 @@ | ||
package com.mmodding.mmodding_lib.library.blocks; | ||
|
||
import net.minecraft.block.LilyPadBlock; | ||
import net.minecraft.block.BlockState; | ||
import net.minecraft.block.Material; | ||
import net.minecraft.block.PlantBlock; | ||
import net.minecraft.fluid.FluidState; | ||
import net.minecraft.fluid.Fluids; | ||
import net.minecraft.item.BlockItem; | ||
import net.minecraft.item.Item; | ||
import net.minecraft.item.ItemGroup; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.world.BlockView; | ||
import org.quiltmc.qsl.item.setting.api.QuiltItemSettings; | ||
|
||
import java.util.concurrent.atomic.AtomicBoolean; | ||
import java.util.function.BiPredicate; | ||
|
||
public class CustomLilyPadBlock extends LilyPadBlock implements BlockRegistrable, BlockWithItem { | ||
public class CustomLilyPadBlock extends PlantBlock implements BlockRegistrable, BlockWithItem { | ||
|
||
private final AtomicBoolean registered = new AtomicBoolean(false); | ||
private final AtomicBoolean registered = new AtomicBoolean(false); | ||
|
||
private BlockItem item = null; | ||
private BlockItem item = null; | ||
|
||
public CustomLilyPadBlock(Settings settings) { | ||
this(settings, false); | ||
} | ||
private final BiPredicate<FluidState, BlockState> placementConditions; | ||
|
||
public CustomLilyPadBlock(Settings settings, boolean hasItem) { | ||
this(settings, hasItem, (ItemGroup) null); | ||
} | ||
public CustomLilyPadBlock(Settings settings) { | ||
this(settings, false); | ||
} | ||
|
||
public CustomLilyPadBlock(Settings settings, boolean hasItem) { | ||
this(settings, hasItem, (ItemGroup) null); | ||
} | ||
|
||
public CustomLilyPadBlock(Settings settings, boolean hasItem, ItemGroup itemGroup) { | ||
this(settings, hasItem, itemGroup != null ? new QuiltItemSettings().group(itemGroup) : new QuiltItemSettings()); | ||
} | ||
|
||
public CustomLilyPadBlock(Settings settings, boolean hasItem, Item.Settings itemSettings) { | ||
super(settings); | ||
if (hasItem) this.item = new BlockItem(this, itemSettings); | ||
} | ||
public CustomLilyPadBlock(Settings settings, boolean hasItem, Item.Settings itemSettings) { | ||
this((fluid, floor) -> fluid.isOf(Fluids.WATER) || floor.getMaterial().equals(Material.ICE), settings, hasItem, itemSettings); | ||
} | ||
|
||
public CustomLilyPadBlock(BiPredicate<FluidState, BlockState> placementConditions, Settings settings) { | ||
this(placementConditions, settings, false); | ||
} | ||
|
||
public CustomLilyPadBlock(BiPredicate<FluidState, BlockState> placementConditions, Settings settings, boolean hasItem) { | ||
this(placementConditions, settings, hasItem, (ItemGroup) null); | ||
} | ||
|
||
public CustomLilyPadBlock(BiPredicate<FluidState, BlockState> placementConditions, Settings settings, boolean hasItem, ItemGroup itemGroup) { | ||
this(placementConditions, settings, hasItem, itemGroup != null ? new QuiltItemSettings().group(itemGroup) : new QuiltItemSettings()); | ||
} | ||
|
||
public CustomLilyPadBlock(BiPredicate<FluidState, BlockState> placementConditions, Settings settings, boolean hasItem, Item.Settings itemSettings) { | ||
super(settings); | ||
if (hasItem) this.item = new BlockItem(this, itemSettings); | ||
this.placementConditions = placementConditions; | ||
} | ||
|
||
@Override | ||
protected boolean canPlantOnTop(BlockState floor, BlockView world, BlockPos pos) { | ||
return this.placementConditions.test(world.getFluidState(pos), floor) && world.getFluidState(pos.up()).isEmpty(); | ||
} | ||
|
||
@Override | ||
public BlockItem getItem() { | ||
return this.item; | ||
} | ||
|
||
@Override | ||
public boolean isNotRegistered() { | ||
return !this.registered.get(); | ||
} | ||
|
||
@Override | ||
public void setRegistered() { | ||
this.registered.set(true); | ||
} | ||
public BlockItem getItem() { | ||
return this.item; | ||
} | ||
|
||
@Override | ||
public boolean isNotRegistered() { | ||
return !this.registered.get(); | ||
} | ||
|
||
@Override | ||
public void setRegistered() { | ||
this.registered.set(true); | ||
} | ||
} |