-
Notifications
You must be signed in to change notification settings - Fork 2
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
91bd98e
commit 9fa8f9e
Showing
12 changed files
with
368 additions
and
45 deletions.
There are no files selected for viewing
64 changes: 48 additions & 16 deletions
64
src/generated/resources/assets/kasuga_lib/blockstates/test/example_fluid.json
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,20 +1,52 @@ | ||
{ | ||
"variants": { | ||
"level=0": {}, | ||
"level=1": {}, | ||
"level=2": {}, | ||
"level=3": {}, | ||
"level=4": {}, | ||
"level=5": {}, | ||
"level=6": {}, | ||
"level=7": {}, | ||
"level=8": {}, | ||
"level=9": {}, | ||
"level=10": {}, | ||
"level=11": {}, | ||
"level=12": {}, | ||
"level=13": {}, | ||
"level=14": {}, | ||
"level=15": {} | ||
"level=0": { | ||
"model": "minecraft:block/air" | ||
}, | ||
"level=1": { | ||
"model": "minecraft:block/air" | ||
}, | ||
"level=2": { | ||
"model": "minecraft:block/air" | ||
}, | ||
"level=3": { | ||
"model": "minecraft:block/air" | ||
}, | ||
"level=4": { | ||
"model": "minecraft:block/air" | ||
}, | ||
"level=5": { | ||
"model": "minecraft:block/air" | ||
}, | ||
"level=6": { | ||
"model": "minecraft:block/air" | ||
}, | ||
"level=7": { | ||
"model": "minecraft:block/air" | ||
}, | ||
"level=8": { | ||
"model": "minecraft:block/air" | ||
}, | ||
"level=9": { | ||
"model": "minecraft:block/air" | ||
}, | ||
"level=10": { | ||
"model": "minecraft:block/air" | ||
}, | ||
"level=11": { | ||
"model": "minecraft:block/air" | ||
}, | ||
"level=12": { | ||
"model": "minecraft:block/air" | ||
}, | ||
"level=13": { | ||
"model": "minecraft:block/air" | ||
}, | ||
"level=14": { | ||
"model": "minecraft:block/air" | ||
}, | ||
"level=15": { | ||
"model": "minecraft:block/air" | ||
} | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
src/generated/resources/data/forge/tags/fluids/example_fluid.json
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 |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"values": [ | ||
"kasuga_lib:example_fluid_still", | ||
"kasuga_lib:example_fluid_flow" | ||
] | ||
} |
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 |
---|---|---|
@@ -0,0 +1,169 @@ | ||
package kasuga.lib.core.base; | ||
|
||
import kasuga.lib.core.util.LazyRecomputable; | ||
import net.minecraft.advancements.CriteriaTriggers; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.core.Direction; | ||
import net.minecraft.core.particles.ParticleTypes; | ||
import net.minecraft.server.level.ServerPlayer; | ||
import net.minecraft.sounds.SoundEvent; | ||
import net.minecraft.sounds.SoundEvents; | ||
import net.minecraft.sounds.SoundSource; | ||
import net.minecraft.stats.Stats; | ||
import net.minecraft.tags.FluidTags; | ||
import net.minecraft.world.InteractionHand; | ||
import net.minecraft.world.InteractionResultHolder; | ||
import net.minecraft.world.entity.player.Player; | ||
import net.minecraft.world.item.ItemStack; | ||
import net.minecraft.world.item.ItemUtils; | ||
import net.minecraft.world.level.Level; | ||
import net.minecraft.world.level.LevelAccessor; | ||
import net.minecraft.world.level.block.Block; | ||
import net.minecraft.world.level.block.BucketPickup; | ||
import net.minecraft.world.level.block.LiquidBlockContainer; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import net.minecraft.world.level.gameevent.GameEvent; | ||
import net.minecraft.world.level.material.FlowingFluid; | ||
import net.minecraft.world.level.material.Fluid; | ||
import net.minecraft.world.level.material.Fluids; | ||
import net.minecraft.world.level.material.Material; | ||
import net.minecraft.world.phys.BlockHitResult; | ||
import net.minecraft.world.phys.HitResult; | ||
import net.minecraftforge.common.SoundActions; | ||
import net.minecraftforge.event.ForgeEventFactory; | ||
import net.minecraftforge.fluids.FluidStack; | ||
import net.minecraftforge.fluids.FluidUtil; | ||
|
||
import javax.annotation.Nullable; | ||
import java.util.Optional; | ||
import java.util.function.Supplier; | ||
|
||
public class BucketItem extends net.minecraft.world.item.BucketItem { | ||
|
||
private final LazyRecomputable<Fluid> fluidSupplier; | ||
|
||
public BucketItem(Supplier<? extends Fluid> supplier, Properties builder) { | ||
super(supplier, builder); | ||
fluidSupplier = LazyRecomputable.of(supplier::get); | ||
} | ||
|
||
public InteractionResultHolder<ItemStack> use(Level pLevel, Player pPlayer, InteractionHand pHand) { | ||
Fluid content = fluidSupplier.get(); | ||
ItemStack itemstack = pPlayer.getItemInHand(pHand); | ||
BlockHitResult blockhitresult = getPlayerPOVHitResult(pLevel, pPlayer, content == Fluids.EMPTY ? net.minecraft.world.level.ClipContext.Fluid.SOURCE_ONLY : net.minecraft.world.level.ClipContext.Fluid.NONE); | ||
InteractionResultHolder<ItemStack> ret = ForgeEventFactory.onBucketUse(pPlayer, pLevel, itemstack, blockhitresult); | ||
if (ret != null) { | ||
return ret; | ||
} else if (blockhitresult.getType() == HitResult.Type.MISS) { | ||
return InteractionResultHolder.pass(itemstack); | ||
} else if (blockhitresult.getType() != HitResult.Type.BLOCK) { | ||
return InteractionResultHolder.pass(itemstack); | ||
} else { | ||
BlockPos blockpos = blockhitresult.getBlockPos(); | ||
Direction direction = blockhitresult.getDirection(); | ||
BlockPos blockpos1 = blockpos.relative(direction); | ||
if (pLevel.mayInteract(pPlayer, blockpos) && pPlayer.mayUseItemAt(blockpos1, direction, itemstack)) { | ||
BlockState blockstate1; | ||
if (content == Fluids.EMPTY) { | ||
blockstate1 = pLevel.getBlockState(blockpos); | ||
if (blockstate1.getBlock() instanceof BucketPickup) { | ||
BucketPickup bucketpickup = (BucketPickup)blockstate1.getBlock(); | ||
ItemStack itemstack1 = bucketpickup.pickupBlock(pLevel, blockpos, blockstate1); | ||
if (!itemstack1.isEmpty()) { | ||
pPlayer.awardStat(Stats.ITEM_USED.get(this)); | ||
bucketpickup.getPickupSound(blockstate1).ifPresent((p_150709_) -> { | ||
pPlayer.playSound(p_150709_, 1.0F, 1.0F); | ||
}); | ||
pLevel.gameEvent(pPlayer, GameEvent.FLUID_PICKUP, blockpos); | ||
ItemStack itemstack2 = ItemUtils.createFilledResult(itemstack, pPlayer, itemstack1); | ||
if (!pLevel.isClientSide) { | ||
CriteriaTriggers.FILLED_BUCKET.trigger((ServerPlayer)pPlayer, itemstack1); | ||
} | ||
|
||
return InteractionResultHolder.sidedSuccess(itemstack2, pLevel.isClientSide()); | ||
} | ||
} | ||
|
||
return InteractionResultHolder.fail(itemstack); | ||
} else { | ||
blockstate1 = pLevel.getBlockState(blockpos); | ||
BlockPos blockpos2 = this.canBlockContainFluid(pLevel, blockpos, blockstate1) ? blockpos : blockpos1; | ||
if (this.emptyContents(pPlayer, pLevel, blockpos2, blockhitresult, itemstack)) { | ||
this.checkExtraContent(pPlayer, pLevel, itemstack, blockpos2); | ||
if (pPlayer instanceof ServerPlayer) { | ||
CriteriaTriggers.PLACED_BLOCK.trigger((ServerPlayer)pPlayer, blockpos2, itemstack); | ||
} | ||
|
||
pPlayer.awardStat(Stats.ITEM_USED.get(this)); | ||
return InteractionResultHolder.sidedSuccess(getEmptySuccessItem(itemstack, pPlayer), pLevel.isClientSide()); | ||
} else { | ||
return InteractionResultHolder.fail(itemstack); | ||
} | ||
} | ||
} else { | ||
return InteractionResultHolder.fail(itemstack); | ||
} | ||
} | ||
} | ||
|
||
public boolean emptyContents(@Nullable Player p_150716_, Level p_150717_, BlockPos p_150718_, @Nullable BlockHitResult p_150719_, @Nullable ItemStack container) { | ||
Fluid content = fluidSupplier.get(); | ||
if (!(content instanceof FlowingFluid)) { | ||
return false; | ||
} else { | ||
BlockState blockstate = p_150717_.getBlockState(p_150718_); | ||
Block block = blockstate.getBlock(); | ||
Material material = blockstate.getMaterial(); | ||
boolean flag = blockstate.canBeReplaced(content); | ||
boolean flag1 = blockstate.isAir() || flag || block instanceof LiquidBlockContainer && ((LiquidBlockContainer)block).canPlaceLiquid(p_150717_, p_150718_, blockstate, content); | ||
Optional<FluidStack> containedFluidStack = Optional.ofNullable(container).flatMap(FluidUtil::getFluidContained); | ||
if (!flag1) { | ||
return p_150719_ != null && this.emptyContents(p_150716_, p_150717_, p_150719_.getBlockPos().relative(p_150719_.getDirection()), (BlockHitResult)null, container); | ||
} else if (containedFluidStack.isPresent() && content.getFluidType().isVaporizedOnPlacement(p_150717_, p_150718_, (FluidStack)containedFluidStack.get())) { | ||
content.getFluidType().onVaporize(p_150716_, p_150717_, p_150718_, (FluidStack)containedFluidStack.get()); | ||
return true; | ||
} else if (p_150717_.dimensionType().ultraWarm() && content.is(FluidTags.WATER)) { | ||
int i = p_150718_.getX(); | ||
int j = p_150718_.getY(); | ||
int k = p_150718_.getZ(); | ||
p_150717_.playSound(p_150716_, p_150718_, SoundEvents.FIRE_EXTINGUISH, SoundSource.BLOCKS, 0.5F, 2.6F + (p_150717_.random.nextFloat() - p_150717_.random.nextFloat()) * 0.8F); | ||
|
||
for(int l = 0; l < 8; ++l) { | ||
p_150717_.addParticle(ParticleTypes.LARGE_SMOKE, (double)i + Math.random(), (double)j + Math.random(), (double)k + Math.random(), 0.0, 0.0, 0.0); | ||
} | ||
|
||
return true; | ||
} else if (block instanceof LiquidBlockContainer && ((LiquidBlockContainer)block).canPlaceLiquid(p_150717_, p_150718_, blockstate, content)) { | ||
((LiquidBlockContainer)block).placeLiquid(p_150717_, p_150718_, blockstate, ((FlowingFluid)content).getSource(false)); | ||
this.playEmptySound(p_150716_, p_150717_, p_150718_); | ||
return true; | ||
} else { | ||
if (!p_150717_.isClientSide && flag && !material.isLiquid()) { | ||
p_150717_.destroyBlock(p_150718_, true); | ||
} | ||
|
||
if (!p_150717_.setBlock(p_150718_, content.defaultFluidState().createLegacyBlock(), 11) && !blockstate.getFluidState().isSource()) { | ||
return false; | ||
} else { | ||
this.playEmptySound(p_150716_, p_150717_, p_150718_); | ||
return true; | ||
} | ||
} | ||
} | ||
} | ||
|
||
protected void playEmptySound(@Nullable Player pPlayer, LevelAccessor pLevel, BlockPos pPos) { | ||
Fluid content = fluidSupplier.get(); | ||
SoundEvent soundevent = content.getFluidType().getSound(pPlayer, pLevel, pPos, SoundActions.BUCKET_EMPTY); | ||
if (soundevent == null) { | ||
soundevent = content.is(FluidTags.LAVA) ? SoundEvents.BUCKET_EMPTY_LAVA : SoundEvents.BUCKET_EMPTY; | ||
} | ||
|
||
pLevel.playSound(pPlayer, pPos, soundevent, SoundSource.BLOCKS, 1.0F, 1.0F); | ||
pLevel.gameEvent(pPlayer, GameEvent.FLUID_PLACE, pPos); | ||
} | ||
|
||
protected boolean canBlockContainFluid(Level worldIn, BlockPos posIn, BlockState blockstate) { | ||
return blockstate.getBlock() instanceof LiquidBlockContainer && ((LiquidBlockContainer)blockstate.getBlock()).canPlaceLiquid(worldIn, posIn, blockstate, fluidSupplier.get()); | ||
} | ||
} |
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
48 changes: 48 additions & 0 deletions
48
src/main/java/kasuga/lib/example_env/block/fluid/ExampleFluid.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 |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package kasuga.lib.example_env.block.fluid; | ||
|
||
import kasuga.lib.registrations.common.FluidReg; | ||
import net.minecraft.resources.ResourceLocation; | ||
import net.minecraft.world.level.block.state.StateDefinition; | ||
import net.minecraft.world.level.material.FlowingFluid; | ||
import net.minecraft.world.level.material.Fluid; | ||
import net.minecraft.world.level.material.FluidState; | ||
import net.minecraftforge.common.extensions.IForgeFluid; | ||
import net.minecraftforge.fluids.FluidType; | ||
import net.minecraftforge.fluids.ForgeFlowingFluid; | ||
import net.minecraftforge.registries.RegistryObject; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class ExampleFluid extends ForgeFlowingFluid { | ||
|
||
|
||
public ExampleFluid(Properties properties) { | ||
super(properties); | ||
} | ||
|
||
@Override | ||
protected void createFluidStateDefinition(StateDefinition.Builder<Fluid, FluidState> pBuilder) { | ||
super.createFluidStateDefinition(pBuilder.add(LEVEL)); | ||
} | ||
|
||
@Override | ||
public boolean isSource(FluidState fluidState) { | ||
return true; | ||
} | ||
|
||
@Override | ||
public int getAmount(@NotNull FluidState fluidState) { | ||
return isSource(fluidState) ? 8 : (Integer) fluidState.getValue(LEVEL); | ||
} | ||
|
||
public static class Flowing extends ExampleFluid { | ||
|
||
public Flowing(Properties properties) { | ||
super(properties); | ||
} | ||
|
||
@Override | ||
public boolean isSource(FluidState fluidState) { | ||
return false; | ||
} | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
src/main/java/kasuga/lib/example_env/block/fluid/ExampleFluidBlock.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 |
---|---|---|
@@ -0,0 +1,26 @@ | ||
package kasuga.lib.example_env.block.fluid; | ||
|
||
import net.minecraft.world.item.context.BlockPlaceContext; | ||
import net.minecraft.world.level.block.Block; | ||
import net.minecraft.world.level.block.LiquidBlock; | ||
import net.minecraft.world.level.block.state.BlockBehaviour; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import net.minecraft.world.level.block.state.StateDefinition; | ||
import net.minecraft.world.level.material.FlowingFluid; | ||
import net.minecraftforge.fluids.ForgeFlowingFluid; | ||
import net.minecraftforge.fluids.IFluidBlock; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.function.Supplier; | ||
|
||
public class ExampleFluidBlock extends LiquidBlock { | ||
|
||
public ExampleFluidBlock(Supplier<? extends ForgeFlowingFluid> supplier, Properties properties) { | ||
super(supplier, properties); | ||
} | ||
|
||
@Override | ||
public @Nullable BlockState getStateForPlacement(BlockPlaceContext pContext) { | ||
return super.getStateForPlacement(pContext).setValue(LEVEL, 8); | ||
} | ||
} |
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
Oops, something went wrong.