Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/main/java/org/moddingx/libx/base/BlockBase.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.moddingx.libx.base;

import net.minecraft.core.registries.Registries;
import net.minecraft.world.flag.FeatureFlagSet;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
Expand Down Expand Up @@ -85,5 +86,10 @@ public int getBurnTime(@Nonnull ItemStack stack, @Nullable RecipeType<?> recipeT
public Stream<ItemStack> makeCreativeTabStacks() {
return BlockBase.this.makeCreativeTabStacks();
}

@Override
public boolean isEnabled(@Nonnull FeatureFlagSet enabledFeatures) {
return this.getBlock().isEnabled(enabledFeatures);
}
}
}
31 changes: 29 additions & 2 deletions src/main/java/org/moddingx/libx/base/FluidBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.flag.FeatureFlagSet;
import net.minecraft.world.item.BucketItem;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.Items;
Expand Down Expand Up @@ -30,6 +31,7 @@
import javax.annotation.OverridingMethodsMustInvokeSuper;
import java.util.function.BiFunction;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.function.UnaryOperator;

/**
Expand Down Expand Up @@ -168,18 +170,20 @@ public static class Builder {
private BlockBehaviour.Properties blockProperties;
private Item.Properties bucketItemProperties;
private UnaryOperator<BaseFlowingFluid.Properties> fluidProperties;
private Supplier<Boolean> enabled;

private Builder() {
this.fluidTypeFactory = FluidType::new;
this.sourceFluidFactory = BaseFlowingFluid.Source::new;
this.flowingFluidFactory = BaseFlowingFluid.Flowing::new;
this.liquidBlockFactory = LiquidBlock::new;
this.bucketItemFactory = DefaultBucketItem::new;
this.liquidBlockFactory = this.defaultLiquidBlockFactory();
this.bucketItemFactory = this.defaultBucketItemFactory();

this.fluidTypeProperties = FluidType.Properties.create();
this.blockProperties = BlockBehaviour.Properties.ofFullCopy(Blocks.WATER);
this.bucketItemProperties = new Item.Properties().craftRemainder(Items.BUCKET).stacksTo(1);
this.fluidProperties = UnaryOperator.identity();
this.enabled = () -> true;
}

/**
Expand Down Expand Up @@ -278,6 +282,29 @@ public FluidBase.Builder fluidProperties(UnaryOperator<BaseFlowingFluid.Properti
this.fluidProperties = compose(this.fluidProperties, fluidPropertiesOp);
return this;
}

public FluidBase.Builder isEnabled(Supplier<Boolean> enabled) {
this.enabled = enabled;
return this;
}

private BiFunction<? super FlowingFluid, ? super BlockBehaviour.Properties, ? extends LiquidBlock> defaultLiquidBlockFactory() {
return (FlowingFluid fluid, BlockBehaviour.Properties properties) -> new LiquidBlock(fluid, properties) {
@Override
public boolean isEnabled(@Nonnull FeatureFlagSet enabledFeatures) {
return Builder.this.enabled.get();
}
};
}

private BiFunction<? super Fluid, ? super Item.Properties, ? extends BucketItem> defaultBucketItemFactory() {
return (Fluid content, Item.Properties properties) -> new DefaultBucketItem(content, properties) {
@Override
public boolean isEnabled(@Nonnull FeatureFlagSet enabledFeatures) {
return Builder.this.enabled.get();
}
};
}

private static <T> UnaryOperator<T> compose(UnaryOperator<T> a, UnaryOperator<T> b) {
return t -> b.apply(a.apply(t));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import net.minecraft.core.Registry;
import net.minecraft.core.registries.Registries;
import net.minecraft.resources.ResourceKey;
import net.minecraft.world.flag.FeatureFlagSet;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
Expand Down Expand Up @@ -89,5 +90,10 @@ public int getBurnTime(@Nonnull ItemStack stack, @Nullable RecipeType<?> recipeT
if (burnTime < 0) return burnTime;
return (int) Math.round(this.burnTimeModifier * burnTime);
}

@Override
public boolean isEnabled(@Nonnull FeatureFlagSet enabledFeatures) {
return this.parent.isEnabled(enabledFeatures);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import net.minecraft.core.BlockPos;
import net.minecraft.util.RandomSource;
import net.minecraft.world.flag.FeatureFlagSet;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.ButtonBlock;
Expand Down Expand Up @@ -39,4 +40,9 @@ public int getLightBlock(@Nonnull BlockState state, @Nonnull BlockGetter level,
public int getLightEmission(@Nonnull BlockState state, @Nonnull BlockGetter world, @Nonnull BlockPos pos) {
return this.parent.getLightEmission(state, world, pos);
}

@Override
public boolean isEnabled(@Nonnull FeatureFlagSet enabledFeatures) {
return this.parent.isEnabled(enabledFeatures);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import net.minecraft.core.BlockPos;
import net.minecraft.util.RandomSource;
import net.minecraft.world.flag.FeatureFlagSet;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.DoorBlock;
Expand Down Expand Up @@ -40,4 +41,9 @@ public int getLightBlock(@Nonnull BlockState state, @Nonnull BlockGetter level,
public int getLightEmission(@Nonnull BlockState state, @Nonnull BlockGetter world, @Nonnull BlockPos pos) {
return this.parent.getLightEmission(state, world, pos);
}

@Override
public boolean isEnabled(@Nonnull FeatureFlagSet enabledFeatures) {
return this.parent.isEnabled(enabledFeatures);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import net.minecraft.core.BlockPos;
import net.minecraft.util.RandomSource;
import net.minecraft.world.flag.FeatureFlagSet;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.FenceBlock;
Expand Down Expand Up @@ -39,4 +40,9 @@ public int getLightBlock(@Nonnull BlockState state, @Nonnull BlockGetter level,
public int getLightEmission(@Nonnull BlockState state, @Nonnull BlockGetter world, @Nonnull BlockPos pos) {
return this.parent.getLightEmission(state, world, pos);
}

@Override
public boolean isEnabled(@Nonnull FeatureFlagSet enabledFeatures) {
return this.parent.isEnabled(enabledFeatures);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import net.minecraft.core.BlockPos;
import net.minecraft.util.RandomSource;
import net.minecraft.world.flag.FeatureFlagSet;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.FenceGateBlock;
Expand Down Expand Up @@ -39,4 +40,9 @@ public int getLightBlock(@Nonnull BlockState state, @Nonnull BlockGetter level,
public int getLightEmission(@Nonnull BlockState state, @Nonnull BlockGetter world, @Nonnull BlockPos pos) {
return this.parent.getLightEmission(state, world, pos);
}

@Override
public boolean isEnabled(@Nonnull FeatureFlagSet enabledFeatures) {
return this.parent.isEnabled(enabledFeatures);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import net.minecraft.client.renderer.blockentity.HangingSignRenderer;
import net.minecraft.core.BlockPos;
import net.minecraft.core.registries.Registries;
import net.minecraft.world.flag.FeatureFlagSet;
import net.minecraft.world.item.HangingSignItem;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.block.CeilingHangingSignBlock;
Expand Down Expand Up @@ -47,7 +48,13 @@ public DecoratedHangingSign(ModX mod, DecoratedBlock parent) {
this.wall = new Wall(this.parent, this::getBlockEntityType, this.parent.getMaterialProperties().woodType());
//noinspection ConstantConditions
this.beType = new BlockEntityType<>((pos, state) -> new Entity(this.getBlockEntityType(), pos, state), Set.of(this.ceiling, this.wall), null);
this.item = new HangingSignItem(this.ceiling, this.wall, new Item.Properties().stacksTo(16));
this.item = new HangingSignItem(this.ceiling, this.wall, new Item.Properties().stacksTo(16)) {

@Override
public boolean isEnabled(@Nonnull FeatureFlagSet enabledFeatures) {
return parent.isEnabled(enabledFeatures);
}
};
}

@Override
Expand Down Expand Up @@ -108,6 +115,11 @@ public Ceiling(DecoratedBlock parent, Supplier<BlockEntityType<Entity>> beType,
public BlockEntity newBlockEntity(@Nonnull BlockPos pos, @Nonnull BlockState state) {
return this.beType.get().create(pos, state);
}

@Override
public boolean isEnabled(@Nonnull FeatureFlagSet enabledFeatures) {
return this.parent.isEnabled(enabledFeatures);
}
}

public static class Wall extends WallHangingSignBlock {
Expand All @@ -127,6 +139,11 @@ public Wall(DecoratedBlock parent, Supplier<BlockEntityType<Entity>> beType, Woo
public BlockEntity newBlockEntity(@Nonnull BlockPos pos, @Nonnull BlockState state) {
return this.beType.get().create(pos, state);
}

@Override
public boolean isEnabled(@Nonnull FeatureFlagSet enabledFeatures) {
return this.parent.isEnabled(enabledFeatures);
}
}

public static class Entity extends HangingSignBlockEntity {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import net.minecraft.core.BlockPos;
import net.minecraft.util.RandomSource;
import net.minecraft.world.flag.FeatureFlagSet;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.PressurePlateBlock;
Expand Down Expand Up @@ -39,4 +40,9 @@ public int getLightBlock(@Nonnull BlockState state, @Nonnull BlockGetter level,
public int getLightEmission(@Nonnull BlockState state, @Nonnull BlockGetter world, @Nonnull BlockPos pos) {
return this.parent.getLightEmission(state, world, pos);
}

@Override
public boolean isEnabled(@Nonnull FeatureFlagSet enabledFeatures) {
return this.parent.isEnabled(enabledFeatures);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import net.minecraft.client.renderer.blockentity.SignRenderer;
import net.minecraft.core.BlockPos;
import net.minecraft.core.registries.Registries;
import net.minecraft.world.flag.FeatureFlagSet;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.SignItem;
import net.minecraft.world.level.block.StandingSignBlock;
Expand Down Expand Up @@ -47,7 +48,12 @@ public DecoratedSign(ModX mod, DecoratedBlock parent) {
this.wall = new Wall(this.parent, this::getBlockEntityType, this.parent.getMaterialProperties().woodType());
//noinspection ConstantConditions
this.beType = new BlockEntityType<>((pos, state) -> new Entity(this.getBlockEntityType(), pos, state), Set.of(this.standing, this.wall), null);
this.item = new SignItem(new Item.Properties().stacksTo(16), this.standing, this.wall);
this.item = new SignItem(new Item.Properties().stacksTo(16), this.standing, this.wall) {
@Override
public boolean isEnabled(@Nonnull FeatureFlagSet enabledFeatures) {
return parent.isEnabled(enabledFeatures);
}
};
}

@Override
Expand Down Expand Up @@ -108,6 +114,11 @@ public Standing(DecoratedBlock parent, Supplier<BlockEntityType<Entity>> beType,
public BlockEntity newBlockEntity(@Nonnull BlockPos pos, @Nonnull BlockState state) {
return this.beType.get().create(pos, state);
}

@Override
public boolean isEnabled(@Nonnull FeatureFlagSet enabledFeatures) {
return this.parent.isEnabled(enabledFeatures);
}
}

public static class Wall extends WallSignBlock {
Expand All @@ -127,6 +138,11 @@ public Wall(DecoratedBlock parent, Supplier<BlockEntityType<Entity>> beType, Woo
public BlockEntity newBlockEntity(@Nonnull BlockPos pos, @Nonnull BlockState state) {
return this.beType.get().create(pos, state);
}

@Override
public boolean isEnabled(@Nonnull FeatureFlagSet enabledFeatures) {
return this.parent.isEnabled(enabledFeatures);
}
}

public static class Entity extends SignBlockEntity {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import net.minecraft.core.BlockPos;
import net.minecraft.util.RandomSource;
import net.minecraft.world.flag.FeatureFlagSet;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.SlabBlock;
Expand Down Expand Up @@ -39,4 +40,9 @@ public int getLightBlock(@Nonnull BlockState state, @Nonnull BlockGetter level,
public int getLightEmission(@Nonnull BlockState state, @Nonnull BlockGetter world, @Nonnull BlockPos pos) {
return this.parent.getLightEmission(state, world, pos);
}

@Override
public boolean isEnabled(@Nonnull FeatureFlagSet enabledFeatures) {
return this.parent.isEnabled(enabledFeatures);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import net.minecraft.core.BlockPos;
import net.minecraft.util.RandomSource;
import net.minecraft.world.flag.FeatureFlagSet;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.StairBlock;
Expand Down Expand Up @@ -39,4 +40,9 @@ public int getLightBlock(@Nonnull BlockState state, @Nonnull BlockGetter level,
public int getLightEmission(@Nonnull BlockState state, @Nonnull BlockGetter world, @Nonnull BlockPos pos) {
return this.parent.getLightEmission(state, world, pos);
}

@Override
public boolean isEnabled(@Nonnull FeatureFlagSet enabledFeatures) {
return this.parent.isEnabled(enabledFeatures);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import net.minecraft.core.BlockPos;
import net.minecraft.util.RandomSource;
import net.minecraft.world.flag.FeatureFlagSet;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.TrapDoorBlock;
Expand Down Expand Up @@ -40,4 +41,9 @@ public int getLightBlock(@Nonnull BlockState state, @Nonnull BlockGetter level,
public int getLightEmission(@Nonnull BlockState state, @Nonnull BlockGetter world, @Nonnull BlockPos pos) {
return this.parent.getLightEmission(state, world, pos);
}

@Override
public boolean isEnabled(@Nonnull FeatureFlagSet enabledFeatures) {
return this.parent.isEnabled(enabledFeatures);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import net.minecraft.core.BlockPos;
import net.minecraft.util.RandomSource;
import net.minecraft.world.flag.FeatureFlagSet;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.WallBlock;
Expand Down Expand Up @@ -39,4 +40,9 @@ public int getLightBlock(@Nonnull BlockState state, @Nonnull BlockGetter level,
public int getLightEmission(@Nonnull BlockState state, @Nonnull BlockGetter world, @Nonnull BlockPos pos) {
return this.parent.getLightEmission(state, world, pos);
}

@Override
public boolean isEnabled(@Nonnull FeatureFlagSet enabledFeatures) {
return this.parent.isEnabled(enabledFeatures);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import net.minecraft.core.BlockPos;
import net.minecraft.util.RandomSource;
import net.minecraft.world.flag.FeatureFlagSet;
import net.minecraft.world.item.context.UseOnContext;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
Expand Down Expand Up @@ -61,4 +62,9 @@ public BlockState getToolModifiedState(@Nonnull BlockState state, @Nonnull UseOn
return super.getToolModifiedState(state, context, itemAbility, simulate);
}
}

@Override
public boolean isEnabled(@Nonnull FeatureFlagSet enabledFeatures) {
return this.parent.isEnabled(enabledFeatures);
}
}