Skip to content

Commit

Permalink
Merge branch 'master' into feat/channel
Browse files Browse the repository at this point in the history
  • Loading branch information
TimeBather authored Nov 19, 2024
2 parents 3a57a23 + d8a4d19 commit a68b42f
Show file tree
Hide file tree
Showing 42 changed files with 1,375 additions and 47 deletions.
3 changes: 3 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,9 @@ dependencies {
annotationProcessor "org.spongepowered:mixin:${mixin_version}:processor"
testAnnotationProcessor "org.spongepowered:mixin:${mixin_version}:processor"

implementation "org.projectlombok:lombok:1.18.34"
annotationProcessor "org.projectlombok:lombok:1.18.34"

// implementation files('libs/Mixed-Arithmetic-Logic-Interpreter-1.0.0.jar')

minecraftLibrary ('org.lwjgl:lwjgl-yoga:3.3.1') {
Expand Down
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"
}
}
}
3 changes: 2 additions & 1 deletion src/generated/resources/assets/kasuga_lib/lang/en_us.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"tips.block": "--------------------------------------=== all blocks ===--------------------------------------",
"block.kasuga_lib.green_apple": "Green Apple"
"block.kasuga_lib.green_apple": "Green Apple",
"item.kasuga_lib.example_fluid_bucket": "Example Fluid Bucket"
}
3 changes: 2 additions & 1 deletion src/generated/resources/assets/kasuga_lib/lang/zh_cn.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{
"tips.block": "--------------------------------------=== 方块 ===--------------------------------------",
"block.kasuga_lib.green_apple": "绿色林檎"
"block.kasuga_lib.green_apple": "绿色林檎",
"item.kasuga_lib.example_fluid_bucket": "范例液体桶"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"parent": "item/generated",
"textures": {
"layer0": "kasuga_lib:item/example_fluid_bucket"
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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"
]
}
169 changes: 169 additions & 0 deletions src/main/java/kasuga/lib/core/base/BucketItem.java
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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,13 @@ public DomNode(T context) {
this.domContext = context;
}

public boolean addChildBefore(DomNode<T> child, DomNode<T> before){
int index = children.indexOf(before);
if(index == -1)
return false;
return addChildAt(index,child);
}

public boolean addChildAt(int i, DomNode<T> child){
if(child.parent != null)
return false;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,18 +69,34 @@ public LayoutContext<?,GuiDomNode> getLayoutManager() {

protected BackgroundRenderer background = new BackgroundRenderer();

@HostAccess.Export
@Override
public boolean addChildBefore(DomNode<GuiContext> child, DomNode<GuiContext> before) {
this.domContext.queueDuringRender(()->{
int index = children.indexOf(before);
if(index == -1)
return;
addChildInstant(index, child);
});
return true;
}

@HostAccess.Export
@Override
public boolean addChildAt(int i, DomNode<GuiContext> child) {
this.domContext.queueDuringRender(()->{
if(child instanceof GuiDomNode domNode)
getLayoutManager().addChild(i,domNode.getLayoutManager());
styles.notifyUpdate();
super.addChildAt(i,child);
addChildInstant(i, child);
});
return true;
}

protected void addChildInstant(int i, DomNode<GuiContext> child){
if(child instanceof GuiDomNode domNode)
getLayoutManager().addChild(i,domNode.getLayoutManager());
styles.notifyUpdate();
super.addChildAt(i,child);
}

@HostAccess.Export
@Override
public boolean removeChild(DomNode<GuiContext> child) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package kasuga.lib.core.util.nbt_json;

import com.google.gson.JsonElement;
import kasuga.lib.core.util.nbt_json.collection.ByteArrayPair;
import kasuga.lib.core.util.nbt_json.collection.IntArrayPair;
import kasuga.lib.core.util.nbt_json.collection.LongArrayPair;
import kasuga.lib.core.util.nbt_json.primitive.BooleanPair;
import kasuga.lib.core.util.nbt_json.primitive.StringPair;
import kasuga.lib.core.util.nbt_json.primitive.numeric.*;
import net.minecraft.nbt.*;

public class AllConversionPairs {

public static final BooleanPair BOOLEAN_PAIR = new BooleanPair();
public static final StringPair STRING_PAIR = new StringPair();
public static final BytePair BYTE_PAIR = new BytePair();
public static final DoublePair DOUBLE_PAIR = new DoublePair();
public static final FloatPair FLOAT_PAIR = new FloatPair();
public static final IntPair INT_PAIR = new IntPair();
public static final LongPair LONG_PAIR = new LongPair();
public static final ShortPair SHORT_PAIR = new ShortPair();
public static final ByteArrayPair BYTE_ARRAY_PAIR = new ByteArrayPair();
public static final IntArrayPair INT_ARRAY_PAIR = new IntArrayPair();
public static final LongArrayPair LONG_ARRAY_PAIR = new LongArrayPair();

public static final Converter CONVERTER = new Converter();

static {
CONVERTER.addDefaultConversions();
}
}
Loading

0 comments on commit a68b42f

Please sign in to comment.