Merge branch 'main' of github.com:paulevsGitch/BCLib

This commit is contained in:
Frank Bauer 2021-07-20 00:44:49 +02:00
commit 65b70f57ad
134 changed files with 3347 additions and 1210 deletions

View file

@ -8,7 +8,7 @@ yarn_mappings= 6
loader_version= 0.11.6
# Mod Properties
mod_version = 0.2.5
mod_version = 0.3.0
maven_group = ru.bclib
archives_base_name = bclib

View file

@ -24,7 +24,12 @@ public class BiomeAPI {
* Empty biome used as default value if requested biome doesn't exist or linked. Shouldn't be registered anywhere to prevent bugs.
* Have {@code Biomes.THE_VOID} as the reference biome.
*/
public static final BCLBiome EMPTY_BIOME = new BCLBiome(Biomes.THE_VOID.location(), BuiltinRegistries.BIOME.get(Biomes.THE_VOID), 1, 0);
public static final BCLBiome EMPTY_BIOME = new BCLBiome(
Biomes.THE_VOID.location(),
BuiltinRegistries.BIOME.get(Biomes.THE_VOID),
1,
0
);
private static final HashMap<ResourceLocation, BCLBiome> ID_MAP = Maps.newHashMap();
private static final HashMap<Biome, BCLBiome> CLIENT = Maps.newHashMap();
@ -55,7 +60,13 @@ public class BiomeAPI {
public static void addNetherBiomeToFabricApi(BCLBiome biome) {
ResourceKey<Biome> key = BuiltinRegistries.BIOME.getResourceKey(biome.getBiome()).get();
Random random = new Random(biome.getID().toString().hashCode());
ClimateParameters parameters = new ClimateParameters(MHelper.randRange(-2F, 2F, random), MHelper.randRange(-2F, 2F, random), MHelper.randRange(-2F, 2F, random), MHelper.randRange(-2F, 2F, random), MHelper.randRange(-2F, 2F, random));
ClimateParameters parameters = new ClimateParameters(
MHelper.randRange(-2F, 2F, random),
MHelper.randRange(-2F, 2F, random),
MHelper.randRange(-2F, 2F, random),
MHelper.randRange(-2F, 2F, random),
MHelper.randRange(-2F, 2F, random)
);
InternalBiomeData.addNetherBiome(key, parameters);
}
@ -106,7 +117,9 @@ public class BiomeAPI {
BCLBiome endBiome = CLIENT.get(biome);
if (endBiome == null) {
Minecraft minecraft = Minecraft.getInstance();
ResourceLocation id = minecraft.level.registryAccess().registryOrThrow(Registry.BIOME_REGISTRY).getKey(biome);
ResourceLocation id = minecraft.level.registryAccess()
.registryOrThrow(Registry.BIOME_REGISTRY)
.getKey(biome);
endBiome = id == null ? EMPTY_BIOME : ID_MAP.getOrDefault(id, EMPTY_BIOME);
CLIENT.put(biome, endBiome);
}

View file

@ -134,7 +134,16 @@ public class BaseBarrelBlockEntity extends RandomizableContainerBlockEntity {
double d = (double) this.worldPosition.getX() + 0.5D + (double) vec3i.getX() / 2.0D;
double e = (double) this.worldPosition.getY() + 0.5D + (double) vec3i.getY() / 2.0D;
double f = (double) this.worldPosition.getZ() + 0.5D + (double) vec3i.getZ() / 2.0D;
level.playSound(null, d, e, f, soundEvent, SoundSource.BLOCKS, 0.5F, this.level.random.nextFloat() * 0.1F + 0.9F);
level.playSound(
null,
d,
e,
f,
soundEvent,
SoundSource.BLOCKS,
0.5F,
this.level.random.nextFloat() * 0.1F + 0.9F
);
}
}
}

View file

@ -4,10 +4,12 @@ import com.google.common.collect.Lists;
import com.google.common.collect.Maps;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.item.v1.FabricItemSettings;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.client.renderer.block.model.BlockModel;
import net.minecraft.client.resources.model.UnbakedModel;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.level.block.AnvilBlock;
@ -20,16 +22,17 @@ import net.minecraft.world.level.material.MaterialColor;
import net.minecraft.world.level.storage.loot.LootContext;
import org.jetbrains.annotations.Nullable;
import ru.bclib.client.models.BasePatterns;
import ru.bclib.client.models.BlockModelProvider;
import ru.bclib.client.models.ModelsHelper;
import ru.bclib.client.models.PatternsHelper;
import ru.bclib.interfaces.BlockModelProvider;
import ru.bclib.interfaces.CustomItemProvider;
import ru.bclib.items.BaseAnvilItem;
import java.util.List;
import java.util.Map;
import java.util.Optional;
public abstract class BaseAnvilBlock extends AnvilBlock implements BlockModelProvider {
public abstract class BaseAnvilBlock extends AnvilBlock implements BlockModelProvider, CustomItemProvider {
public static final IntegerProperty DESTRUCTION = BlockProperties.DESTRUCTION;
public BaseAnvilBlock(MaterialColor color) {
@ -59,9 +62,6 @@ public abstract class BaseAnvilBlock extends AnvilBlock implements BlockModelPro
return blockId.getPath() + "_top_" + last;
}
@Override
public abstract Item asItem();
@Override
@Environment(EnvType.CLIENT)
public BlockModel getItemModel(ResourceLocation blockId) {
@ -91,4 +91,9 @@ public abstract class BaseAnvilBlock extends AnvilBlock implements BlockModelPro
registerBlockModel(stateId, modelLocation, blockState, modelCache);
return ModelsHelper.createFacingModel(modelLocation, blockState.getValue(FACING), false, false);
}
@Override
public BlockItem getCustomItem(ResourceLocation blockID, FabricItemSettings settings) {
return new BaseAnvilItem(this, settings);
}
}

View file

@ -28,9 +28,9 @@ import net.minecraft.world.phys.BlockHitResult;
import org.jetbrains.annotations.Nullable;
import ru.bclib.blockentities.BaseBarrelBlockEntity;
import ru.bclib.client.models.BasePatterns;
import ru.bclib.client.models.BlockModelProvider;
import ru.bclib.client.models.ModelsHelper;
import ru.bclib.client.models.PatternsHelper;
import ru.bclib.interfaces.BlockModelProvider;
import ru.bclib.registry.BaseBlockEntities;
import java.util.List;

View file

@ -8,7 +8,7 @@ import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.MaterialColor;
import net.minecraft.world.level.storage.loot.LootContext;
import ru.bclib.client.models.BlockModelProvider;
import ru.bclib.interfaces.BlockModelProvider;
import java.util.Collections;
import java.util.List;

View file

@ -15,9 +15,9 @@ import net.minecraft.world.level.block.state.properties.AttachFace;
import net.minecraft.world.level.storage.loot.LootContext;
import org.jetbrains.annotations.Nullable;
import ru.bclib.client.models.BasePatterns;
import ru.bclib.client.models.BlockModelProvider;
import ru.bclib.client.models.ModelsHelper;
import ru.bclib.client.models.PatternsHelper;
import ru.bclib.interfaces.BlockModelProvider;
import java.util.Collections;
import java.util.List;
@ -51,7 +51,10 @@ public abstract class BaseButtonBlock extends ButtonBlock implements BlockModelP
@Environment(EnvType.CLIENT)
public @Nullable BlockModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) {
ResourceLocation parentId = Registry.BLOCK.getKey(parent);
Optional<String> pattern = blockState.getValue(POWERED) ? PatternsHelper.createJson(BasePatterns.BLOCK_BUTTON_PRESSED, parentId) : PatternsHelper.createJson(BasePatterns.BLOCK_BUTTON, parentId);
Optional<String> pattern = blockState.getValue(POWERED) ? PatternsHelper.createJson(
BasePatterns.BLOCK_BUTTON_PRESSED,
parentId
) : PatternsHelper.createJson(BasePatterns.BLOCK_BUTTON, parentId);
return ModelsHelper.fromPattern(pattern);
}

View file

@ -15,18 +15,18 @@ import net.minecraft.world.level.material.MaterialColor;
import net.minecraft.world.level.storage.loot.LootContext;
import org.jetbrains.annotations.Nullable;
import ru.bclib.client.models.BasePatterns;
import ru.bclib.client.models.BlockModelProvider;
import ru.bclib.client.models.ModelsHelper;
import ru.bclib.client.models.PatternsHelper;
import ru.bclib.client.render.BCLRenderLayer;
import ru.bclib.interfaces.IRenderTyped;
import ru.bclib.interfaces.BlockModelProvider;
import ru.bclib.interfaces.RenderLayerProvider;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
public class BaseChainBlock extends ChainBlock implements BlockModelProvider, IRenderTyped {
public class BaseChainBlock extends ChainBlock implements BlockModelProvider, RenderLayerProvider {
public BaseChainBlock(MaterialColor color) {
super(FabricBlockSettings.copyOf(Blocks.CHAIN).mapColor(color));
}

View file

@ -15,9 +15,9 @@ import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.storage.loot.LootContext;
import org.jetbrains.annotations.Nullable;
import ru.bclib.client.models.BasePatterns;
import ru.bclib.client.models.BlockModelProvider;
import ru.bclib.client.models.ModelsHelper;
import ru.bclib.client.models.PatternsHelper;
import ru.bclib.interfaces.BlockModelProvider;
import ru.bclib.registry.BaseBlockEntities;
import java.util.List;

View file

@ -13,10 +13,10 @@ import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.storage.loot.LootContext;
import org.jetbrains.annotations.Nullable;
import ru.bclib.client.models.BasePatterns;
import ru.bclib.client.models.BlockModelProvider;
import ru.bclib.client.models.ModelsHelper;
import ru.bclib.client.models.ModelsHelper.MultiPartBuilder;
import ru.bclib.client.models.PatternsHelper;
import ru.bclib.interfaces.BlockModelProvider;
import java.util.Collections;
import java.util.List;

View file

@ -12,9 +12,9 @@ import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.storage.loot.LootContext;
import org.jetbrains.annotations.Nullable;
import ru.bclib.client.models.BasePatterns;
import ru.bclib.client.models.BlockModelProvider;
import ru.bclib.client.models.ModelsHelper;
import ru.bclib.client.models.PatternsHelper;
import ru.bclib.interfaces.BlockModelProvider;
import java.util.Collections;
import java.util.HashMap;

View file

@ -38,7 +38,12 @@ public class BaseCropBlock extends BasePlantBlock {
private final Item drop;
public BaseCropBlock(Item drop, Block... terrain) {
super(FabricBlockSettings.of(Material.PLANT).breakByTool(FabricToolTags.HOES).breakByHand(true).sound(SoundType.GRASS).randomTicks().noCollission());
super(FabricBlockSettings.of(Material.PLANT)
.breakByTool(FabricToolTags.HOES)
.breakByHand(true)
.sound(SoundType.GRASS)
.randomTicks()
.noCollission());
this.drop = drop;
this.terrain = terrain;
this.registerDefaultState(defaultBlockState().setValue(AGE, 0));

View file

@ -18,18 +18,18 @@ import net.minecraft.world.level.block.state.properties.DoubleBlockHalf;
import net.minecraft.world.level.storage.loot.LootContext;
import org.jetbrains.annotations.Nullable;
import ru.bclib.client.models.BasePatterns;
import ru.bclib.client.models.BlockModelProvider;
import ru.bclib.client.models.ModelsHelper;
import ru.bclib.client.models.PatternsHelper;
import ru.bclib.client.render.BCLRenderLayer;
import ru.bclib.interfaces.IRenderTyped;
import ru.bclib.interfaces.BlockModelProvider;
import ru.bclib.interfaces.RenderLayerProvider;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
public class BaseDoorBlock extends DoorBlock implements IRenderTyped, BlockModelProvider {
public class BaseDoorBlock extends DoorBlock implements RenderLayerProvider, BlockModelProvider {
public BaseDoorBlock(Block source) {
super(FabricBlockSettings.copyOf(source).strength(3F, 3F).noOcclusion());
}
@ -114,7 +114,10 @@ public class BaseDoorBlock extends DoorBlock implements IRenderTyped, BlockModel
}
break;
}
ResourceLocation modelId = new ResourceLocation(stateId.getNamespace(), "block/" + stateId.getPath() + "_" + doorType);
ResourceLocation modelId = new ResourceLocation(
stateId.getNamespace(),
"block/" + stateId.getPath() + "_" + doorType
);
registerBlockModel(stateId, modelId, blockState, modelCache);
return ModelsHelper.createMultiVariant(modelId, rotation.getRotation(), false);
}

View file

@ -31,25 +31,34 @@ import net.minecraft.world.phys.Vec3;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;
import ru.bclib.client.render.BCLRenderLayer;
import ru.bclib.interfaces.IRenderTyped;
import ru.bclib.interfaces.RenderLayerProvider;
import ru.bclib.util.BlocksHelper;
import java.util.List;
import java.util.Random;
@SuppressWarnings("deprecation")
public abstract class BaseDoublePlantBlock extends BaseBlockNotFull implements IRenderTyped, BonemealableBlock {
public abstract class BaseDoublePlantBlock extends BaseBlockNotFull implements RenderLayerProvider, BonemealableBlock {
private static final VoxelShape SHAPE = Block.box(4, 2, 4, 12, 16, 12);
public static final IntegerProperty ROTATION = BlockProperties.ROTATION;
public static final BooleanProperty TOP = BooleanProperty.create("top");
public BaseDoublePlantBlock() {
super(FabricBlockSettings.of(Material.PLANT).breakByTool(FabricToolTags.SHEARS).breakByHand(true).sound(SoundType.WET_GRASS).noCollission());
super(FabricBlockSettings.of(Material.PLANT)
.breakByTool(FabricToolTags.SHEARS)
.breakByHand(true)
.sound(SoundType.WET_GRASS)
.noCollission());
this.registerDefaultState(this.stateDefinition.any().setValue(TOP, false));
}
public BaseDoublePlantBlock(int light) {
super(FabricBlockSettings.of(Material.PLANT).breakByTool(FabricToolTags.SHEARS).breakByHand(true).sound(SoundType.WET_GRASS).lightLevel((state) -> state.getValue(TOP) ? light : 0).noCollission());
super(FabricBlockSettings.of(Material.PLANT)
.breakByTool(FabricToolTags.SHEARS)
.breakByHand(true)
.sound(SoundType.WET_GRASS)
.lightLevel((state) -> state.getValue(TOP) ? light : 0)
.noCollission());
this.registerDefaultState(this.stateDefinition.any().setValue(TOP, false));
}
@ -101,7 +110,10 @@ public abstract class BaseDoublePlantBlock extends BaseBlockNotFull implements I
}
ItemStack tool = builder.getParameter(LootContextParams.TOOL);
if (tool != null && FabricToolTags.SHEARS.contains(tool.getItem()) || EnchantmentHelper.getItemEnchantmentLevel(Enchantments.SILK_TOUCH, tool) > 0) {
if (tool != null && FabricToolTags.SHEARS.contains(tool.getItem()) || EnchantmentHelper.getItemEnchantmentLevel(
Enchantments.SILK_TOUCH,
tool
) > 0) {
return Lists.newArrayList(new ItemStack(this));
}
else {
@ -126,7 +138,13 @@ public abstract class BaseDoublePlantBlock extends BaseBlockNotFull implements I
@Override
public void performBonemeal(ServerLevel world, Random random, BlockPos pos, BlockState state) {
ItemEntity item = new ItemEntity(world, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, new ItemStack(this));
ItemEntity item = new ItemEntity(
world,
pos.getX() + 0.5,
pos.getY() + 0.5,
pos.getZ() + 0.5,
new ItemStack(this)
);
world.addFreshEntity(item);
}

View file

@ -15,10 +15,10 @@ import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.storage.loot.LootContext;
import org.jetbrains.annotations.Nullable;
import ru.bclib.client.models.BasePatterns;
import ru.bclib.client.models.BlockModelProvider;
import ru.bclib.client.models.ModelsHelper;
import ru.bclib.client.models.ModelsHelper.MultiPartBuilder;
import ru.bclib.client.models.PatternsHelper;
import ru.bclib.interfaces.BlockModelProvider;
import java.util.Collections;
import java.util.List;
@ -72,9 +72,21 @@ public class BaseFenceBlock extends FenceBlock implements BlockModelProvider {
MultiPartBuilder builder = MultiPartBuilder.create(stateDefinition);
builder.part(sideId).setCondition(state -> state.getValue(NORTH)).setUVLock(true).add();
builder.part(sideId).setCondition(state -> state.getValue(EAST)).setTransformation(BlockModelRotation.X0_Y90.getRotation()).setUVLock(true).add();
builder.part(sideId).setCondition(state -> state.getValue(SOUTH)).setTransformation(BlockModelRotation.X0_Y180.getRotation()).setUVLock(true).add();
builder.part(sideId).setCondition(state -> state.getValue(WEST)).setTransformation(BlockModelRotation.X0_Y270.getRotation()).setUVLock(true).add();
builder.part(sideId)
.setCondition(state -> state.getValue(EAST))
.setTransformation(BlockModelRotation.X0_Y90.getRotation())
.setUVLock(true)
.add();
builder.part(sideId)
.setCondition(state -> state.getValue(SOUTH))
.setTransformation(BlockModelRotation.X0_Y180.getRotation())
.setUVLock(true)
.add();
builder.part(sideId)
.setCondition(state -> state.getValue(WEST))
.setTransformation(BlockModelRotation.X0_Y270.getRotation())
.setUVLock(true)
.add();
builder.part(postId).add();
return builder.build();

View file

@ -26,18 +26,18 @@ import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
import org.jetbrains.annotations.Nullable;
import ru.bclib.blockentities.BaseFurnaceBlockEntity;
import ru.bclib.client.models.BasePatterns;
import ru.bclib.client.models.BlockModelProvider;
import ru.bclib.client.models.ModelsHelper;
import ru.bclib.client.models.PatternsHelper;
import ru.bclib.client.render.BCLRenderLayer;
import ru.bclib.interfaces.IRenderTyped;
import ru.bclib.interfaces.BlockModelProvider;
import ru.bclib.interfaces.RenderLayerProvider;
import ru.bclib.registry.BaseBlockEntities;
import java.util.List;
import java.util.Map;
import java.util.Optional;
public class BaseFurnaceBlock extends FurnaceBlock implements BlockModelProvider, IRenderTyped {
public class BaseFurnaceBlock extends FurnaceBlock implements BlockModelProvider, RenderLayerProvider {
public BaseFurnaceBlock(Block source) {
super(FabricBlockSettings.copyOf(source).luminance(state -> state.getValue(LIT) ? 13 : 0));
}
@ -119,6 +119,10 @@ public class BaseFurnaceBlock extends FurnaceBlock implements BlockModelProvider
@Nullable
protected static <T extends BlockEntity> BlockEntityTicker<T> createFurnaceTicker(Level level, BlockEntityType<T> blockEntityType, BlockEntityType<? extends AbstractFurnaceBlockEntity> blockEntityType2) {
return level.isClientSide ? null : createTickerHelper(blockEntityType, blockEntityType2, AbstractFurnaceBlockEntity::serverTick);
return level.isClientSide ? null : createTickerHelper(
blockEntityType,
blockEntityType2,
AbstractFurnaceBlockEntity::serverTick
);
}
}

View file

@ -14,9 +14,9 @@ import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.storage.loot.LootContext;
import org.jetbrains.annotations.Nullable;
import ru.bclib.client.models.BasePatterns;
import ru.bclib.client.models.BlockModelProvider;
import ru.bclib.client.models.ModelsHelper;
import ru.bclib.client.models.PatternsHelper;
import ru.bclib.interfaces.BlockModelProvider;
import java.util.Collections;
import java.util.List;
@ -51,10 +51,16 @@ public class BaseGateBlock extends FenceGateBlock implements BlockModelProvider
ResourceLocation parentId = Registry.BLOCK.getKey(parent);
Optional<String> pattern;
if (inWall) {
pattern = isOpen ? PatternsHelper.createJson(BasePatterns.BLOCK_GATE_OPEN_WALL, parentId) : PatternsHelper.createJson(BasePatterns.BLOCK_GATE_CLOSED_WALL, parentId);
pattern = isOpen ? PatternsHelper.createJson(
BasePatterns.BLOCK_GATE_OPEN_WALL,
parentId
) : PatternsHelper.createJson(BasePatterns.BLOCK_GATE_CLOSED_WALL, parentId);
}
else {
pattern = isOpen ? PatternsHelper.createJson(BasePatterns.BLOCK_GATE_OPEN, parentId) : PatternsHelper.createJson(BasePatterns.BLOCK_GATE_CLOSED, parentId);
pattern = isOpen ? PatternsHelper.createJson(
BasePatterns.BLOCK_GATE_OPEN,
parentId
) : PatternsHelper.createJson(BasePatterns.BLOCK_GATE_CLOSED, parentId);
}
return ModelsHelper.fromPattern(pattern);
}

View file

@ -28,18 +28,18 @@ import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;
import org.jetbrains.annotations.Nullable;
import ru.bclib.client.models.BasePatterns;
import ru.bclib.client.models.BlockModelProvider;
import ru.bclib.client.models.ModelsHelper;
import ru.bclib.client.models.PatternsHelper;
import ru.bclib.client.render.BCLRenderLayer;
import ru.bclib.interfaces.IRenderTyped;
import ru.bclib.interfaces.BlockModelProvider;
import ru.bclib.interfaces.RenderLayerProvider;
import ru.bclib.util.BlocksHelper;
import java.util.Map;
import java.util.Optional;
@SuppressWarnings("deprecation")
public class BaseLadderBlock extends BaseBlockNotFull implements IRenderTyped, BlockModelProvider {
public class BaseLadderBlock extends BaseBlockNotFull implements RenderLayerProvider, BlockModelProvider {
public static final DirectionProperty FACING = HorizontalDirectionalBlock.FACING;
public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED;
protected static final VoxelShape EAST_SHAPE = Block.box(0.0D, 0.0D, 0.0D, 3.0D, 16.0D, 16.0D);

View file

@ -15,20 +15,27 @@ import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.MaterialColor;
import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
import ru.bclib.client.models.BlockModelProvider;
import ru.bclib.client.render.BCLRenderLayer;
import ru.bclib.interfaces.IRenderTyped;
import ru.bclib.interfaces.BlockModelProvider;
import ru.bclib.interfaces.RenderLayerProvider;
import ru.bclib.util.MHelper;
import java.util.Collections;
import java.util.List;
import java.util.function.Consumer;
public class BaseLeavesBlock extends LeavesBlock implements BlockModelProvider, IRenderTyped {
public class BaseLeavesBlock extends LeavesBlock implements BlockModelProvider, RenderLayerProvider {
private final Block sapling;
private static FabricBlockSettings makeLeaves(MaterialColor color) {
return FabricBlockSettings.copyOf(Blocks.OAK_LEAVES).mapColor(color).breakByTool(FabricToolTags.HOES).breakByTool(FabricToolTags.SHEARS).breakByHand(true).allowsSpawning((state, world, pos, type) -> false).suffocates((state, world, pos) -> false).blockVision((state, world, pos) -> false);
return FabricBlockSettings.copyOf(Blocks.OAK_LEAVES)
.mapColor(color)
.breakByTool(FabricToolTags.HOES)
.breakByTool(FabricToolTags.SHEARS)
.breakByHand(true)
.allowsSpawning((state, world, pos, type) -> false)
.suffocates((state, world, pos) -> false)
.blockVision((state, world, pos) -> false);
}
public BaseLeavesBlock(Block sapling, MaterialColor color, Consumer<FabricBlockSettings> customizeProperties) {
@ -61,7 +68,10 @@ public class BaseLeavesBlock extends LeavesBlock implements BlockModelProvider,
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
ItemStack tool = builder.getParameter(LootContextParams.TOOL);
if (tool != null) {
if (FabricToolTags.SHEARS.contains(tool.getItem()) || EnchantmentHelper.getItemEnchantmentLevel(Enchantments.SILK_TOUCH, tool) > 0) {
if (FabricToolTags.SHEARS.contains(tool.getItem()) || EnchantmentHelper.getItemEnchantmentLevel(
Enchantments.SILK_TOUCH,
tool
) > 0) {
return Collections.singletonList(new ItemStack(this));
}
int fortune = EnchantmentHelper.getItemEnchantmentLevel(Enchantments.BLOCK_FORTUNE, tool);

View file

@ -16,18 +16,18 @@ import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.storage.loot.LootContext;
import org.jetbrains.annotations.Nullable;
import ru.bclib.client.models.BasePatterns;
import ru.bclib.client.models.BlockModelProvider;
import ru.bclib.client.models.ModelsHelper;
import ru.bclib.client.models.PatternsHelper;
import ru.bclib.client.render.BCLRenderLayer;
import ru.bclib.interfaces.IRenderTyped;
import ru.bclib.interfaces.BlockModelProvider;
import ru.bclib.interfaces.RenderLayerProvider;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.Optional;
public class BaseMetalBarsBlock extends IronBarsBlock implements BlockModelProvider, IRenderTyped {
public class BaseMetalBarsBlock extends IronBarsBlock implements BlockModelProvider, RenderLayerProvider {
public BaseMetalBarsBlock(Block source) {
super(FabricBlockSettings.copyOf(source).strength(5.0F, 6.0F).noOcclusion());
}
@ -81,11 +81,26 @@ public class BaseMetalBarsBlock extends IronBarsBlock implements BlockModelProvi
registerBlockModel(sideId, sideId, blockState, modelCache);
ModelsHelper.MultiPartBuilder builder = ModelsHelper.MultiPartBuilder.create(stateDefinition);
builder.part(postId).setCondition(state -> !state.getValue(NORTH) && !state.getValue(EAST) && !state.getValue(SOUTH) && !state.getValue(WEST)).add();
builder.part(postId)
.setCondition(state -> !state.getValue(NORTH) && !state.getValue(EAST) && !state.getValue(SOUTH) && !state
.getValue(WEST))
.add();
builder.part(sideId).setCondition(state -> state.getValue(NORTH)).setUVLock(true).add();
builder.part(sideId).setCondition(state -> state.getValue(EAST)).setTransformation(BlockModelRotation.X0_Y90.getRotation()).setUVLock(true).add();
builder.part(sideId).setCondition(state -> state.getValue(SOUTH)).setTransformation(BlockModelRotation.X0_Y180.getRotation()).setUVLock(true).add();
builder.part(sideId).setCondition(state -> state.getValue(WEST)).setTransformation(BlockModelRotation.X0_Y270.getRotation()).setUVLock(true).add();
builder.part(sideId)
.setCondition(state -> state.getValue(EAST))
.setTransformation(BlockModelRotation.X0_Y90.getRotation())
.setUVLock(true)
.add();
builder.part(sideId)
.setCondition(state -> state.getValue(SOUTH))
.setTransformation(BlockModelRotation.X0_Y180.getRotation())
.setUVLock(true)
.add();
builder.part(sideId)
.setCondition(state -> state.getValue(WEST))
.setTransformation(BlockModelRotation.X0_Y270.getRotation())
.setUVLock(true)
.add();
return builder.build();
}

View file

@ -16,7 +16,7 @@ import net.minecraft.world.level.material.Material;
import net.minecraft.world.level.material.MaterialColor;
import net.minecraft.world.level.storage.loot.LootContext;
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
import ru.bclib.client.models.BlockModelProvider;
import ru.bclib.interfaces.BlockModelProvider;
import ru.bclib.util.MHelper;
import java.util.Collections;
@ -28,7 +28,11 @@ public class BaseOreBlock extends OreBlock implements BlockModelProvider {
private final int maxCount;
public BaseOreBlock(Item drop, int minCount, int maxCount, int experience) {
super(FabricBlockSettings.of(Material.STONE, MaterialColor.SAND).hardness(3F).resistance(9F).requiresCorrectToolForDrops().sound(SoundType.STONE), UniformInt.of(1, experience));
super(FabricBlockSettings.of(Material.STONE, MaterialColor.SAND)
.hardness(3F)
.resistance(9F)
.requiresCorrectToolForDrops()
.sound(SoundType.STONE), UniformInt.of(1, experience));
this.dropItem = drop;
this.minCount = minCount;
this.maxCount = maxCount;

View file

@ -27,13 +27,13 @@ import net.minecraft.world.phys.Vec3;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;
import ru.bclib.client.render.BCLRenderLayer;
import ru.bclib.interfaces.IRenderTyped;
import ru.bclib.interfaces.RenderLayerProvider;
import java.util.List;
import java.util.Random;
@SuppressWarnings("deprecation")
public abstract class BasePlantBlock extends BaseBlockNotFull implements IRenderTyped, BonemealableBlock {
public abstract class BasePlantBlock extends BaseBlockNotFull implements RenderLayerProvider, BonemealableBlock {
private static final VoxelShape SHAPE = Block.box(4, 0, 4, 12, 14, 12);
public BasePlantBlock() {
@ -45,11 +45,20 @@ public abstract class BasePlantBlock extends BaseBlockNotFull implements IRender
}
public BasePlantBlock(boolean replaceable) {
super(FabricBlockSettings.of(replaceable ? Material.REPLACEABLE_PLANT : Material.PLANT).breakByTool(FabricToolTags.SHEARS).breakByHand(true).sound(SoundType.GRASS).noCollission());
super(FabricBlockSettings.of(replaceable ? Material.REPLACEABLE_PLANT : Material.PLANT)
.breakByTool(FabricToolTags.SHEARS)
.breakByHand(true)
.sound(SoundType.GRASS)
.noCollission());
}
public BasePlantBlock(boolean replaceable, int light) {
super(FabricBlockSettings.of(replaceable ? Material.REPLACEABLE_PLANT : Material.PLANT).breakByTool(FabricToolTags.SHEARS).breakByHand(true).luminance(light).sound(SoundType.GRASS).noCollission());
super(FabricBlockSettings.of(replaceable ? Material.REPLACEABLE_PLANT : Material.PLANT)
.breakByTool(FabricToolTags.SHEARS)
.breakByHand(true)
.luminance(light)
.sound(SoundType.GRASS)
.noCollission());
}
public BasePlantBlock(Properties settings) {
@ -88,7 +97,10 @@ public abstract class BasePlantBlock extends BaseBlockNotFull implements IRender
@Override
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
ItemStack tool = builder.getParameter(LootContextParams.TOOL);
if (tool != null && FabricToolTags.SHEARS.contains(tool.getItem()) || EnchantmentHelper.getItemEnchantmentLevel(Enchantments.SILK_TOUCH, tool) > 0) {
if (tool != null && FabricToolTags.SHEARS.contains(tool.getItem()) || EnchantmentHelper.getItemEnchantmentLevel(
Enchantments.SILK_TOUCH,
tool
) > 0) {
return Lists.newArrayList(new ItemStack(this));
}
else {
@ -113,7 +125,13 @@ public abstract class BasePlantBlock extends BaseBlockNotFull implements IRender
@Override
public void performBonemeal(ServerLevel world, Random random, BlockPos pos, BlockState state) {
ItemEntity item = new ItemEntity(world, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, new ItemStack(this));
ItemEntity item = new ItemEntity(
world,
pos.getX() + 0.5,
pos.getY() + 0.5,
pos.getZ() + 0.5,
new ItemStack(this)
);
world.addFreshEntity(item);
}
}

View file

@ -19,7 +19,12 @@ public abstract class BasePlantWithAgeBlock extends BasePlantBlock {
public static final IntegerProperty AGE = BlockProperties.AGE;
public BasePlantWithAgeBlock() {
this(FabricBlockSettings.of(Material.PLANT).breakByTool(FabricToolTags.SHEARS).breakByHand(true).sound(SoundType.GRASS).randomTicks().noCollission());
this(FabricBlockSettings.of(Material.PLANT)
.breakByTool(FabricToolTags.SHEARS)
.breakByHand(true)
.sound(SoundType.GRASS)
.randomTicks()
.noCollission());
}
public BasePlantWithAgeBlock(Properties settings) {

View file

@ -14,9 +14,9 @@ import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.storage.loot.LootContext;
import org.jetbrains.annotations.Nullable;
import ru.bclib.client.models.BasePatterns;
import ru.bclib.client.models.BlockModelProvider;
import ru.bclib.client.models.ModelsHelper;
import ru.bclib.client.models.PatternsHelper;
import ru.bclib.interfaces.BlockModelProvider;
import java.util.Collections;
import java.util.List;

View file

@ -12,9 +12,9 @@ import net.minecraft.world.level.block.RotatedPillarBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.storage.loot.LootContext;
import org.jetbrains.annotations.Nullable;
import ru.bclib.client.models.BlockModelProvider;
import ru.bclib.client.models.ModelsHelper;
import ru.bclib.client.models.PatternsHelper;
import ru.bclib.interfaces.BlockModelProvider;
import java.util.Collections;
import java.util.List;

View file

@ -2,6 +2,7 @@ package ru.bclib.blocks;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.fabricmc.fabric.api.item.v1.FabricItemSettings;
import net.fabricmc.fabric.api.object.builder.v1.block.FabricBlockSettings;
import net.minecraft.client.renderer.block.model.BlockModel;
import net.minecraft.core.BlockPos;
@ -13,6 +14,7 @@ import net.minecraft.server.level.ServerPlayer;
import net.minecraft.util.Mth;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.BlockGetter;
@ -39,25 +41,33 @@ import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;
import org.jetbrains.annotations.Nullable;
import ru.bclib.blockentities.BaseSignBlockEntity;
import ru.bclib.client.models.BlockModelProvider;
import ru.bclib.client.models.ModelsHelper;
import ru.bclib.interfaces.ISpetialItem;
import ru.bclib.interfaces.BlockModelProvider;
import ru.bclib.interfaces.CustomItemProvider;
import ru.bclib.util.BlocksHelper;
import java.util.Collections;
import java.util.List;
@SuppressWarnings("deprecation")
public class BaseSignBlock extends SignBlock implements BlockModelProvider, ISpetialItem {
public class BaseSignBlock extends SignBlock implements BlockModelProvider, CustomItemProvider {
public static final IntegerProperty ROTATION = BlockStateProperties.ROTATION_16;
public static final BooleanProperty FLOOR = BooleanProperty.create("floor");
private static final VoxelShape[] WALL_SHAPES = new VoxelShape[] {Block.box(0.0D, 4.5D, 14.0D, 16.0D, 12.5D, 16.0D), Block.box(0.0D, 4.5D, 0.0D, 2.0D, 12.5D, 16.0D), Block.box(0.0D, 4.5D, 0.0D, 16.0D, 12.5D, 2.0D), Block.box(14.0D, 4.5D, 0.0D, 16.0D, 12.5D, 16.0D)};
private static final VoxelShape[] WALL_SHAPES = new VoxelShape[] {
Block.box(0.0D, 4.5D, 14.0D, 16.0D, 12.5D, 16.0D),
Block.box(0.0D, 4.5D, 0.0D, 2.0D, 12.5D, 16.0D),
Block.box(0.0D, 4.5D, 0.0D, 16.0D, 12.5D, 2.0D),
Block.box(14.0D, 4.5D, 0.0D, 16.0D, 12.5D, 16.0D)
};
private final Block parent;
public BaseSignBlock(Block source) {
super(FabricBlockSettings.copyOf(source).strength(1.0F, 1.0F).noCollission().noOcclusion(), WoodType.OAK);
this.registerDefaultState(this.stateDefinition.any().setValue(ROTATION, 0).setValue(FLOOR, false).setValue(WATERLOGGED, false));
this.registerDefaultState(this.stateDefinition.any()
.setValue(ROTATION, 0)
.setValue(FLOOR, false)
.setValue(WATERLOGGED, false));
this.parent = source;
}
@ -98,7 +108,8 @@ public class BaseSignBlock extends SignBlock implements BlockModelProvider, ISpe
world.getLiquidTicks().scheduleTick(pos, Fluids.WATER, Fluids.WATER.getTickDelay(world));
}
if (!canSurvive(state, world, pos)) {
return state.getValue(WATERLOGGED) ? state.getFluidState().createLegacyBlock() : Blocks.AIR.defaultBlockState();
return state.getValue(WATERLOGGED) ? state.getFluidState()
.createLegacyBlock() : Blocks.AIR.defaultBlockState();
}
return super.updateShape(state, facing, neighborState, world, pos, neighborPos);
}
@ -118,7 +129,10 @@ public class BaseSignBlock extends SignBlock implements BlockModelProvider, ISpe
public BlockState getStateForPlacement(BlockPlaceContext ctx) {
if (ctx.getClickedFace() == Direction.UP) {
FluidState fluidState = ctx.getLevel().getFluidState(ctx.getClickedPos());
return this.defaultBlockState().setValue(FLOOR, true).setValue(ROTATION, Mth.floor((180.0 + ctx.getRotation() * 16.0 / 360.0) + 0.5 - 12) & 15).setValue(WATERLOGGED, fluidState.getType() == Fluids.WATER);
return this.defaultBlockState()
.setValue(FLOOR, true)
.setValue(ROTATION, Mth.floor((180.0 + ctx.getRotation() * 16.0 / 360.0) + 0.5 - 12) & 15)
.setValue(WATERLOGGED, fluidState.getType() == Fluids.WATER);
}
else if (ctx.getClickedFace() != Direction.DOWN) {
BlockState blockState = this.defaultBlockState();
@ -133,7 +147,8 @@ public class BaseSignBlock extends SignBlock implements BlockModelProvider, ISpe
int rot = Mth.floor((180.0 + dir.toYRot() * 16.0 / 360.0) + 0.5 + 4) & 15;
blockState = blockState.setValue(ROTATION, rot);
if (blockState.canSurvive(worldView, blockPos)) {
return blockState.setValue(FLOOR, false).setValue(WATERLOGGED, fluidState.getType() == Fluids.WATER);
return blockState.setValue(FLOOR, false)
.setValue(WATERLOGGED, fluidState.getType() == Fluids.WATER);
}
}
}
@ -177,12 +192,7 @@ public class BaseSignBlock extends SignBlock implements BlockModelProvider, ISpe
}
@Override
public int getStackSize() {
return 16;
}
@Override
public boolean canPlaceOnWater() {
return false;
public BlockItem getCustomItem(ResourceLocation blockID, FabricItemSettings settings) {
return new BlockItem(this, settings.maxCount(16));
}
}

View file

@ -16,9 +16,9 @@ import net.minecraft.world.level.block.state.properties.SlabType;
import net.minecraft.world.level.storage.loot.LootContext;
import org.jetbrains.annotations.Nullable;
import ru.bclib.client.models.BasePatterns;
import ru.bclib.client.models.BlockModelProvider;
import ru.bclib.client.models.ModelsHelper;
import ru.bclib.client.models.PatternsHelper;
import ru.bclib.interfaces.BlockModelProvider;
import java.util.Collections;
import java.util.List;
@ -63,7 +63,10 @@ public class BaseSlabBlock extends SlabBlock implements BlockModelProvider {
@Environment(EnvType.CLIENT)
public UnbakedModel getModelVariant(ResourceLocation stateId, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
SlabType type = blockState.getValue(TYPE);
ResourceLocation modelId = new ResourceLocation(stateId.getNamespace(), "block/" + stateId.getPath() + "_" + type);
ResourceLocation modelId = new ResourceLocation(
stateId.getNamespace(),
"block/" + stateId.getPath() + "_" + type
);
registerBlockModel(stateId, modelId, blockState, modelCache);
if (type == SlabType.TOP) {
return ModelsHelper.createMultiVariant(modelId, BlockModelRotation.X180_Y0.getRotation(), true);

View file

@ -17,9 +17,9 @@ import net.minecraft.world.level.block.state.properties.StairsShape;
import net.minecraft.world.level.storage.loot.LootContext;
import org.jetbrains.annotations.Nullable;
import ru.bclib.client.models.BasePatterns;
import ru.bclib.client.models.BlockModelProvider;
import ru.bclib.client.models.ModelsHelper;
import ru.bclib.client.models.PatternsHelper;
import ru.bclib.interfaces.BlockModelProvider;
import java.util.Collections;
import java.util.List;

View file

@ -30,7 +30,11 @@ public class BaseStripableLogBlock extends BaseRotatedPillarBlock {
if (FabricToolTags.AXES.contains(player.getMainHandItem().getItem())) {
world.playSound(player, pos, SoundEvents.AXE_STRIP, SoundSource.BLOCKS, 1.0F, 1.0F);
if (!world.isClientSide) {
world.setBlock(pos, striped.defaultBlockState().setValue(RotatedPillarBlock.AXIS, state.getValue(RotatedPillarBlock.AXIS)), 11);
world.setBlock(pos,
striped.defaultBlockState()
.setValue(RotatedPillarBlock.AXIS, state.getValue(RotatedPillarBlock.AXIS)),
11
);
if (!player.isCreative()) {
player.getMainHandItem().hurt(1, world.random, (ServerPlayer) player);
}

View file

@ -51,7 +51,10 @@ public class BaseTerrainBlock extends BaseBlock {
private Block pathBlock;
public BaseTerrainBlock(Block baseBlock, MaterialColor color) {
super(FabricBlockSettings.copyOf(baseBlock).materialColor(color).sound(BlockSounds.TERRAIN_SOUND).randomTicks());
super(FabricBlockSettings.copyOf(baseBlock)
.materialColor(color)
.sound(BlockSounds.TERRAIN_SOUND)
.randomTicks());
this.baseBlock = baseBlock;
}
@ -104,7 +107,15 @@ public class BaseTerrainBlock extends BaseBlock {
return false;
}
else {
int i = LayerLightEngine.getLightBlockInto(worldView, state, pos, blockState, blockPos, Direction.UP, blockState.getLightBlock(worldView, blockPos));
int i = LayerLightEngine.getLightBlockInto(
worldView,
state,
pos,
blockState,
blockPos,
Direction.UP,
blockState.getLightBlock(worldView, blockPos)
);
return i < 5;
}
}

View file

@ -15,11 +15,11 @@ import net.minecraft.world.level.block.state.properties.Half;
import net.minecraft.world.level.storage.loot.LootContext;
import org.jetbrains.annotations.Nullable;
import ru.bclib.client.models.BasePatterns;
import ru.bclib.client.models.BlockModelProvider;
import ru.bclib.client.models.ModelsHelper;
import ru.bclib.client.models.PatternsHelper;
import ru.bclib.client.render.BCLRenderLayer;
import ru.bclib.interfaces.IRenderTyped;
import ru.bclib.interfaces.BlockModelProvider;
import ru.bclib.interfaces.RenderLayerProvider;
import java.util.Collections;
import java.util.HashMap;
@ -27,7 +27,7 @@ import java.util.List;
import java.util.Map;
import java.util.Optional;
public class BaseTrapdoorBlock extends TrapDoorBlock implements IRenderTyped, BlockModelProvider {
public class BaseTrapdoorBlock extends TrapDoorBlock implements RenderLayerProvider, BlockModelProvider {
public BaseTrapdoorBlock(Block source) {
super(FabricBlockSettings.copyOf(source).strength(3.0F, 3.0F).noOcclusion());
}
@ -53,7 +53,9 @@ public class BaseTrapdoorBlock extends TrapDoorBlock implements IRenderTyped, Bl
@Environment(EnvType.CLIENT)
public @Nullable BlockModel getBlockModel(ResourceLocation resourceLocation, BlockState blockState) {
String name = resourceLocation.getPath();
Optional<String> pattern = PatternsHelper.createJson(BasePatterns.BLOCK_TRAPDOOR, new HashMap<String, String>() {
Optional<String> pattern = PatternsHelper.createJson(
BasePatterns.BLOCK_TRAPDOOR,
new HashMap<String, String>() {
private static final long serialVersionUID = 1L;
{
@ -61,7 +63,8 @@ public class BaseTrapdoorBlock extends TrapDoorBlock implements IRenderTyped, Bl
put("%texture%", name);
put("%side%", name.replace("trapdoor", "door_side"));
}
});
}
);
return ModelsHelper.fromPattern(pattern);
}

View file

@ -17,11 +17,20 @@ import net.minecraft.world.level.material.Material;
public abstract class BaseUnderwaterWallPlantBlock extends BaseWallPlantBlock implements LiquidBlockContainer {
public BaseUnderwaterWallPlantBlock() {
super(FabricBlockSettings.of(Material.WATER_PLANT).breakByTool(FabricToolTags.SHEARS).breakByHand(true).sound(SoundType.WET_GRASS).noCollission());
super(FabricBlockSettings.of(Material.WATER_PLANT)
.breakByTool(FabricToolTags.SHEARS)
.breakByHand(true)
.sound(SoundType.WET_GRASS)
.noCollission());
}
public BaseUnderwaterWallPlantBlock(int light) {
super(FabricBlockSettings.of(Material.WATER_PLANT).breakByTool(FabricToolTags.SHEARS).breakByHand(true).luminance(light).sound(SoundType.WET_GRASS).noCollission());
super(FabricBlockSettings.of(Material.WATER_PLANT)
.breakByTool(FabricToolTags.SHEARS)
.breakByHand(true)
.luminance(light)
.sound(SoundType.WET_GRASS)
.noCollission());
}
public BaseUnderwaterWallPlantBlock(Properties settings) {

View file

@ -30,14 +30,14 @@ import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;
import ru.bclib.blocks.BlockProperties.TripleShape;
import ru.bclib.client.render.BCLRenderLayer;
import ru.bclib.interfaces.IRenderTyped;
import ru.bclib.interfaces.RenderLayerProvider;
import ru.bclib.util.BlocksHelper;
import java.util.List;
import java.util.Random;
@SuppressWarnings("deprecation")
public class BaseVineBlock extends BaseBlockNotFull implements IRenderTyped, BonemealableBlock {
public class BaseVineBlock extends BaseBlockNotFull implements RenderLayerProvider, BonemealableBlock {
public static final EnumProperty<TripleShape> SHAPE = BlockProperties.TRIPLE_SHAPE;
private static final VoxelShape VOXEL_SHAPE = Block.box(2, 0, 2, 14, 16, 14);
@ -50,7 +50,12 @@ public class BaseVineBlock extends BaseBlockNotFull implements IRenderTyped, Bon
}
public BaseVineBlock(int light, boolean bottomOnly) {
super(FabricBlockSettings.of(Material.PLANT).breakByTool(FabricToolTags.SHEARS).breakByHand(true).sound(SoundType.GRASS).lightLevel((state) -> bottomOnly ? state.getValue(SHAPE) == TripleShape.BOTTOM ? light : 0 : light).noCollission());
super(FabricBlockSettings.of(Material.PLANT)
.breakByTool(FabricToolTags.SHEARS)
.breakByHand(true)
.sound(SoundType.GRASS)
.lightLevel((state) -> bottomOnly ? state.getValue(SHAPE) == TripleShape.BOTTOM ? light : 0 : light)
.noCollission());
this.registerDefaultState(this.stateDefinition.any().setValue(SHAPE, TripleShape.BOTTOM));
}
@ -99,7 +104,10 @@ public class BaseVineBlock extends BaseBlockNotFull implements IRenderTyped, Bon
@Override
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
ItemStack tool = builder.getParameter(LootContextParams.TOOL);
if (tool != null && FabricToolTags.SHEARS.contains(tool.getItem()) || EnchantmentHelper.getItemEnchantmentLevel(Enchantments.SILK_TOUCH, tool) > 0) {
if (tool != null && FabricToolTags.SHEARS.contains(tool.getItem()) || EnchantmentHelper.getItemEnchantmentLevel(
Enchantments.SILK_TOUCH,
tool
) > 0) {
return Lists.newArrayList(new ItemStack(this));
}
else {

View file

@ -16,9 +16,9 @@ import net.minecraft.world.level.block.state.properties.WallSide;
import net.minecraft.world.level.storage.loot.LootContext;
import org.jetbrains.annotations.Nullable;
import ru.bclib.client.models.BasePatterns;
import ru.bclib.client.models.BlockModelProvider;
import ru.bclib.client.models.ModelsHelper;
import ru.bclib.client.models.PatternsHelper;
import ru.bclib.interfaces.BlockModelProvider;
import java.util.Collections;
import java.util.List;
@ -71,20 +71,50 @@ public class BaseWallBlock extends WallBlock implements BlockModelProvider {
public UnbakedModel getModelVariant(ResourceLocation stateId, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
ResourceLocation postId = new ResourceLocation(stateId.getNamespace(), "block/" + stateId.getPath() + "_post");
ResourceLocation sideId = new ResourceLocation(stateId.getNamespace(), "block/" + stateId.getPath() + "_side");
ResourceLocation sideTallId = new ResourceLocation(stateId.getNamespace(), "block/" + stateId.getPath() + "_side_tall");
ResourceLocation sideTallId = new ResourceLocation(
stateId.getNamespace(),
"block/" + stateId.getPath() + "_side_tall"
);
registerBlockModel(postId, postId, blockState, modelCache);
registerBlockModel(sideId, sideId, blockState, modelCache);
registerBlockModel(sideTallId, sideTallId, blockState, modelCache);
ModelsHelper.MultiPartBuilder builder = ModelsHelper.MultiPartBuilder.create(stateDefinition);
builder.part(sideId).setCondition(state -> state.getValue(NORTH_WALL) == WallSide.LOW).setUVLock(true).add();
builder.part(sideId).setCondition(state -> state.getValue(EAST_WALL) == WallSide.LOW).setTransformation(BlockModelRotation.X0_Y90.getRotation()).setUVLock(true).add();
builder.part(sideId).setCondition(state -> state.getValue(SOUTH_WALL) == WallSide.LOW).setTransformation(BlockModelRotation.X0_Y180.getRotation()).setUVLock(true).add();
builder.part(sideId).setCondition(state -> state.getValue(WEST_WALL) == WallSide.LOW).setTransformation(BlockModelRotation.X0_Y270.getRotation()).setUVLock(true).add();
builder.part(sideTallId).setCondition(state -> state.getValue(NORTH_WALL) == WallSide.TALL).setUVLock(true).add();
builder.part(sideTallId).setCondition(state -> state.getValue(EAST_WALL) == WallSide.TALL).setTransformation(BlockModelRotation.X0_Y90.getRotation()).setUVLock(true).add();
builder.part(sideTallId).setCondition(state -> state.getValue(SOUTH_WALL) == WallSide.TALL).setTransformation(BlockModelRotation.X0_Y180.getRotation()).setUVLock(true).add();
builder.part(sideTallId).setCondition(state -> state.getValue(WEST_WALL) == WallSide.TALL).setTransformation(BlockModelRotation.X0_Y270.getRotation()).setUVLock(true).add();
builder.part(sideId)
.setCondition(state -> state.getValue(EAST_WALL) == WallSide.LOW)
.setTransformation(BlockModelRotation.X0_Y90.getRotation())
.setUVLock(true)
.add();
builder.part(sideId)
.setCondition(state -> state.getValue(SOUTH_WALL) == WallSide.LOW)
.setTransformation(BlockModelRotation.X0_Y180.getRotation())
.setUVLock(true)
.add();
builder.part(sideId)
.setCondition(state -> state.getValue(WEST_WALL) == WallSide.LOW)
.setTransformation(BlockModelRotation.X0_Y270.getRotation())
.setUVLock(true)
.add();
builder.part(sideTallId)
.setCondition(state -> state.getValue(NORTH_WALL) == WallSide.TALL)
.setUVLock(true)
.add();
builder.part(sideTallId)
.setCondition(state -> state.getValue(EAST_WALL) == WallSide.TALL)
.setTransformation(BlockModelRotation.X0_Y90.getRotation())
.setUVLock(true)
.add();
builder.part(sideTallId)
.setCondition(state -> state.getValue(SOUTH_WALL) == WallSide.TALL)
.setTransformation(BlockModelRotation.X0_Y180.getRotation())
.setUVLock(true)
.add();
builder.part(sideTallId)
.setCondition(state -> state.getValue(WEST_WALL) == WallSide.TALL)
.setTransformation(BlockModelRotation.X0_Y270.getRotation())
.setUVLock(true)
.add();
builder.part(postId).setCondition(state -> state.getValue(UP)).add();
return builder.build();

View file

@ -28,15 +28,33 @@ import ru.bclib.util.BlocksHelper;
import java.util.EnumMap;
public abstract class BaseWallPlantBlock extends BasePlantBlock {
private static final EnumMap<Direction, VoxelShape> SHAPES = Maps.newEnumMap(ImmutableMap.of(Direction.NORTH, Block.box(1, 1, 8, 15, 15, 16), Direction.SOUTH, Block.box(1, 1, 0, 15, 15, 8), Direction.WEST, Block.box(8, 1, 1, 16, 15, 15), Direction.EAST, Block.box(0, 1, 1, 8, 15, 15)));
private static final EnumMap<Direction, VoxelShape> SHAPES = Maps.newEnumMap(ImmutableMap.of(
Direction.NORTH,
Block.box(1, 1, 8, 15, 15, 16),
Direction.SOUTH,
Block.box(1, 1, 0, 15, 15, 8),
Direction.WEST,
Block.box(8, 1, 1, 16, 15, 15),
Direction.EAST,
Block.box(0, 1, 1, 8, 15, 15)
));
public static final DirectionProperty FACING = HorizontalDirectionalBlock.FACING;
public BaseWallPlantBlock() {
this(FabricBlockSettings.of(Material.PLANT).breakByTool(FabricToolTags.SHEARS).breakByHand(true).sound(SoundType.GRASS).noCollission());
this(FabricBlockSettings.of(Material.PLANT)
.breakByTool(FabricToolTags.SHEARS)
.breakByHand(true)
.sound(SoundType.GRASS)
.noCollission());
}
public BaseWallPlantBlock(int light) {
this(FabricBlockSettings.of(Material.PLANT).breakByTool(FabricToolTags.SHEARS).breakByHand(true).luminance(light).sound(SoundType.GRASS).noCollission());
this(FabricBlockSettings.of(Material.PLANT)
.breakByTool(FabricToolTags.SHEARS)
.breakByHand(true)
.luminance(light)
.sound(SoundType.GRASS)
.noCollission());
}
public BaseWallPlantBlock(Properties settings) {

View file

@ -14,9 +14,9 @@ import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.storage.loot.LootContext;
import org.jetbrains.annotations.Nullable;
import ru.bclib.client.models.BasePatterns;
import ru.bclib.client.models.BlockModelProvider;
import ru.bclib.client.models.ModelsHelper;
import ru.bclib.client.models.PatternsHelper;
import ru.bclib.interfaces.BlockModelProvider;
import java.util.Collections;
import java.util.List;
@ -27,7 +27,10 @@ public class BaseWeightedPlateBlock extends WeightedPressurePlateBlock implement
private final Block parent;
public BaseWeightedPlateBlock(Block source) {
super(15, FabricBlockSettings.copyOf(source).noCollission().noOcclusion().requiresCorrectToolForDrops().strength(0.5F));
super(
15,
FabricBlockSettings.copyOf(source).noCollission().noOcclusion().requiresCorrectToolForDrops().strength(0.5F)
);
this.parent = source;
}

View file

@ -25,11 +25,11 @@ import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;
import org.jetbrains.annotations.Nullable;
import ru.bclib.client.models.BasePatterns;
import ru.bclib.client.models.BlockModelProvider;
import ru.bclib.client.models.ModelsHelper;
import ru.bclib.client.models.PatternsHelper;
import ru.bclib.client.render.BCLRenderLayer;
import ru.bclib.interfaces.IRenderTyped;
import ru.bclib.interfaces.BlockModelProvider;
import ru.bclib.interfaces.RenderLayerProvider;
import java.util.Collections;
import java.util.List;
@ -37,15 +37,32 @@ import java.util.Optional;
import java.util.Random;
@SuppressWarnings("deprecation")
public abstract class FeatureSaplingBlock extends SaplingBlock implements IRenderTyped, BlockModelProvider {
public abstract class FeatureSaplingBlock extends SaplingBlock implements RenderLayerProvider, BlockModelProvider {
private static final VoxelShape SHAPE = Block.box(4, 0, 4, 12, 14, 12);
public FeatureSaplingBlock() {
super(null, FabricBlockSettings.of(Material.PLANT).breakByHand(true).collidable(false).instabreak().sound(SoundType.GRASS).randomTicks());
super(
null,
FabricBlockSettings.of(Material.PLANT)
.breakByHand(true)
.collidable(false)
.instabreak()
.sound(SoundType.GRASS)
.randomTicks()
);
}
public FeatureSaplingBlock(int light) {
super(null, FabricBlockSettings.of(Material.PLANT).breakByHand(true).collidable(false).luminance(light).instabreak().sound(SoundType.GRASS).randomTicks());
super(
null,
FabricBlockSettings.of(Material.PLANT)
.breakByHand(true)
.collidable(false)
.luminance(light)
.instabreak()
.sound(SoundType.GRASS)
.randomTicks()
);
}
protected abstract Feature<?> getFeature();
@ -73,7 +90,13 @@ public abstract class FeatureSaplingBlock extends SaplingBlock implements IRende
@Override
public void advanceTree(ServerLevel world, BlockPos pos, BlockState blockState, Random random) {
FeaturePlaceContext context = new FeaturePlaceContext(world, world.getChunkSource().getGenerator(), random, pos, null);
FeaturePlaceContext context = new FeaturePlaceContext(
world,
world.getChunkSource().getGenerator(),
random,
pos,
null
);
getFeature().place(context);
}

View file

@ -5,15 +5,30 @@ import net.minecraft.world.level.block.SoundType;
import net.minecraft.world.level.material.Material;
import net.minecraft.world.level.material.MaterialColor;
import ru.bclib.client.render.BCLRenderLayer;
import ru.bclib.interfaces.IRenderTyped;
import ru.bclib.interfaces.RenderLayerProvider;
public class SimpleLeavesBlock extends BaseBlockNotFull implements IRenderTyped {
public class SimpleLeavesBlock extends BaseBlockNotFull implements RenderLayerProvider {
public SimpleLeavesBlock(MaterialColor color) {
super(FabricBlockSettings.of(Material.LEAVES).strength(0.2F).mapColor(color).sound(SoundType.GRASS).noOcclusion().isValidSpawn((state, world, pos, type) -> false).isSuffocating((state, world, pos) -> false).isViewBlocking((state, world, pos) -> false));
super(FabricBlockSettings.of(Material.LEAVES)
.strength(0.2F)
.mapColor(color)
.sound(SoundType.GRASS)
.noOcclusion()
.isValidSpawn((state, world, pos, type) -> false)
.isSuffocating((state, world, pos) -> false)
.isViewBlocking((state, world, pos) -> false));
}
public SimpleLeavesBlock(MaterialColor color, int light) {
super(FabricBlockSettings.of(Material.LEAVES).luminance(light).mapColor(color).strength(0.2F).sound(SoundType.GRASS).noOcclusion().isValidSpawn((state, world, pos, type) -> false).isSuffocating((state, world, pos) -> false).isViewBlocking((state, world, pos) -> false));
super(FabricBlockSettings.of(Material.LEAVES)
.luminance(light)
.mapColor(color)
.strength(0.2F)
.sound(SoundType.GRASS)
.noOcclusion()
.isValidSpawn((state, world, pos, type) -> false)
.isSuffocating((state, world, pos) -> false)
.isViewBlocking((state, world, pos) -> false));
}
@Override

View file

@ -37,13 +37,13 @@ import ru.bclib.client.models.BasePatterns;
import ru.bclib.client.models.ModelsHelper;
import ru.bclib.client.models.PatternsHelper;
import ru.bclib.client.render.BCLRenderLayer;
import ru.bclib.interfaces.IRenderTyped;
import ru.bclib.interfaces.RenderLayerProvider;
import java.util.Map;
import java.util.Optional;
@SuppressWarnings("deprecation")
public class StalactiteBlock extends BaseBlockNotFull implements SimpleWaterloggedBlock, LiquidBlockContainer, IRenderTyped {
public class StalactiteBlock extends BaseBlockNotFull implements SimpleWaterloggedBlock, LiquidBlockContainer, RenderLayerProvider {
public static final BooleanProperty WATERLOGGED = BlockStateProperties.WATERLOGGED;
public static final BooleanProperty IS_FLOOR = BlockProperties.IS_FLOOR;
public static final IntegerProperty SIZE = BlockProperties.SIZE;
@ -51,7 +51,10 @@ public class StalactiteBlock extends BaseBlockNotFull implements SimpleWaterlogg
public StalactiteBlock(Block source) {
super(FabricBlockSettings.copy(source).noOcclusion());
this.registerDefaultState(getStateDefinition().any().setValue(SIZE, 0).setValue(IS_FLOOR, true).setValue(WATERLOGGED, false));
this.registerDefaultState(getStateDefinition().any()
.setValue(SIZE, 0)
.setValue(IS_FLOOR, true)
.setValue(WATERLOGGED, false));
}
@Override
@ -212,7 +215,10 @@ public class StalactiteBlock extends BaseBlockNotFull implements SimpleWaterlogg
@Environment(EnvType.CLIENT)
public UnbakedModel getModelVariant(ResourceLocation stateId, BlockState blockState, Map<ResourceLocation, UnbakedModel> modelCache) {
BlockModelRotation rotation = blockState.getValue(IS_FLOOR) ? BlockModelRotation.X0_Y0 : BlockModelRotation.X180_Y0;
ResourceLocation modelId = new ResourceLocation(stateId.getNamespace(), stateId.getPath() + "_" + blockState.getValue(SIZE));
ResourceLocation modelId = new ResourceLocation(
stateId.getNamespace(),
stateId.getPath() + "_" + blockState.getValue(SIZE)
);
registerBlockModel(modelId, modelId, blockState, modelCache);
return ModelsHelper.createMultiVariant(modelId, rotation.getRotation(), false);
}

View file

@ -30,7 +30,11 @@ public class StripableBarkBlock extends BaseBarkBlock {
if (FabricToolTags.AXES.contains(player.getMainHandItem().getItem())) {
world.playSound(player, pos, SoundEvents.AXE_STRIP, SoundSource.BLOCKS, 1.0F, 1.0F);
if (!world.isClientSide) {
world.setBlock(pos, striped.defaultBlockState().setValue(RotatedPillarBlock.AXIS, state.getValue(RotatedPillarBlock.AXIS)), 11);
world.setBlock(pos,
striped.defaultBlockState()
.setValue(RotatedPillarBlock.AXIS, state.getValue(RotatedPillarBlock.AXIS)),
11
);
if (!player.isCreative()) {
player.getMainHandItem().hurt(1, world.random, (ServerPlayer) player);
}

View file

@ -153,7 +153,17 @@ public class TripleTerrainBlock extends BaseTerrainBlock {
return new MultiVariant(variants);
}
else if (blockState.getValue(SHAPE) == TripleShape.TOP) {
return new MultiVariant(Lists.newArrayList(new Variant(modelId, BlockModelRotation.X180_Y0.getRotation(), false, 1), new Variant(modelId, BlockModelRotation.X180_Y90.getRotation(), false, 1), new Variant(modelId, BlockModelRotation.X180_Y180.getRotation(), false, 1), new Variant(modelId, BlockModelRotation.X180_Y270.getRotation(), false, 1)));
return new MultiVariant(Lists.newArrayList(
new Variant(
modelId,
BlockModelRotation.X180_Y0.getRotation(),
false,
1
),
new Variant(modelId, BlockModelRotation.X180_Y90.getRotation(), false, 1),
new Variant(modelId, BlockModelRotation.X180_Y180.getRotation(), false, 1),
new Variant(modelId, BlockModelRotation.X180_Y270.getRotation(), false, 1)
));
}
return ModelsHelper.createRandomTopModel(modelId);
}

View file

@ -31,21 +31,30 @@ import net.minecraft.world.phys.Vec3;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;
import ru.bclib.client.render.BCLRenderLayer;
import ru.bclib.interfaces.IRenderTyped;
import ru.bclib.interfaces.RenderLayerProvider;
import java.util.List;
import java.util.Random;
@SuppressWarnings("deprecation")
public abstract class UnderwaterPlantBlock extends BaseBlockNotFull implements IRenderTyped, BonemealableBlock, LiquidBlockContainer {
public abstract class UnderwaterPlantBlock extends BaseBlockNotFull implements RenderLayerProvider, BonemealableBlock, LiquidBlockContainer {
private static final VoxelShape SHAPE = Block.box(4, 0, 4, 12, 14, 12);
public UnderwaterPlantBlock() {
super(FabricBlockSettings.of(Material.WATER_PLANT).breakByTool(FabricToolTags.SHEARS).breakByHand(true).sound(SoundType.WET_GRASS).noCollission());
super(FabricBlockSettings.of(Material.WATER_PLANT)
.breakByTool(FabricToolTags.SHEARS)
.breakByHand(true)
.sound(SoundType.WET_GRASS)
.noCollission());
}
public UnderwaterPlantBlock(int light) {
super(FabricBlockSettings.of(Material.WATER_PLANT).breakByTool(FabricToolTags.SHEARS).breakByHand(true).luminance(light).sound(SoundType.WET_GRASS).noCollission());
super(FabricBlockSettings.of(Material.WATER_PLANT)
.breakByTool(FabricToolTags.SHEARS)
.breakByHand(true)
.luminance(light)
.sound(SoundType.WET_GRASS)
.noCollission());
}
public UnderwaterPlantBlock(Properties settings) {
@ -86,7 +95,10 @@ public abstract class UnderwaterPlantBlock extends BaseBlockNotFull implements I
@Override
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
ItemStack tool = builder.getParameter(LootContextParams.TOOL);
if (tool != null && FabricToolTags.SHEARS.contains(tool.getItem()) || EnchantmentHelper.getItemEnchantmentLevel(Enchantments.SILK_TOUCH, tool) > 0) {
if (tool != null && FabricToolTags.SHEARS.contains(tool.getItem()) || EnchantmentHelper.getItemEnchantmentLevel(
Enchantments.SILK_TOUCH,
tool
) > 0) {
return Lists.newArrayList(new ItemStack(this));
}
else {
@ -111,7 +123,13 @@ public abstract class UnderwaterPlantBlock extends BaseBlockNotFull implements I
@Override
public void performBonemeal(ServerLevel world, Random random, BlockPos pos, BlockState state) {
ItemEntity item = new ItemEntity(world, pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, new ItemStack(this));
ItemEntity item = new ItemEntity(
world,
pos.getX() + 0.5,
pos.getY() + 0.5,
pos.getZ() + 0.5,
new ItemStack(this)
);
world.addFreshEntity(item);
}

View file

@ -18,7 +18,12 @@ public abstract class UnderwaterPlantWithAgeBlock extends UnderwaterPlantBlock {
public static final IntegerProperty AGE = BlockProperties.AGE;
public UnderwaterPlantWithAgeBlock() {
super(FabricBlockSettings.of(Material.WATER_PLANT).breakByTool(FabricToolTags.SHEARS).breakByHand(true).sound(SoundType.WET_GRASS).randomTicks().noCollission());
super(FabricBlockSettings.of(Material.WATER_PLANT)
.breakByTool(FabricToolTags.SHEARS)
.breakByHand(true)
.sound(SoundType.WET_GRASS)
.randomTicks()
.noCollission());
}
@Override

View file

@ -24,16 +24,20 @@ import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;
import ru.bclib.client.render.BCLRenderLayer;
import ru.bclib.interfaces.IRenderTyped;
import ru.bclib.interfaces.RenderLayerProvider;
import java.util.List;
@SuppressWarnings("deprecation")
public abstract class UpDownPlantBlock extends BaseBlockNotFull implements IRenderTyped {
public abstract class UpDownPlantBlock extends BaseBlockNotFull implements RenderLayerProvider {
private static final VoxelShape SHAPE = Block.box(4, 0, 4, 12, 16, 12);
public UpDownPlantBlock() {
super(FabricBlockSettings.of(Material.PLANT).breakByTool(FabricToolTags.SHEARS).breakByHand(true).sound(SoundType.GRASS).noCollission());
super(FabricBlockSettings.of(Material.PLANT)
.breakByTool(FabricToolTags.SHEARS)
.breakByHand(true)
.sound(SoundType.GRASS)
.noCollission());
}
protected abstract boolean isTerrain(BlockState state);
@ -67,7 +71,10 @@ public abstract class UpDownPlantBlock extends BaseBlockNotFull implements IRend
@Override
public List<ItemStack> getDrops(BlockState state, LootContext.Builder builder) {
ItemStack tool = builder.getParameter(LootContextParams.TOOL);
if (tool != null && FabricToolTags.SHEARS.contains(tool.getItem()) || EnchantmentHelper.getItemEnchantmentLevel(Enchantments.SILK_TOUCH, tool) > 0) {
if (tool != null && FabricToolTags.SHEARS.contains(tool.getItem()) || EnchantmentHelper.getItemEnchantmentLevel(
Enchantments.SILK_TOUCH,
tool
) > 0) {
return Lists.newArrayList(new ItemStack(this));
}
else {

View file

@ -16,7 +16,14 @@ import java.util.List;
public abstract class WallMushroomBlock extends BaseWallPlantBlock {
public WallMushroomBlock(int light) {
super(FabricBlockSettings.of(Material.PLANT).breakByTool(FabricToolTags.AXES).breakByHand(true).luminance(light).hardness(0.2F).sound(SoundType.GRASS).sound(SoundType.WOOD).noCollission());
super(FabricBlockSettings.of(Material.PLANT)
.breakByTool(FabricToolTags.AXES)
.breakByHand(true)
.luminance(light)
.hardness(0.2F)
.sound(SoundType.GRASS)
.sound(SoundType.WOOD)
.noCollission());
}
@Override

View file

@ -6,8 +6,8 @@ import net.minecraft.client.renderer.RenderType;
import net.minecraft.core.Registry;
import ru.bclib.api.ModIntegrationAPI;
import ru.bclib.client.render.BCLRenderLayer;
import ru.bclib.interfaces.IPostInit;
import ru.bclib.interfaces.IRenderTyped;
import ru.bclib.interfaces.PostInitable;
import ru.bclib.interfaces.RenderLayerProvider;
import ru.bclib.registry.BaseBlockEntityRenders;
public class BCLibClient implements ClientModInitializer {
@ -17,8 +17,8 @@ public class BCLibClient implements ClientModInitializer {
BaseBlockEntityRenders.register();
registerRenderLayers();
Registry.BLOCK.forEach(block -> {
if (block instanceof IPostInit) {
((IPostInit) block).postInit();
if (block instanceof PostInitable) {
((PostInitable) block).postInit();
}
});
}
@ -27,8 +27,8 @@ public class BCLibClient implements ClientModInitializer {
RenderType cutout = RenderType.cutout();
RenderType translucent = RenderType.translucent();
Registry.BLOCK.forEach(block -> {
if (block instanceof IRenderTyped) {
BCLRenderLayer layer = ((IRenderTyped) block).getRenderLayer();
if (block instanceof RenderLayerProvider) {
BCLRenderLayer layer = ((RenderLayerProvider) block).getRenderLayer();
if (layer == BCLRenderLayer.CUTOUT) BlockRenderLayerMap.INSTANCE.putBlock(block, cutout);
else if (layer == BCLRenderLayer.TRANSLUCENT) BlockRenderLayerMap.INSTANCE.putBlock(block, translucent);
}

View file

@ -53,28 +53,48 @@ public class BlockSignEditScreen extends Screen {
protected void init() {
//set up a default model
model = new SignRenderer.SignModel(this.minecraft.getEntityModels().bakeLayer(ModelLayers.createSignModelName(WoodType.OAK)));
model = new SignRenderer.SignModel(this.minecraft.getEntityModels()
.bakeLayer(ModelLayers.createSignModelName(WoodType.OAK)));
minecraft.keyboardHandler.setSendRepeatsToGui(true);
this.addRenderableWidget(new Button(this.width / 2 - 100, this.height / 4 + 120, 200, 20, CommonComponents.GUI_DONE, (buttonWidget) -> {
this.addRenderableWidget(new Button(
this.width / 2 - 100,
this.height / 4 + 120,
200,
20,
CommonComponents.GUI_DONE,
(buttonWidget) -> {
this.finishEditing();
}));
}
));
this.sign.setEditable(false);
this.selectionManager = new TextFieldHelper(() -> {
this.selectionManager = new TextFieldHelper(
() -> {
return this.text[this.currentRow];
}, (string) -> {
},
(string) -> {
this.text[this.currentRow] = string;
this.sign.setMessage(this.currentRow, new TextComponent(string));
}, TextFieldHelper.createClipboardGetter(this.minecraft), TextFieldHelper.createClipboardSetter(this.minecraft), (string) -> {
},
TextFieldHelper.createClipboardGetter(this.minecraft),
TextFieldHelper.createClipboardSetter(this.minecraft),
(string) -> {
return this.minecraft.font.width(string) <= 90;
});
}
);
}
public void removed() {
minecraft.keyboardHandler.setSendRepeatsToGui(false);
ClientPacketListener clientPlayNetworkHandler = this.minecraft.getConnection();
if (clientPlayNetworkHandler != null) {
clientPlayNetworkHandler.send(new ServerboundSignUpdatePacket(this.sign.getBlockPos(), this.text[0], this.text[1], this.text[2], this.text[3]));
clientPlayNetworkHandler.send(new ServerboundSignUpdatePacket(
this.sign.getBlockPos(),
this.text[0],
this.text[1],
this.text[2],
this.text[3]
));
}
this.sign.setEditable(true);
@ -167,12 +187,36 @@ public class BlockSignEditScreen extends Screen {
}
float n = (float) (-this.minecraft.font.width(string2) / 2);
this.minecraft.font.drawInBatch(string2, n, (float) (m * 10 - this.text.length * 5), i, false, matrix4f, immediate, false, 0, 15728880, false);
this.minecraft.font.drawInBatch(
string2,
n,
(float) (m * 10 - this.text.length * 5),
i,
false,
matrix4f,
immediate,
false,
0,
15728880,
false
);
if (m == this.currentRow && j >= 0 && bl2) {
s = this.minecraft.font.width(string2.substring(0, Math.max(Math.min(j, string2.length()), 0)));
t = s - this.minecraft.font.width(string2) / 2;
if (j >= string2.length()) {
this.minecraft.font.drawInBatch("_", (float) t, (float) l, i, false, matrix4f, immediate, false, 0, 15728880, false);
this.minecraft.font.drawInBatch(
"_",
(float) t,
(float) l,
i,
false,
matrix4f,
immediate,
false,
0,
15728880,
false
);
}
}
}

View file

@ -23,31 +23,71 @@ public class BaseChestBlockModel {
MeshDefinition modelData = new MeshDefinition();
PartDefinition modelPartData = modelData.getRoot();
CubeDeformation deformation_partC = new CubeDeformation(0.0f);
modelPartData.addOrReplaceChild("partC", CubeListBuilder.create().texOffs(0, 19).addBox(1.0f, 0.0f, 1.0f, 14.0f, 9.0f, 14.0f, deformation_partC), PartPose.ZERO);
modelPartData.addOrReplaceChild(
"partC",
CubeListBuilder.create().texOffs(0, 19).addBox(1.0f, 0.0f, 1.0f, 14.0f, 9.0f, 14.0f, deformation_partC),
PartPose.ZERO
);
CubeDeformation deformation_partA = new CubeDeformation(0.0f);
modelPartData.addOrReplaceChild("partA", CubeListBuilder.create().texOffs(0, 0).addBox(1.0f, 0.0f, 0.0f, 14.0f, 5.0f, 14.0f, deformation_partA), PartPose.offset(0.0f, 9.0f, 1.0f));
modelPartData.addOrReplaceChild(
"partA",
CubeListBuilder.create().texOffs(0, 0).addBox(1.0f, 0.0f, 0.0f, 14.0f, 5.0f, 14.0f, deformation_partA),
PartPose.offset(0.0f, 9.0f, 1.0f)
);
CubeDeformation deformation_partB = new CubeDeformation(0.0f);
modelPartData.addOrReplaceChild("partB", CubeListBuilder.create().texOffs(0, 0).addBox(7.0f, -1.0f, 15.0f, 2.0f, 4.0f, 1.0f, deformation_partB), PartPose.offset(0.0f, 8.0f, 0.0f));
modelPartData.addOrReplaceChild(
"partB",
CubeListBuilder.create().texOffs(0, 0).addBox(7.0f, -1.0f, 15.0f, 2.0f, 4.0f, 1.0f, deformation_partB),
PartPose.offset(0.0f, 8.0f, 0.0f)
);
CubeDeformation deformation_partRightC = new CubeDeformation(0.0f);
modelPartData.addOrReplaceChild("partRightC", CubeListBuilder.create().texOffs(0, 19).addBox(1.0f, 0.0f, 1.0f, 15.0f, 9.0f, 14.0f, deformation_partRightC), PartPose.ZERO);
modelPartData.addOrReplaceChild(
"partRightC",
CubeListBuilder.create()
.texOffs(0, 19)
.addBox(1.0f, 0.0f, 1.0f, 15.0f, 9.0f, 14.0f, deformation_partRightC),
PartPose.ZERO
);
CubeDeformation deformation_partRightA = new CubeDeformation(0.0f);
modelPartData.addOrReplaceChild("partRightA", CubeListBuilder.create().texOffs(0, 0).addBox(1.0f, 0.0f, 0.0f, 15.0f, 5.0f, 14.0f, deformation_partRightA), PartPose.offset(0.0f, 9.0f, 1.0f));
modelPartData.addOrReplaceChild(
"partRightA",
CubeListBuilder.create().texOffs(0, 0).addBox(1.0f, 0.0f, 0.0f, 15.0f, 5.0f, 14.0f, deformation_partRightA),
PartPose.offset(0.0f, 9.0f, 1.0f)
);
CubeDeformation deformation_partRightB = new CubeDeformation(0.0f);
PartDefinition partRightB = modelPartData.addOrReplaceChild("partRightB", CubeListBuilder.create().texOffs(0, 0).addBox(15.0f, -1.0f, 15.0f, 1.0f, 4.0f, 1.0f, deformation_partRightB), PartPose.offset(0.0f, 8.0f, 0.0f));
PartDefinition partRightB = modelPartData.addOrReplaceChild(
"partRightB",
CubeListBuilder.create()
.texOffs(0, 0)
.addBox(15.0f, -1.0f, 15.0f, 1.0f, 4.0f, 1.0f, deformation_partRightB),
PartPose.offset(0.0f, 8.0f, 0.0f)
);
CubeDeformation deformation_partLeftC = new CubeDeformation(0.0f);
modelPartData.addOrReplaceChild("partLeftC", CubeListBuilder.create().texOffs(0, 19).addBox(0.0f, 0.0f, 1.0f, 15.0f, 9.0f, 14.0f, deformation_partLeftC), PartPose.ZERO);
modelPartData.addOrReplaceChild(
"partLeftC",
CubeListBuilder.create().texOffs(0, 19).addBox(0.0f, 0.0f, 1.0f, 15.0f, 9.0f, 14.0f, deformation_partLeftC),
PartPose.ZERO
);
CubeDeformation deformation_partLeftA = new CubeDeformation(0.0f);
modelPartData.addOrReplaceChild("partLeftA", CubeListBuilder.create().texOffs(0, 0).addBox(0.0f, 0.0f, 0.0f, 15.0f, 5.0f, 14.0f, deformation_partLeftA), PartPose.offset(0.0f, 9.0f, 1.0f));
modelPartData.addOrReplaceChild(
"partLeftA",
CubeListBuilder.create().texOffs(0, 0).addBox(0.0f, 0.0f, 0.0f, 15.0f, 5.0f, 14.0f, deformation_partLeftA),
PartPose.offset(0.0f, 9.0f, 1.0f)
);
CubeDeformation deformation_partLeftB = new CubeDeformation(0.0f);
modelPartData.addOrReplaceChild("partLeftB", CubeListBuilder.create().texOffs(0, 0).addBox(0.0f, -1.0f, 15.0f, 1.0f, 4.0f, 1.0f, deformation_partLeftB), PartPose.offset(0.0f, 8.0f, 0.0f));
modelPartData.addOrReplaceChild(
"partLeftB",
CubeListBuilder.create().texOffs(0, 0).addBox(0.0f, -1.0f, 15.0f, 1.0f, 4.0f, 1.0f, deformation_partLeftB),
PartPose.offset(0.0f, 8.0f, 0.0f)
);
return LayerDefinition.create(modelData, 64, 64);
}

View file

@ -78,7 +78,12 @@ public class ModelsHelper {
}
public static MultiVariant createRandomTopModel(ResourceLocation resourceLocation) {
return new MultiVariant(Lists.newArrayList(new Variant(resourceLocation, Transformation.identity(), false, 1), new Variant(resourceLocation, BlockModelRotation.X0_Y90.getRotation(), false, 1), new Variant(resourceLocation, BlockModelRotation.X0_Y180.getRotation(), false, 1), new Variant(resourceLocation, BlockModelRotation.X0_Y270.getRotation(), false, 1)));
return new MultiVariant(Lists.newArrayList(
new Variant(resourceLocation, Transformation.identity(), false, 1),
new Variant(resourceLocation, BlockModelRotation.X0_Y90.getRotation(), false, 1),
new Variant(resourceLocation, BlockModelRotation.X0_Y180.getRotation(), false, 1),
new Variant(resourceLocation, BlockModelRotation.X0_Y270.getRotation(), false, 1)
));
}
public static class MultiPartBuilder {

View file

@ -52,7 +52,8 @@ public class PatternsHelper {
public static Optional<String> createJson(ResourceLocation patternId, Map<String, String> textures) {
ResourceManager resourceManager = Minecraft.getInstance().getResourceManager();
try (InputStream input = resourceManager.getResource(patternId).getInputStream()) {
String json = new BufferedReader(new InputStreamReader(input, StandardCharsets.UTF_8)).lines().collect(Collectors.joining());
String json = new BufferedReader(new InputStreamReader(input, StandardCharsets.UTF_8)).lines()
.collect(Collectors.joining());
for (Map.Entry<String, String> texture : textures.entrySet()) {
json = json.replace(texture.getKey(), texture.getValue());
}

View file

@ -51,7 +51,11 @@ public class BaseChestBlockEntityRenderer implements BlockEntityRenderer<BaseChe
public void render(BaseChestBlockEntity entity, float tickDelta, PoseStack matrices, MultiBufferSource vertexConsumers, int light, int overlay) {
Level world = entity.getLevel();
boolean worldExists = world != null;
BlockState blockState = worldExists ? entity.getBlockState() : Blocks.CHEST.defaultBlockState().setValue(ChestBlock.FACING, Direction.SOUTH);
BlockState blockState = worldExists ? entity.getBlockState() : Blocks.CHEST.defaultBlockState()
.setValue(
ChestBlock.FACING,
Direction.SOUTH
);
ChestType chestType = blockState.hasProperty(ChestBlock.TYPE) ? blockState.getValue(ChestBlock.TYPE) : ChestType.SINGLE;
Block block = blockState.getBlock();
if (block instanceof AbstractChestBlock) {
@ -72,23 +76,54 @@ public class BaseChestBlockEntityRenderer implements BlockEntityRenderer<BaseChe
propertySource = DoubleBlockCombiner.Combiner::acceptNone;
}
float pitch = ((Float2FloatFunction) propertySource.apply(ChestBlock.opennessCombiner(entity))).get(tickDelta);
float pitch = ((Float2FloatFunction) propertySource.apply(ChestBlock.opennessCombiner(entity))).get(
tickDelta);
pitch = 1.0F - pitch;
pitch = 1.0F - pitch * pitch * pitch;
@SuppressWarnings({"unchecked", "rawtypes"}) int blockLight = ((Int2IntFunction) propertySource.apply(new BrightnessCombiner())).applyAsInt(light);
@SuppressWarnings({
"unchecked",
"rawtypes"
}) int blockLight = ((Int2IntFunction) propertySource.apply(new BrightnessCombiner())).applyAsInt(light);
VertexConsumer vertexConsumer = getConsumer(vertexConsumers, block, chestType);
if (isDouble) {
if (chestType == ChestType.LEFT) {
renderParts(matrices, vertexConsumer, chestModel.partLeftA, chestModel.partLeftB, chestModel.partLeftC, pitch, blockLight, overlay);
renderParts(
matrices,
vertexConsumer,
chestModel.partLeftA,
chestModel.partLeftB,
chestModel.partLeftC,
pitch,
blockLight,
overlay
);
}
else {
renderParts(matrices, vertexConsumer, chestModel.partRightA, chestModel.partRightB, chestModel.partRightC, pitch, blockLight, overlay);
renderParts(
matrices,
vertexConsumer,
chestModel.partRightA,
chestModel.partRightB,
chestModel.partRightC,
pitch,
blockLight,
overlay
);
}
}
else {
renderParts(matrices, vertexConsumer, chestModel.partA, chestModel.partB, chestModel.partC, pitch, blockLight, overlay);
renderParts(
matrices,
vertexConsumer,
chestModel.partA,
chestModel.partB,
chestModel.partC,
pitch,
blockLight,
overlay
);
}
matrices.popPose();
@ -120,10 +155,24 @@ public class BaseChestBlockEntityRenderer implements BlockEntityRenderer<BaseChe
ResourceLocation blockId = Registry.BLOCK.getKey(block);
String modId = blockId.getNamespace();
String path = blockId.getPath();
LAYERS.put(block, new RenderType[] {RenderType.entityCutout(new ResourceLocation(modId, "textures/entity/chest/" + path + ".png")), RenderType.entityCutout(new ResourceLocation(modId, "textures/entity/chest/" + path + "_left.png")), RenderType.entityCutout(new ResourceLocation(modId, "textures/entity/chest/" + path + "_right.png"))});
LAYERS.put(
block,
new RenderType[] {
RenderType.entityCutout(new ResourceLocation(
modId,
"textures/entity/chest/" + path + ".png"
)),
RenderType.entityCutout(new ResourceLocation(modId, "textures/entity/chest/" + path + "_left.png")),
RenderType.entityCutout(new ResourceLocation(modId, "textures/entity/chest/" + path + "_right.png"))
}
);
}
static {
defaultLayer = new RenderType[] {RenderType.entityCutout(new ResourceLocation("textures/entity/chest/normal.png")), RenderType.entityCutout(new ResourceLocation("textures/entity/chest/normal_left.png")), RenderType.entityCutout(new ResourceLocation("textures/entity/chest/normal_right.png"))};
defaultLayer = new RenderType[] {
RenderType.entityCutout(new ResourceLocation("textures/entity/chest/normal.png")),
RenderType.entityCutout(new ResourceLocation("textures/entity/chest/normal_left.png")),
RenderType.entityCutout(new ResourceLocation("textures/entity/chest/normal_right.png"))
};
}
}

View file

@ -87,10 +87,14 @@ public class BaseSignBlockEntityRenderer implements BlockEntityRenderer<BaseSign
int p = (int) (NativeImage.getB(m) * 0.4D);
int q = NativeImage.combine(0, p, o, n);
FormattedCharSequence[] formattedCharSequences = signBlockEntity.getRenderMessages(Minecraft.getInstance().isTextFilteringEnabled(), (component) -> {
FormattedCharSequence[] formattedCharSequences = signBlockEntity.getRenderMessages(
Minecraft.getInstance()
.isTextFilteringEnabled(),
(component) -> {
List<FormattedCharSequence> list = this.font.split(component, 90);
return list.isEmpty() ? FormattedCharSequence.EMPTY : (FormattedCharSequence) list.get(0);
});
}
);
int drawColor;
boolean drawOutlined;
int drawLight;
@ -109,10 +113,30 @@ public class BaseSignBlockEntityRenderer implements BlockEntityRenderer<BaseSign
FormattedCharSequence formattedCharSequence = formattedCharSequences[s];
float t = (float) (-this.font.width(formattedCharSequence) / 2);
if (drawOutlined) {
this.font.drawInBatch8xOutline(formattedCharSequence, t, (float) (s * 10 - 20), drawColor, m, matrixStack.last().pose(), provider, drawLight);
this.font.drawInBatch8xOutline(
formattedCharSequence,
t,
(float) (s * 10 - 20),
drawColor,
m,
matrixStack.last().pose(),
provider,
drawLight
);
}
else {
this.font.drawInBatch((FormattedCharSequence) formattedCharSequence, t, (float) (s * 10 - 20), drawColor, false, matrixStack.last().pose(), provider, false, 0, drawLight);
this.font.drawInBatch(
(FormattedCharSequence) formattedCharSequence,
t,
(float) (s * 10 - 20),
drawColor,
false,
matrixStack.last().pose(),
provider,
false,
0,
drawLight
);
}
}
@ -160,7 +184,10 @@ public class BaseSignBlockEntityRenderer implements BlockEntityRenderer<BaseSign
public static void registerRenderLayer(Block block) {
ResourceLocation blockId = Registry.BLOCK.getKey(block);
RenderType layer = RenderType.entitySolid(new ResourceLocation(blockId.getNamespace(), "textures/entity/sign/" + blockId.getPath() + ".png"));
RenderType layer = RenderType.entitySolid(new ResourceLocation(
blockId.getNamespace(),
"textures/entity/sign/" + blockId.getPath() + ".png"
));
LAYERS.put(block, layer);
}

View file

@ -4,5 +4,13 @@ import net.minecraft.sounds.SoundEvents;
import net.minecraft.world.level.block.SoundType;
public class BlockSounds {
public static final SoundType TERRAIN_SOUND = new SoundType(1.0F, 1.0F, SoundEvents.STONE_BREAK, SoundEvents.WART_BLOCK_STEP, SoundEvents.STONE_PLACE, SoundEvents.STONE_HIT, SoundEvents.STONE_FALL);
public static final SoundType TERRAIN_SOUND = new SoundType(
1.0F,
1.0F,
SoundEvents.STONE_BREAK,
SoundEvents.WART_BLOCK_STEP,
SoundEvents.STONE_PLACE,
SoundEvents.STONE_HIT,
SoundEvents.STONE_FALL
);
}

View file

@ -19,7 +19,10 @@ public class ConfigWriter {
}
public ConfigWriter(String modID, String configFile, File configFolder) {
this.configFile = new File((configFolder == null ? GAME_CONFIG_DIR.resolve(modID).toFile() : new File(configFolder, modID)), configFile + ".json");
this.configFile = new File((configFolder == null ? GAME_CONFIG_DIR.resolve(modID).toFile() : new File(
configFolder,
modID
)), configFile + ".json");
File parent = this.configFile.getParentFile();
if (!parent.exists()) {
parent.mkdirs();

View file

@ -1,4 +1,4 @@
package ru.bclib.client.models;
package ru.bclib.interfaces;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
@ -8,6 +8,8 @@ import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.level.block.state.BlockState;
import org.jetbrains.annotations.Nullable;
import ru.bclib.BCLib;
import ru.bclib.client.models.ModelsHelper;
import ru.bclib.client.models.PatternsHelper;
import java.util.Map;
import java.util.Optional;

View file

@ -3,7 +3,7 @@ package ru.bclib.interfaces;
import net.minecraft.client.color.block.BlockColor;
import net.minecraft.client.color.item.ItemColor;
public interface IColorProvider {
public interface CustomColorProvider {
BlockColor getProvider();
ItemColor getItemProvider();

View file

@ -0,0 +1,14 @@
package ru.bclib.interfaces;
import net.fabricmc.fabric.api.item.v1.FabricItemSettings;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.BlockItem;
public interface CustomItemProvider {
/**
* Used to replace default Block Item when block is registered.
*
* @return {@link BlockItem}
*/
BlockItem getCustomItem(ResourceLocation blockID, FabricItemSettings settings);
}

View file

@ -1,7 +0,0 @@
package ru.bclib.interfaces;
public interface ISpetialItem {
boolean canPlaceOnWater();
int getStackSize();
}

View file

@ -1,9 +1,10 @@
package ru.bclib.client.models;
package ru.bclib.interfaces;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.renderer.block.model.BlockModel;
import net.minecraft.resources.ResourceLocation;
import ru.bclib.client.models.ModelsHelper;
public interface ItemModelProvider {
@Environment(EnvType.CLIENT)

View file

@ -1,5 +1,5 @@
package ru.bclib.interfaces;
public interface IPostInit {
public interface PostInitable {
void postInit();
}

View file

@ -2,6 +2,6 @@ package ru.bclib.interfaces;
import ru.bclib.client.render.BCLRenderLayer;
public interface IRenderTyped {
public interface RenderLayerProvider {
BCLRenderLayer getRenderLayer();
}

View file

@ -16,12 +16,12 @@ import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import org.jetbrains.annotations.Nullable;
import ru.bclib.blocks.BaseAnvilBlock;
import ru.bclib.client.models.ItemModelProvider;
import ru.bclib.interfaces.BlockModelProvider;
import ru.bclib.interfaces.ItemModelProvider;
import java.util.List;
public class BaseAnvilItem extends BlockItem implements ItemModelProvider {
public final static String DESTRUCTION = "destruction";
public BaseAnvilItem(Block block, Properties properties) {
@ -54,6 +54,6 @@ public class BaseAnvilItem extends BlockItem implements ItemModelProvider {
public BlockModel getItemModel(ResourceLocation resourceLocation) {
Block anvilBlock = getBlock();
ResourceLocation blockId = Registry.BLOCK.getKey(anvilBlock);
return ((ItemModelProvider) anvilBlock).getItemModel(blockId);
return ((BlockModelProvider) anvilBlock).getBlockModel(blockId, anvilBlock.defaultBlockState());
}
}

View file

@ -8,13 +8,18 @@ import net.minecraft.world.entity.ai.attributes.AttributeModifier;
import net.minecraft.world.entity.ai.attributes.Attributes;
import net.minecraft.world.item.ArmorItem;
import net.minecraft.world.item.ArmorMaterial;
import ru.bclib.client.models.ItemModelProvider;
import ru.bclib.interfaces.ItemModelProvider;
import java.util.UUID;
public class BaseArmorItem extends ArmorItem implements ItemModelProvider {
protected static final UUID[] ARMOR_MODIFIER_UUID_PER_SLOT = new UUID[] {UUID.fromString("845DB27C-C624-495F-8C9F-6020A9A58B6B"), UUID.fromString("D8499B04-0E66-4726-AB29-64469D734E0D"), UUID.fromString("9F3D476D-C118-4544-8365-64846904B48E"), UUID.fromString("2AD3F246-FEE1-4E67-B886-69FD380BB150")};
protected static final UUID[] ARMOR_MODIFIER_UUID_PER_SLOT = new UUID[] {
UUID.fromString("845DB27C-C624-495F-8C9F-6020A9A58B6B"),
UUID.fromString("D8499B04-0E66-4726-AB29-64469D734E0D"),
UUID.fromString("9F3D476D-C118-4544-8365-64846904B48E"),
UUID.fromString("2AD3F246-FEE1-4E67-B886-69FD380BB150")
};
protected final Multimap<Attribute, AttributeModifier> defaultModifiers;
@ -22,10 +27,23 @@ public class BaseArmorItem extends ArmorItem implements ItemModelProvider {
super(material, equipmentSlot, settings);
this.defaultModifiers = HashMultimap.create();
UUID uuid = ARMOR_MODIFIER_UUID_PER_SLOT[equipmentSlot.getIndex()];
addAttributeModifier(Attributes.ARMOR, new AttributeModifier(uuid, "Armor modifier", getDefense(), AttributeModifier.Operation.ADDITION));
addAttributeModifier(Attributes.ARMOR_TOUGHNESS, new AttributeModifier(uuid, "Armor toughness", getToughness(), AttributeModifier.Operation.ADDITION));
addAttributeModifier(
Attributes.ARMOR,
new AttributeModifier(uuid, "Armor modifier", getDefense(), AttributeModifier.Operation.ADDITION)
);
addAttributeModifier(
Attributes.ARMOR_TOUGHNESS,
new AttributeModifier(uuid, "Armor toughness", getToughness(), AttributeModifier.Operation.ADDITION)
);
if (knockbackResistance > 0.0F) {
addAttributeModifier(Attributes.KNOCKBACK_RESISTANCE, new AttributeModifier(uuid, "Armor knockback resistance", knockbackResistance, AttributeModifier.Operation.ADDITION));
addAttributeModifier(
Attributes.KNOCKBACK_RESISTANCE,
new AttributeModifier(uuid,
"Armor knockback resistance",
knockbackResistance,
AttributeModifier.Operation.ADDITION
)
);
}
}

View file

@ -5,7 +5,7 @@ import net.minecraft.sounds.SoundEvents;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.item.MobBucketItem;
import net.minecraft.world.level.material.Fluids;
import ru.bclib.client.models.ItemModelProvider;
import ru.bclib.interfaces.ItemModelProvider;
public class BaseBucketItem extends MobBucketItem implements ItemModelProvider {
public BaseBucketItem(EntityType<?> type, FabricItemSettings settings) {

View file

@ -2,7 +2,7 @@ package ru.bclib.items;
import net.minecraft.sounds.SoundEvent;
import net.minecraft.world.item.RecordItem;
import ru.bclib.client.models.ItemModelProvider;
import ru.bclib.interfaces.ItemModelProvider;
public class BaseDiscItem extends RecordItem implements ItemModelProvider {
public BaseDiscItem(int comparatorOutput, SoundEvent sound, Properties settings) {

View file

@ -8,9 +8,9 @@ import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.Mob;
import net.minecraft.world.item.SpawnEggItem;
import ru.bclib.client.models.BasePatterns;
import ru.bclib.client.models.ItemModelProvider;
import ru.bclib.client.models.ModelsHelper;
import ru.bclib.client.models.PatternsHelper;
import ru.bclib.interfaces.ItemModelProvider;
import java.util.Optional;

View file

@ -5,8 +5,8 @@ import net.fabricmc.api.Environment;
import net.minecraft.client.renderer.block.model.BlockModel;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.Item;
import ru.bclib.client.models.ItemModelProvider;
import ru.bclib.client.models.ModelsHelper;
import ru.bclib.interfaces.ItemModelProvider;
public class ModelProviderItem extends Item implements ItemModelProvider {
public ModelProviderItem(Properties settings) {

View file

@ -13,8 +13,8 @@ import net.minecraft.world.item.Item;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Tier;
import net.minecraft.world.level.block.state.BlockState;
import ru.bclib.client.models.ItemModelProvider;
import ru.bclib.client.models.ModelsHelper;
import ru.bclib.interfaces.ItemModelProvider;
public class BaseAxeItem extends AxeItem implements DynamicAttributeTool, ItemModelProvider {
public BaseAxeItem(Tier material, float attackDamage, float attackSpeed, Properties settings) {

View file

@ -6,8 +6,8 @@ import net.minecraft.client.renderer.block.model.BlockModel;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.HoeItem;
import net.minecraft.world.item.Tier;
import ru.bclib.client.models.ItemModelProvider;
import ru.bclib.client.models.ModelsHelper;
import ru.bclib.interfaces.ItemModelProvider;
public class BaseHoeItem extends HoeItem implements ItemModelProvider {
public BaseHoeItem(Tier material, int attackDamage, float attackSpeed, Properties settings) {

View file

@ -15,8 +15,8 @@ import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.PickaxeItem;
import net.minecraft.world.item.Tier;
import net.minecraft.world.level.block.state.BlockState;
import ru.bclib.client.models.ItemModelProvider;
import ru.bclib.client.models.ModelsHelper;
import ru.bclib.interfaces.ItemModelProvider;
public class BasePickaxeItem extends PickaxeItem implements DynamicAttributeTool, ItemModelProvider {
public BasePickaxeItem(Tier material, int attackDamage, float attackSpeed, Properties settings) {
@ -34,7 +34,10 @@ public class BasePickaxeItem extends PickaxeItem implements DynamicAttributeTool
@Override
public float getDestroySpeed(ItemStack stack, BlockState state) {
Entry entry = ToolManagerImpl.entryNullable(state.getBlock());
return (entry != null && entry.getMiningLevel(FabricToolTags.PICKAXES) >= 0) ? speed : super.getDestroySpeed(stack, state);
return (entry != null && entry.getMiningLevel(FabricToolTags.PICKAXES) >= 0) ? speed : super.getDestroySpeed(
stack,
state
);
}
@Override

View file

@ -15,8 +15,8 @@ import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.ShovelItem;
import net.minecraft.world.item.Tier;
import net.minecraft.world.level.block.state.BlockState;
import ru.bclib.client.models.ItemModelProvider;
import ru.bclib.client.models.ModelsHelper;
import ru.bclib.interfaces.ItemModelProvider;
public class BaseShovelItem extends ShovelItem implements DynamicAttributeTool, ItemModelProvider {
public BaseShovelItem(Tier material, float attackDamage, float attackSpeed, Properties settings) {
@ -34,7 +34,10 @@ public class BaseShovelItem extends ShovelItem implements DynamicAttributeTool,
@Override
public float getDestroySpeed(ItemStack stack, BlockState state) {
Entry entry = ToolManagerImpl.entryNullable(state.getBlock());
return (entry != null && entry.getMiningLevel(FabricToolTags.SHOVELS) >= 0) ? speed : super.getDestroySpeed(stack, state);
return (entry != null && entry.getMiningLevel(FabricToolTags.SHOVELS) >= 0) ? speed : super.getDestroySpeed(
stack,
state
);
}
@Override

View file

@ -7,8 +7,8 @@ import net.minecraft.client.renderer.block.model.BlockModel;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.SwordItem;
import net.minecraft.world.item.Tier;
import ru.bclib.client.models.ItemModelProvider;
import ru.bclib.client.models.ModelsHelper;
import ru.bclib.interfaces.ItemModelProvider;
public class BaseSwordItem extends SwordItem implements DynamicAttributeTool, ItemModelProvider {
public BaseSwordItem(Tier material, int attackDamage, float attackSpeed, Properties settings) {

View file

@ -34,7 +34,15 @@ public abstract class EnchantingTableBlockMixin extends Block {
if (!world.isEmptyBlock(pos.offset(px / 2, 0, pz / 2))) {
break;
}
world.addParticle(ParticleTypes.ENCHANT, pos.getX() + 0.5, pos.getY() + 2.0, pos.getZ() + 0.5, px + random.nextFloat() - 0.5, py - random.nextFloat() - 1.0, pz + random.nextFloat() - 0.5);
world.addParticle(
ParticleTypes.ENCHANT,
pos.getX() + 0.5,
pos.getY() + 2.0,
pos.getZ() + 0.5,
px + random.nextFloat() - 0.5,
py - random.nextFloat() - 1.0,
pz + random.nextFloat() - 0.5
);
}
}
}

View file

@ -11,7 +11,7 @@ import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import ru.bclib.interfaces.IColorProvider;
import ru.bclib.interfaces.CustomColorProvider;
@Mixin(Minecraft.class)
public class MinecraftMixin {
@ -26,8 +26,8 @@ public class MinecraftMixin {
@Inject(method = "<init>*", at = @At("TAIL"))
private void bclib_onMCInit(GameConfig args, CallbackInfo info) {
Registry.BLOCK.forEach(block -> {
if (block instanceof IColorProvider) {
IColorProvider provider = (IColorProvider) block;
if (block instanceof CustomColorProvider) {
CustomColorProvider provider = (CustomColorProvider) block;
blockColors.register(provider.getProvider(), block);
itemColors.register(provider.getItemProvider(), block.asItem());
}

View file

@ -20,8 +20,8 @@ import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import ru.bclib.BCLib;
import ru.bclib.client.models.BlockModelProvider;
import ru.bclib.client.models.ItemModelProvider;
import ru.bclib.interfaces.BlockModelProvider;
import ru.bclib.interfaces.ItemModelProvider;
import java.util.List;
import java.util.Map;
@ -81,13 +81,26 @@ public abstract class ModelBakeryMixin {
Block block = Registry.BLOCK.get(clearLoc);
if (block instanceof BlockModelProvider) {
List<BlockState> possibleStates = block.getStateDefinition().getPossibleStates();
Optional<BlockState> possibleState = possibleStates.stream().filter(state -> modelId.equals(BlockModelShaper.stateToModelLocation(clearLoc, state))).findFirst();
Optional<BlockState> possibleState = possibleStates.stream()
.filter(state -> modelId.equals(
BlockModelShaper.stateToModelLocation(
clearLoc,
state
)))
.findFirst();
if (possibleState.isPresent()) {
UnbakedModel modelVariant = ((BlockModelProvider) block).getModelVariant(modelId, possibleState.get(), unbakedCache);
UnbakedModel modelVariant = ((BlockModelProvider) block).getModelVariant(
modelId,
possibleState.get(),
unbakedCache
);
if (modelVariant != null) {
if (modelVariant instanceof MultiPart) {
possibleStates.forEach(state -> {
ResourceLocation stateId = BlockModelShaper.stateToModelLocation(clearLoc, state);
ResourceLocation stateId = BlockModelShaper.stateToModelLocation(
clearLoc,
state
);
cacheAndQueueDependencies(stateId, modelVariant);
});
}

View file

@ -29,12 +29,18 @@ public class TextureAtlasMixin {
private void bclib_loadSprite(ResourceManager resourceManager, TextureAtlasSprite.Info spriteInfo, int atlasWidth, int atlasHeight, int maxLevel, int posX, int posY, CallbackInfoReturnable<TextureAtlasSprite> info) {
ResourceLocation location = spriteInfo.name();
if (bclib_modifyAtlas && location.getPath().startsWith("block")) {
ResourceLocation emissiveLocation = new ResourceLocation(location.getNamespace(), "textures/" + location.getPath() + "_e.png");
ResourceLocation emissiveLocation = new ResourceLocation(
location.getNamespace(),
"textures/" + location.getPath() + "_e.png"
);
if (resourceManager.hasResource(emissiveLocation)) {
NativeImage sprite = null;
NativeImage emission = null;
try {
ResourceLocation spriteLocation = new ResourceLocation(location.getNamespace(), "textures/" + location.getPath() + ".png");
ResourceLocation spriteLocation = new ResourceLocation(
location.getNamespace(),
"textures/" + location.getPath() + ".png"
);
Resource resource = resourceManager.getResource(spriteLocation);
sprite = NativeImage.read(resource.getInputStream());
resource.close();
@ -65,7 +71,16 @@ public class TextureAtlasMixin {
}
}
TextureAtlas self = (TextureAtlas) (Object) this;
FabricSprite result = new FabricSprite(self, spriteInfo, maxLevel, atlasWidth, atlasHeight, posX, posY, sprite);
FabricSprite result = new FabricSprite(
self,
spriteInfo,
maxLevel,
atlasWidth,
atlasHeight,
posX,
posY,
sprite
);
info.setReturnValue(result);
}
}

View file

@ -99,7 +99,8 @@ public class BoneMealItemMixin {
for (int y = y1; y >= y2; y--) {
bclib_BLOCK_POS.setY(y);
BlockPos down = bclib_BLOCK_POS.below();
if (BlocksHelper.isFluid(world.getBlockState(bclib_BLOCK_POS)) && !BlocksHelper.isFluid(world.getBlockState(down))) {
if (BlocksHelper.isFluid(world.getBlockState(bclib_BLOCK_POS)) && !BlocksHelper.isFluid(world.getBlockState(
down))) {
BlockState grass = bclib_getWaterGrassState(world, down);
if (grass != null) {
BlocksHelper.setWithoutUpdate(world, bclib_BLOCK_POS, grass);

View file

@ -66,7 +66,11 @@ public abstract class EnchantmentMenuMixin extends AbstractContainerMenu {
int j;
for (j = -1; j <= 1; ++j) {
for (int k = -1; k <= 1; ++k) {
if ((j != 0 || k != 0) && world.isEmptyBlock(blockPos.offset(k, 0, j)) && world.isEmptyBlock(blockPos.offset(k, 1, j))) {
if ((j != 0 || k != 0) && world.isEmptyBlock(blockPos.offset(
k,
0,
j
)) && world.isEmptyBlock(blockPos.offset(k, 1, j))) {
if (world.getBlockState(blockPos.offset(k * 2, 0, j * 2)).is(TagAPI.BOOKSHELVES)) {
++i;
}
@ -111,7 +115,8 @@ public abstract class EnchantmentMenuMixin extends AbstractContainerMenu {
if (this.costs[j] > 0) {
List<EnchantmentInstance> list = this.getEnchantmentList(itemStack, j, this.costs[j]);
if (list != null && !list.isEmpty()) {
EnchantmentInstance enchantmentLevelEntry = (EnchantmentInstance) list.get(this.random.nextInt(list.size()));
EnchantmentInstance enchantmentLevelEntry = (EnchantmentInstance) list.get(this.random.nextInt(
list.size()));
enchantClue[j] = Registry.ENCHANTMENT.getId(enchantmentLevelEntry.enchantment);
levelClue[j] = enchantmentLevelEntry.level;
}

View file

@ -2256,21 +2256,48 @@ public class OpenSimplexNoise {
double attn_ext0 = 2 - dx_ext0 * dx_ext0 - dy_ext0 * dy_ext0 - dz_ext0 * dz_ext0 - dw_ext0 * dw_ext0;
if (attn_ext0 > 0) {
attn_ext0 *= attn_ext0;
value += attn_ext0 * attn_ext0 * extrapolate(xsv_ext0, ysv_ext0, zsv_ext0, wsv_ext0, dx_ext0, dy_ext0, dz_ext0, dw_ext0);
value += attn_ext0 * attn_ext0 * extrapolate(
xsv_ext0,
ysv_ext0,
zsv_ext0,
wsv_ext0,
dx_ext0,
dy_ext0,
dz_ext0,
dw_ext0
);
}
// Second extra vertex
double attn_ext1 = 2 - dx_ext1 * dx_ext1 - dy_ext1 * dy_ext1 - dz_ext1 * dz_ext1 - dw_ext1 * dw_ext1;
if (attn_ext1 > 0) {
attn_ext1 *= attn_ext1;
value += attn_ext1 * attn_ext1 * extrapolate(xsv_ext1, ysv_ext1, zsv_ext1, wsv_ext1, dx_ext1, dy_ext1, dz_ext1, dw_ext1);
value += attn_ext1 * attn_ext1 * extrapolate(
xsv_ext1,
ysv_ext1,
zsv_ext1,
wsv_ext1,
dx_ext1,
dy_ext1,
dz_ext1,
dw_ext1
);
}
// Third extra vertex
double attn_ext2 = 2 - dx_ext2 * dx_ext2 - dy_ext2 * dy_ext2 - dz_ext2 * dz_ext2 - dw_ext2 * dw_ext2;
if (attn_ext2 > 0) {
attn_ext2 *= attn_ext2;
value += attn_ext2 * attn_ext2 * extrapolate(xsv_ext2, ysv_ext2, zsv_ext2, wsv_ext2, dx_ext2, dy_ext2, dz_ext2, dw_ext2);
value += attn_ext2 * attn_ext2 * extrapolate(
xsv_ext2,
ysv_ext2,
zsv_ext2,
wsv_ext2,
dx_ext2,
dy_ext2,
dz_ext2,
dw_ext2
);
}
return value / NORM_CONSTANT_4D;
@ -2304,11 +2331,341 @@ public class OpenSimplexNoise {
// vertices of a rhombicuboctahedron from the center, skewed so
// that the triangular and square facets can be inscribed inside
// circles of the same radius.
private static byte[] gradients3D = new byte[] {-11, 4, 4, -4, 11, 4, -4, 4, 11, 11, 4, 4, 4, 11, 4, 4, 4, 11, -11, -4, 4, -4, -11, 4, -4, -4, 11, 11, -4, 4, 4, -11, 4, 4, -4, 11, -11, 4, -4, -4, 11, -4, -4, 4, -11, 11, 4, -4, 4, 11, -4, 4, 4, -11, -11, -4, -4, -4, -11, -4, -4, -4, -11, 11, -4, -4, 4, -11, -4, 4, -4, -11,};
private static byte[] gradients3D = new byte[] {
-11,
4,
4,
-4,
11,
4,
-4,
4,
11,
11,
4,
4,
4,
11,
4,
4,
4,
11,
-11,
-4,
4,
-4,
-11,
4,
-4,
-4,
11,
11,
-4,
4,
4,
-11,
4,
4,
-4,
11,
-11,
4,
-4,
-4,
11,
-4,
-4,
4,
-11,
11,
4,
-4,
4,
11,
-4,
4,
4,
-11,
-11,
-4,
-4,
-4,
-11,
-4,
-4,
-4,
-11,
11,
-4,
-4,
4,
-11,
-4,
4,
-4,
-11,
};
// Gradients for 4D. They approximate the directions to the
// vertices of a disprismatotesseractihexadecachoron from the center,
// skewed so that the tetrahedral and cubic facets can be inscribed inside
// spheres of the same radius.
private static byte[] gradients4D = new byte[] {3, 1, 1, 1, 1, 3, 1, 1, 1, 1, 3, 1, 1, 1, 1, 3, -3, 1, 1, 1, -1, 3, 1, 1, -1, 1, 3, 1, -1, 1, 1, 3, 3, -1, 1, 1, 1, -3, 1, 1, 1, -1, 3, 1, 1, -1, 1, 3, -3, -1, 1, 1, -1, -3, 1, 1, -1, -1, 3, 1, -1, -1, 1, 3, 3, 1, -1, 1, 1, 3, -1, 1, 1, 1, -3, 1, 1, 1, -1, 3, -3, 1, -1, 1, -1, 3, -1, 1, -1, 1, -3, 1, -1, 1, -1, 3, 3, -1, -1, 1, 1, -3, -1, 1, 1, -1, -3, 1, 1, -1, -1, 3, -3, -1, -1, 1, -1, -3, -1, 1, -1, -1, -3, 1, -1, -1, -1, 3, 3, 1, 1, -1, 1, 3, 1, -1, 1, 1, 3, -1, 1, 1, 1, -3, -3, 1, 1, -1, -1, 3, 1, -1, -1, 1, 3, -1, -1, 1, 1, -3, 3, -1, 1, -1, 1, -3, 1, -1, 1, -1, 3, -1, 1, -1, 1, -3, -3, -1, 1, -1, -1, -3, 1, -1, -1, -1, 3, -1, -1, -1, 1, -3, 3, 1, -1, -1, 1, 3, -1, -1, 1, 1, -3, -1, 1, 1, -1, -3, -3, 1, -1, -1, -1, 3, -1, -1, -1, 1, -3, -1, -1, 1, -1, -3, 3, -1, -1, -1, 1, -3, -1, -1, 1, -1, -3, -1, 1, -1, -1, -3, -3, -1, -1, -1, -1, -3, -1, -1, -1, -1, -3, -1, -1, -1, -1, -3,};
private static byte[] gradients4D = new byte[] {
3,
1,
1,
1,
1,
3,
1,
1,
1,
1,
3,
1,
1,
1,
1,
3,
-3,
1,
1,
1,
-1,
3,
1,
1,
-1,
1,
3,
1,
-1,
1,
1,
3,
3,
-1,
1,
1,
1,
-3,
1,
1,
1,
-1,
3,
1,
1,
-1,
1,
3,
-3,
-1,
1,
1,
-1,
-3,
1,
1,
-1,
-1,
3,
1,
-1,
-1,
1,
3,
3,
1,
-1,
1,
1,
3,
-1,
1,
1,
1,
-3,
1,
1,
1,
-1,
3,
-3,
1,
-1,
1,
-1,
3,
-1,
1,
-1,
1,
-3,
1,
-1,
1,
-1,
3,
3,
-1,
-1,
1,
1,
-3,
-1,
1,
1,
-1,
-3,
1,
1,
-1,
-1,
3,
-3,
-1,
-1,
1,
-1,
-3,
-1,
1,
-1,
-1,
-3,
1,
-1,
-1,
-1,
3,
3,
1,
1,
-1,
1,
3,
1,
-1,
1,
1,
3,
-1,
1,
1,
1,
-3,
-3,
1,
1,
-1,
-1,
3,
1,
-1,
-1,
1,
3,
-1,
-1,
1,
1,
-3,
3,
-1,
1,
-1,
1,
-3,
1,
-1,
1,
-1,
3,
-1,
1,
-1,
1,
-3,
-3,
-1,
1,
-1,
-1,
-3,
1,
-1,
-1,
-1,
3,
-1,
-1,
-1,
1,
-3,
3,
1,
-1,
-1,
1,
3,
-1,
-1,
1,
1,
-3,
-1,
1,
1,
-1,
-3,
-3,
1,
-1,
-1,
-1,
3,
-1,
-1,
-1,
1,
-3,
-1,
-1,
1,
-1,
-3,
3,
-1,
-1,
-1,
1,
-3,
-1,
-1,
1,
-1,
-3,
-1,
1,
-1,
-1,
-3,
-3,
-1,
-1,
-1,
-1,
-3,
-1,
-1,
-1,
-1,
-3,
-1,
-1,
-1,
-1,
-3,
};
}

View file

@ -133,8 +133,16 @@ public class VoronoiNoise {
}
}
BlockPos p1 = new BlockPos((ix + (double) selX) * scale, (iy + (double) selY) * scale, (iz + (double) selZ) * scale);
BlockPos p2 = new BlockPos((ix + (double) selXPre) * scale, (iy + (double) selYPre) * scale, (iz + (double) selZPre) * scale);
BlockPos p1 = new BlockPos(
(ix + (double) selX) * scale,
(iy + (double) selY) * scale,
(iz + (double) selZ) * scale
);
BlockPos p2 = new BlockPos(
(ix + (double) selXPre) * scale,
(iy + (double) selYPre) * scale,
(iz + (double) selZPre) * scale
);
return new BlockPos[] {p1, p2};
}
}

View file

@ -9,19 +9,79 @@ import ru.bclib.config.Configs;
public class CraftingRecipes {
public static void init() {
GridRecipe.make(BCLib.MOD_ID, "tag_smith_table", Blocks.SMITHING_TABLE).setShape("II", "##", "##").addMaterial('#', ItemTags.PLANKS).addMaterial('I', TagAPI.IRON_INGOTS).checkConfig(Configs.RECIPE_CONFIG).build();
GridRecipe.make(BCLib.MOD_ID, "tag_cauldron", Blocks.CAULDRON).setShape("I I", "I I", "III").addMaterial('I', TagAPI.IRON_INGOTS).checkConfig(Configs.RECIPE_CONFIG).build();
GridRecipe.make(BCLib.MOD_ID, "tag_hopper", Blocks.HOPPER).setShape("I I", "ICI", " I ").addMaterial('I', TagAPI.IRON_INGOTS).addMaterial('C', TagAPI.ITEM_CHEST).checkConfig(Configs.RECIPE_CONFIG).build();
GridRecipe.make(BCLib.MOD_ID, "tag_piston", Blocks.PISTON).setShape("WWW", "CIC", "CDC").addMaterial('I', TagAPI.IRON_INGOTS).addMaterial('D', Items.REDSTONE).addMaterial('C', Items.COBBLESTONE).addMaterial('W', ItemTags.PLANKS).checkConfig(Configs.RECIPE_CONFIG).build();
GridRecipe.make(BCLib.MOD_ID, "tag_rail", Blocks.RAIL).setOutputCount(16).setShape("I I", "ISI", "I I").addMaterial('I', TagAPI.IRON_INGOTS).addMaterial('S', Items.STICK).checkConfig(Configs.RECIPE_CONFIG).build();
GridRecipe.make(BCLib.MOD_ID, "tag_stonecutter", Blocks.STONECUTTER).setShape(" I ", "SSS").addMaterial('I', TagAPI.IRON_INGOTS).addMaterial('S', Items.STONE).checkConfig(Configs.RECIPE_CONFIG).build();
GridRecipe.make(BCLib.MOD_ID, "tag_bucket", Items.BUCKET).setShape("I I", " I ").addMaterial('I', TagAPI.IRON_INGOTS).checkConfig(Configs.RECIPE_CONFIG).build();
GridRecipe.make(BCLib.MOD_ID, "tag_compass", Items.COMPASS).setShape(" I ", "IDI", " I ").addMaterial('I', TagAPI.IRON_INGOTS).addMaterial('D', Items.REDSTONE).checkConfig(Configs.RECIPE_CONFIG).build();
GridRecipe.make(BCLib.MOD_ID, "tag_minecart", Items.MINECART).setShape("I I", "III").addMaterial('I', TagAPI.IRON_INGOTS).checkConfig(Configs.RECIPE_CONFIG).build();
GridRecipe.make(BCLib.MOD_ID, "tag_shield", Items.SHIELD).setShape("WIW", "WWW", " W ").addMaterial('I', TagAPI.IRON_INGOTS).addMaterial('W', ItemTags.PLANKS).checkConfig(Configs.RECIPE_CONFIG).build();
GridRecipe.make(BCLib.MOD_ID, "tag_smith_table", Blocks.SMITHING_TABLE)
.setShape("II", "##", "##")
.addMaterial('#', ItemTags.PLANKS)
.addMaterial('I', TagAPI.IRON_INGOTS)
.checkConfig(Configs.RECIPE_CONFIG)
.build();
GridRecipe.make(BCLib.MOD_ID, "tag_cauldron", Blocks.CAULDRON)
.setShape("I I", "I I", "III")
.addMaterial('I', TagAPI.IRON_INGOTS)
.checkConfig(Configs.RECIPE_CONFIG)
.build();
GridRecipe.make(BCLib.MOD_ID, "tag_hopper", Blocks.HOPPER)
.setShape("I I", "ICI", " I ")
.addMaterial('I', TagAPI.IRON_INGOTS)
.addMaterial('C', TagAPI.ITEM_CHEST)
.checkConfig(Configs.RECIPE_CONFIG)
.build();
GridRecipe.make(BCLib.MOD_ID, "tag_piston", Blocks.PISTON)
.setShape("WWW", "CIC", "CDC")
.addMaterial('I', TagAPI.IRON_INGOTS)
.addMaterial('D', Items.REDSTONE)
.addMaterial('C', Items.COBBLESTONE)
.addMaterial('W', ItemTags.PLANKS)
.checkConfig(Configs.RECIPE_CONFIG)
.build();
GridRecipe.make(BCLib.MOD_ID, "tag_rail", Blocks.RAIL)
.setOutputCount(16)
.setShape("I I", "ISI", "I I")
.addMaterial('I', TagAPI.IRON_INGOTS)
.addMaterial('S', Items.STICK)
.checkConfig(Configs.RECIPE_CONFIG)
.build();
GridRecipe.make(BCLib.MOD_ID, "tag_stonecutter", Blocks.STONECUTTER)
.setShape(" I ", "SSS")
.addMaterial('I', TagAPI.IRON_INGOTS)
.addMaterial('S', Items.STONE)
.checkConfig(Configs.RECIPE_CONFIG)
.build();
GridRecipe.make(BCLib.MOD_ID, "tag_bucket", Items.BUCKET)
.setShape("I I", " I ")
.addMaterial('I', TagAPI.IRON_INGOTS)
.checkConfig(Configs.RECIPE_CONFIG)
.build();
GridRecipe.make(BCLib.MOD_ID, "tag_compass", Items.COMPASS)
.setShape(" I ", "IDI", " I ")
.addMaterial('I', TagAPI.IRON_INGOTS)
.addMaterial('D', Items.REDSTONE)
.checkConfig(Configs.RECIPE_CONFIG)
.build();
GridRecipe.make(BCLib.MOD_ID, "tag_minecart", Items.MINECART)
.setShape("I I", "III")
.addMaterial('I', TagAPI.IRON_INGOTS)
.checkConfig(Configs.RECIPE_CONFIG)
.build();
GridRecipe.make(BCLib.MOD_ID, "tag_shield", Items.SHIELD)
.setShape("WIW", "WWW", " W ")
.addMaterial('I', TagAPI.IRON_INGOTS)
.addMaterial('W', ItemTags.PLANKS)
.checkConfig(Configs.RECIPE_CONFIG)
.build();
GridRecipe.make(BCLib.MOD_ID, "tag_hopper", Blocks.HOPPER).setShape("I I", "ICI", " I ").addMaterial('I', TagAPI.IRON_INGOTS).addMaterial('C', TagAPI.ITEM_CHEST).checkConfig(Configs.RECIPE_CONFIG).build();
GridRecipe.make(BCLib.MOD_ID, "tag_hopper", Blocks.HOPPER)
.setShape("I I", "ICI", " I ")
.addMaterial('I', TagAPI.IRON_INGOTS)
.addMaterial('C', TagAPI.ITEM_CHEST)
.checkConfig(Configs.RECIPE_CONFIG)
.build();
GridRecipe.make(BCLib.MOD_ID, "tag_shulker_box", Blocks.SHULKER_BOX).setShape("S", "C", "S").addMaterial('S', Items.SHULKER_SHELL).addMaterial('C', TagAPI.ITEM_CHEST).checkConfig(Configs.RECIPE_CONFIG).build();
GridRecipe.make(BCLib.MOD_ID, "tag_shulker_box", Blocks.SHULKER_BOX)
.setShape("S", "C", "S")
.addMaterial('S', Items.SHULKER_SHELL)
.addMaterial('C', TagAPI.ITEM_CHEST)
.checkConfig(Configs.RECIPE_CONFIG)
.build();
}
}

View file

@ -77,21 +77,49 @@ public class FurnaceRecipe {
public void build(boolean blasting, boolean campfire, boolean smoker) {
if (exist) {
SmeltingRecipe recipe = new SmeltingRecipe(id, group, Ingredient.of(input), new ItemStack(output, count), xp, time);
SmeltingRecipe recipe = new SmeltingRecipe(
id,
group,
Ingredient.of(input),
new ItemStack(output, count),
xp,
time
);
BCLRecipeManager.addRecipe(RecipeType.SMELTING, recipe);
if (blasting) {
BlastingRecipe recipe2 = new BlastingRecipe(id, group, Ingredient.of(input), new ItemStack(output, count), xp, time / 2);
BlastingRecipe recipe2 = new BlastingRecipe(
id,
group,
Ingredient.of(input),
new ItemStack(output, count),
xp,
time / 2
);
BCLRecipeManager.addRecipe(RecipeType.BLASTING, recipe2);
}
if (campfire) {
CampfireCookingRecipe recipe2 = new CampfireCookingRecipe(id, group, Ingredient.of(input), new ItemStack(output, count), xp, time * 3);
CampfireCookingRecipe recipe2 = new CampfireCookingRecipe(
id,
group,
Ingredient.of(input),
new ItemStack(output, count),
xp,
time * 3
);
BCLRecipeManager.addRecipe(RecipeType.CAMPFIRE_COOKING, recipe2);
}
if (smoker) {
SmokingRecipe recipe2 = new SmokingRecipe(id, group, Ingredient.of(input), new ItemStack(output, count), xp, time / 2);
SmokingRecipe recipe2 = new SmokingRecipe(
id,
group,
Ingredient.of(input),
new ItemStack(output, count),
xp,
time / 2
);
BCLRecipeManager.addRecipe(RecipeType.SMOKING, recipe2);
}
}

View file

@ -116,7 +116,14 @@ public class GridRecipe {
ItemStack result = new ItemStack(output, count);
NonNullList<Ingredient> materials = this.getMaterials(width, height);
CraftingRecipe recipe = shaped ? new ShapedRecipe(id, group, width, height, materials, result) : new ShapelessRecipe(id, group, result, materials);
CraftingRecipe recipe = shaped ? new ShapedRecipe(
id,
group,
width,
height,
materials,
result
) : new ShapelessRecipe(id, group, result, materials);
BCLRecipeManager.addRecipe(type, recipe);
}
else {

View file

@ -18,10 +18,16 @@ import ru.bclib.blocks.BaseFurnaceBlock;
import ru.bclib.blocks.BaseSignBlock;
public class BaseBlockEntities {
public static final DynamicBlockEntityType<BaseChestBlockEntity> CHEST = registerBlockEntityType(BCLib.makeID("chest"), BaseChestBlockEntity::new);
public static final DynamicBlockEntityType<BaseBarrelBlockEntity> BARREL = registerBlockEntityType(BCLib.makeID("barrel"), BaseBarrelBlockEntity::new);
public static final DynamicBlockEntityType<BaseSignBlockEntity> SIGN = registerBlockEntityType(BCLib.makeID("sign"), BaseSignBlockEntity::new);
public static final DynamicBlockEntityType<BaseFurnaceBlockEntity> FURNACE = registerBlockEntityType(BCLib.makeID("furnace"), BaseFurnaceBlockEntity::new);
public static final DynamicBlockEntityType<BaseChestBlockEntity> CHEST = registerBlockEntityType(BCLib.makeID(
"chest"), BaseChestBlockEntity::new);
public static final DynamicBlockEntityType<BaseBarrelBlockEntity> BARREL = registerBlockEntityType(BCLib.makeID(
"barrel"), BaseBarrelBlockEntity::new);
public static final DynamicBlockEntityType<BaseSignBlockEntity> SIGN = registerBlockEntityType(
BCLib.makeID("sign"),
BaseSignBlockEntity::new
);
public static final DynamicBlockEntityType<BaseFurnaceBlockEntity> FURNACE = registerBlockEntityType(BCLib.makeID(
"furnace"), BaseFurnaceBlockEntity::new);
public static <T extends BlockEntity> DynamicBlockEntityType<T> registerBlockEntityType(ResourceLocation typeId, BlockEntitySupplier<? extends T> supplier) {
return Registry.register(Registry.BLOCK_ENTITY_TYPE, typeId, new DynamicBlockEntityType<>(supplier));
@ -30,19 +36,39 @@ public class BaseBlockEntities {
public static void register() {}
public static Block[] getChests() {
return BaseRegistry.getRegisteredBlocks().values().stream().filter(item -> item instanceof BlockItem && ((BlockItem) item).getBlock() instanceof BaseChestBlock).map(item -> ((BlockItem) item).getBlock()).toArray(Block[]::new);
return BaseRegistry.getRegisteredBlocks()
.values()
.stream()
.filter(item -> item instanceof BlockItem && ((BlockItem) item).getBlock() instanceof BaseChestBlock)
.map(item -> ((BlockItem) item).getBlock())
.toArray(Block[]::new);
}
public static Block[] getBarrels() {
return BaseRegistry.getRegisteredBlocks().values().stream().filter(item -> item instanceof BlockItem && ((BlockItem) item).getBlock() instanceof BaseBarrelBlock).map(item -> ((BlockItem) item).getBlock()).toArray(Block[]::new);
return BaseRegistry.getRegisteredBlocks()
.values()
.stream()
.filter(item -> item instanceof BlockItem && ((BlockItem) item).getBlock() instanceof BaseBarrelBlock)
.map(item -> ((BlockItem) item).getBlock())
.toArray(Block[]::new);
}
public static Block[] getSigns() {
return BaseRegistry.getRegisteredBlocks().values().stream().filter(item -> item instanceof BlockItem && ((BlockItem) item).getBlock() instanceof BaseSignBlock).map(item -> ((BlockItem) item).getBlock()).toArray(Block[]::new);
return BaseRegistry.getRegisteredBlocks()
.values()
.stream()
.filter(item -> item instanceof BlockItem && ((BlockItem) item).getBlock() instanceof BaseSignBlock)
.map(item -> ((BlockItem) item).getBlock())
.toArray(Block[]::new);
}
public static Block[] getFurnaces() {
return BaseRegistry.getRegisteredBlocks().values().stream().filter(item -> item instanceof BlockItem && ((BlockItem) item).getBlock() instanceof BaseFurnaceBlock).map(item -> ((BlockItem) item).getBlock()).toArray(Block[]::new);
return BaseRegistry.getRegisteredBlocks()
.values()
.stream()
.filter(item -> item instanceof BlockItem && ((BlockItem) item).getBlock() instanceof BaseFurnaceBlock)
.map(item -> ((BlockItem) item).getBlock())
.toArray(Block[]::new);
}
public static boolean registerSpecialBlock(Block block) {

View file

@ -14,11 +14,12 @@ import java.util.List;
import java.util.Map;
public abstract class BaseRegistry<T> {
private static final List<BaseRegistry<?>> REGISTRIES = Lists.newArrayList();
private static final Map<String, List<Item>> MOD_BLOCKS = Maps.newHashMap();
private static final Map<String, List<Item>> MOD_ITEMS = Maps.newHashMap();
protected final CreativeModeTab creativeTab;
public static Map<String, List<Item>> getRegisteredBlocks() {
return MOD_BLOCKS;
}
@ -49,8 +50,6 @@ public abstract class BaseRegistry<T> {
REGISTRIES.forEach(BaseRegistry::registerInternal);
}
protected final CreativeModeTab creativeTab;
protected BaseRegistry(CreativeModeTab creativeTab) {
this.creativeTab = creativeTab;
REGISTRIES.add(this);

View file

@ -6,10 +6,8 @@ import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.item.BlockItem;
import net.minecraft.world.item.CreativeModeTab;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.Item.Properties;
import net.minecraft.world.item.WaterLilyBlockItem;
import net.minecraft.world.level.block.Block;
import ru.bclib.interfaces.ISpetialItem;
import ru.bclib.interfaces.CustomItemProvider;
public abstract class BlocksRegistry extends BaseRegistry<Block> {
@ -19,21 +17,17 @@ public abstract class BlocksRegistry extends BaseRegistry<Block> {
@Override
public Block register(ResourceLocation id, Block block) {
int maxCount = 64;
boolean placeOnWater = false;
if (block instanceof ISpetialItem) {
ISpetialItem item = (ISpetialItem) block;
maxCount = item.getStackSize();
placeOnWater = item.canPlaceOnWater();
}
Properties item = makeItemSettings().stacksTo(maxCount);
if (placeOnWater) {
registerBlockItem(id, new WaterLilyBlockItem(block, item));
BlockItem item = null;
if (block instanceof CustomItemProvider) {
item = ((CustomItemProvider) block).getCustomItem(id, makeItemSettings());
}
else {
registerBlockItem(id, new BlockItem(block, item));
item = new BlockItem(block, makeItemSettings());
}
if (block.defaultBlockState().getMaterial().isFlammable() && FlammableBlockRegistry.getDefaultInstance().get(block).getBurnChance() == 0) {
registerBlockItem(id, item);
if (block.defaultBlockState().getMaterial().isFlammable() && FlammableBlockRegistry.getDefaultInstance()
.get(block)
.getBurnChance() == 0) {
FlammableBlockRegistry.getDefaultInstance().add(block, 5, 5);
}
return Registry.register(Registry.BLOCK, id, block);

View file

@ -78,7 +78,15 @@ public abstract class ItemsRegistry extends BaseRegistry<Item> {
public ItemStack execute(BlockSource pointer, ItemStack stack) {
Direction direction = pointer.getBlockState().getValue(DispenserBlock.FACING);
EntityType<?> entityType = ((SpawnEggItem) stack.getItem()).getType(stack.getTag());
entityType.spawn(pointer.getLevel(), stack, null, pointer.getPos().relative(direction), MobSpawnType.DISPENSER, direction != Direction.UP, false);
entityType.spawn(
pointer.getLevel(),
stack,
null,
pointer.getPos().relative(direction),
MobSpawnType.DISPENSER,
direction != Direction.UP,
false
);
stack.shrink(1);
return stack;
}

View file

@ -34,7 +34,10 @@ public class SDFRadialNoiseMap extends SDFDisplacement {
}
private float getNoise(double x, double z) {
return (float) noise.eval(x, z) + (float) noise.eval(x * 3 + 1000, z * 3) * 0.5F + (float) noise.eval(x * 9 + 1000, z * 9) * 0.2F;
return (float) noise.eval(x, z) + (float) noise.eval(
x * 3 + 1000,
z * 3
) * 0.5F + (float) noise.eval(x * 9 + 1000, z * 9) * 0.2F;
}
public SDFRadialNoiseMap setSeed(long seed) {

View file

@ -30,7 +30,11 @@ public class SDFCappedCone extends SDFPrimitive {
float k2y = 2 * height;
float cax = qx - MHelper.min(qx, (y < 0F) ? radius1 : radius2);
float cay = Math.abs(y) - height;
float mlt = Mth.clamp(MHelper.dot(radius2 - qx, height - y, k2x, k2y) / MHelper.dot(k2x, k2y, k2x, k2y), 0F, 1F);
float mlt = Mth.clamp(
MHelper.dot(radius2 - qx, height - y, k2x, k2y) / MHelper.dot(k2x, k2y, k2x, k2y),
0F,
1F
);
float cbx = qx - radius2 + k2x * mlt;
float cby = y - height + k2y * mlt;
float s = (cbx < 0F && cay < 0F) ? -1F : 1F;

View file

@ -3,15 +3,15 @@ package ru.bclib.server;
import net.fabricmc.api.DedicatedServerModInitializer;
import net.minecraft.core.Registry;
import ru.bclib.api.ModIntegrationAPI;
import ru.bclib.interfaces.IPostInit;
import ru.bclib.interfaces.PostInitable;
public class BCLibServer implements DedicatedServerModInitializer {
@Override
public void onInitializeServer() {
ModIntegrationAPI.registerAll();
Registry.BLOCK.forEach(block -> {
if (block instanceof IPostInit) {
((IPostInit) block).postInit();
if (block instanceof PostInitable) {
((PostInitable) block).postInit();
}
});
}

View file

@ -85,7 +85,10 @@ public class SplineHelper {
for (int i = 1; i < count; i++) {
Vector3f pos = spline.get(i);
float delta = (float) (i - 1) / max;
SDF line = new SDFLine().setRadius(Mth.lerp(delta, radius1, radius2)).setStart(start.x(), start.y(), start.z()).setEnd(pos.x(), pos.y(), pos.z()).setBlock(placerFunction);
SDF line = new SDFLine().setRadius(Mth.lerp(delta, radius1, radius2))
.setStart(start.x(), start.y(), start.z())
.setEnd(pos.x(), pos.y(), pos.z())
.setBlock(placerFunction);
result = result == null ? line : new SDFUnion().setSourceA(result).setSourceB(line);
start = pos;
}
@ -100,7 +103,10 @@ public class SplineHelper {
for (int i = 1; i < count; i++) {
Vector3f pos = spline.get(i);
float delta = (float) (i - 1) / max;
SDF line = new SDFLine().setRadius(radiusFunction.apply(delta)).setStart(start.x(), start.y(), start.z()).setEnd(pos.x(), pos.y(), pos.z()).setBlock(placerFunction);
SDF line = new SDFLine().setRadius(radiusFunction.apply(delta))
.setStart(start.x(), start.y(), start.z())
.setEnd(pos.x(), pos.y(), pos.z())
.setBlock(placerFunction);
result = result == null ? line : new SDFUnion().setSourceA(result).setSourceB(line);
start = pos;
}

View file

@ -87,7 +87,12 @@ public class StructureHelper {
}
public static BlockPos offsetPos(BlockPos pos, StructureTemplate structure, Rotation rotation, Mirror mirror) {
Vec3 offset = StructureTemplate.transform(Vec3.atCenterOf(structure.getSize()), mirror, rotation, BlockPos.ZERO);
Vec3 offset = StructureTemplate.transform(
Vec3.atCenterOf(structure.getSize()),
mirror,
rotation,
BlockPos.ZERO
);
return pos.offset(-offset.x * 0.5, 0, -offset.z * 0.5);
}
@ -97,7 +102,9 @@ public class StructureHelper {
public static void placeCenteredBottom(WorldGenLevel world, BlockPos pos, StructureTemplate structure, Rotation rotation, Mirror mirror, BoundingBox bounds, Random random) {
BlockPos offset = offsetPos(pos, structure, rotation, mirror);
StructurePlaceSettings placementData = new StructurePlaceSettings().setRotation(rotation).setMirror(mirror).setBoundingBox(bounds);
StructurePlaceSettings placementData = new StructurePlaceSettings().setRotation(rotation)
.setMirror(mirror)
.setBoundingBox(bounds);
structure.placeInWorld(world, offset, offset, placementData, random, 4);
}
@ -140,7 +147,11 @@ public class StructureHelper {
mut.setY(y);
BlockState state = world.getBlockState(mut);
boolean ignore = ignore(state, world, mut);
if (canDestruct && BlocksHelper.isInvulnerable(state, world, mut) && random.nextInt(8) == 0 && world.isEmptyBlock(mut.below(2))) {
if (canDestruct && BlocksHelper.isInvulnerable(
state,
world,
mut
) && random.nextInt(8) == 0 && world.isEmptyBlock(mut.below(2))) {
int r = MHelper.randRange(1, 4, random);
int cx = mut.getX();
int cy = mut.getY();
@ -163,7 +174,11 @@ public class StructureHelper {
int dz = pz - cz;
dz *= dz;
mut.setZ(pz);
if (dx + dy + dz <= r && BlocksHelper.isInvulnerable(world.getBlockState(mut), world, mut)) {
if (dx + dy + dz <= r && BlocksHelper.isInvulnerable(
world.getBlockState(mut),
world,
mut
)) {
BlocksHelper.setWithoutUpdate(world, mut, Blocks.AIR);
}
}
@ -181,7 +196,8 @@ public class StructureHelper {
if (!state.isAir() && random.nextBoolean()) {
MHelper.shuffle(DIR, random);
for (Direction dir : DIR) {
if (world.isEmptyBlock(mut.relative(dir)) && world.isEmptyBlock(mut.below().relative(dir))) {
if (world.isEmptyBlock(mut.relative(dir)) && world.isEmptyBlock(mut.below()
.relative(dir))) {
BlocksHelper.setWithoutUpdate(world, mut, Blocks.AIR);
mut.move(dir).move(Direction.DOWN);
for (int py = mut.getY(); y >= bounds.minY() - 10; y--) {
@ -196,7 +212,11 @@ public class StructureHelper {
}
break;
}
else if (random.nextInt(8) == 0 && !BlocksHelper.isInvulnerable(world.getBlockState(mut.above()), world, mut)) {
else if (random.nextInt(8) == 0 && !BlocksHelper.isInvulnerable(
world.getBlockState(mut.above()),
world,
mut
)) {
BlocksHelper.setWithoutUpdate(world, mut, Blocks.AIR);
}
}
@ -344,7 +364,12 @@ public class StructureHelper {
}
private static boolean ignore(BlockState state, WorldGenLevel world, BlockPos pos) {
return state.getMaterial().isReplaceable() || !state.getFluidState().isEmpty() || state.is(TagAPI.END_GROUND) || state.is(BlockTags.LOGS) || state.is(BlockTags.LEAVES) || state.getMaterial().equals(Material.PLANT) || state.getMaterial().equals(Material.LEAVES) || BlocksHelper.isInvulnerable(state, world, pos);
return state.getMaterial().isReplaceable() || !state.getFluidState()
.isEmpty() || state.is(TagAPI.END_GROUND) || state.is(
BlockTags.LOGS) || state.is(BlockTags.LEAVES) || state.getMaterial()
.equals(Material.PLANT) || state.getMaterial()
.equals(Material.LEAVES) || BlocksHelper
.isInvulnerable(state, world, pos);
}
public static void cover(WorldGenLevel world, BoundingBox bounds, Random random) {
@ -357,7 +382,9 @@ public class StructureHelper {
for (int y = bounds.maxY(); y >= bounds.minY(); y--) {
mut.setY(y);
BlockState state = world.getBlockState(mut);
if (state.is(TagAPI.END_GROUND) && !world.getBlockState(mut.above()).getMaterial().isSolidBlocking()) {
if (state.is(TagAPI.END_GROUND) && !world.getBlockState(mut.above())
.getMaterial()
.isSolidBlocking()) {
BlocksHelper.setWithoutUpdate(world, mut, top);
}
}

View file

@ -142,7 +142,11 @@ public class BCLBiome {
list.add(new StructureInfo(structure, offsetY, terrainMerge));
});
if (!list.isEmpty()) {
structuresFeature = BCLFeature.makeChansedFeature(new ResourceLocation(ns, nm + "_structures"), new ListFeature(list), 10);
structuresFeature = BCLFeature.makeChansedFeature(
new ResourceLocation(ns, nm + "_structures"),
new ListFeature(list),
10
);
}
}
}

View file

@ -140,12 +140,19 @@ public class BCLBiomeDef {
}
public BCLBiomeDef setSurface(Block block) {
setSurface(SurfaceBuilder.DEFAULT.configured(new SurfaceBuilderBaseConfiguration(block.defaultBlockState(), Blocks.END_STONE.defaultBlockState(), Blocks.END_STONE.defaultBlockState())));
setSurface(SurfaceBuilder.DEFAULT.configured(new SurfaceBuilderBaseConfiguration(
block.defaultBlockState(),
Blocks.END_STONE.defaultBlockState(),
Blocks.END_STONE.defaultBlockState()
)));
return this;
}
public BCLBiomeDef setSurface(Block block1, Block block2) {
setSurface(DoubleBlockSurfaceBuilder.register("bclib_" + id.getPath() + "_surface").setBlock1(block1).setBlock2(block2).configured());
setSurface(DoubleBlockSurfaceBuilder.register("bclib_" + id.getPath() + "_surface")
.setBlock1(block1)
.setBlock2(block2)
.configured());
return this;
}
@ -299,7 +306,10 @@ public class BCLBiomeDef {
Builder effects = new Builder();
mobs.forEach((spawn) -> {
spawnSettings.addSpawn(spawn.type.getCategory(), new MobSpawnSettings.SpawnerData(spawn.type, spawn.weight, spawn.minGroupSize, spawn.maxGroupSize));
spawnSettings.addSpawn(
spawn.type.getCategory(),
new MobSpawnSettings.SpawnerData(spawn.type, spawn.weight, spawn.minGroupSize, spawn.maxGroupSize)
);
});
spawns.forEach((entry) -> {
@ -311,14 +321,28 @@ public class BCLBiomeDef {
features.forEach((info) -> generationSettings.addFeature(info.featureStep, info.feature));
carvers.forEach((info) -> generationSettings.addCarver(info.carverStep, info.carver));
effects.skyColor(0).waterColor(waterColor).waterFogColor(waterFogColor).fogColor(fogColor).foliageColorOverride(foliageColor).grassColorOverride(grassColor);
effects.skyColor(0)
.waterColor(waterColor)
.waterFogColor(waterFogColor)
.fogColor(fogColor)
.foliageColorOverride(foliageColor)
.grassColorOverride(grassColor);
if (loop != null) effects.ambientLoopSound(loop);
if (mood != null) effects.ambientMoodSound(mood);
if (additions != null) effects.ambientAdditionsSound(additions);
if (particleConfig != null) effects.ambientParticle(particleConfig);
effects.backgroundMusic(music != null ? new Music(music, 600, 2400, true) : Musics.END);
return new Biome.BiomeBuilder().precipitation(precipitation).biomeCategory(category).depth(depth).scale(0.2F).temperature(temperature).downfall(downfall).specialEffects(effects.build()).mobSpawnSettings(spawnSettings.build()).generationSettings(generationSettings.build()).build();
return new Biome.BiomeBuilder().precipitation(precipitation)
.biomeCategory(category)
.depth(depth)
.scale(0.2F)
.temperature(temperature)
.downfall(downfall)
.specialEffects(effects.build())
.mobSpawnSettings(spawnSettings.build())
.generationSettings(generationSettings.build())
.build();
}
private static final class SpawnInfo {

View file

@ -39,39 +39,65 @@ public class BCLFeature {
}
public static BCLFeature makeVegetationFeature(ResourceLocation id, Feature<NoneFeatureConfiguration> feature, int density) {
ConfiguredFeature<?, ?> configured = feature.configured(FeatureConfiguration.NONE).decorated(BCLDecorators.HEIGHTMAP_SQUARE).countRandom(density);
ConfiguredFeature<?, ?> configured = feature.configured(FeatureConfiguration.NONE)
.decorated(BCLDecorators.HEIGHTMAP_SQUARE)
.countRandom(density);
return new BCLFeature(id, feature, GenerationStep.Decoration.VEGETAL_DECORATION, configured);
}
public static BCLFeature makeRawGenFeature(ResourceLocation id, Feature<NoneFeatureConfiguration> feature, int chance) {
ConfiguredFeature<?, ?> configured = feature.configured(FeatureConfiguration.NONE).decorated(FeatureDecorator.CHANCE.configured(new ChanceDecoratorConfiguration(chance)));
ConfiguredFeature<?, ?> configured = feature.configured(FeatureConfiguration.NONE)
.decorated(FeatureDecorator.CHANCE.configured(new ChanceDecoratorConfiguration(
chance)));
return new BCLFeature(id, feature, GenerationStep.Decoration.RAW_GENERATION, configured);
}
public static BCLFeature makeLakeFeature(ResourceLocation id, Feature<NoneFeatureConfiguration> feature, int chance) {
ConfiguredFeature<?, ?> configured = feature.configured(FeatureConfiguration.NONE).decorated(FeatureDecorator.LAVA_LAKE.configured(new ChanceDecoratorConfiguration(chance)));
ConfiguredFeature<?, ?> configured = feature.configured(FeatureConfiguration.NONE)
.decorated(FeatureDecorator.LAVA_LAKE.configured(new ChanceDecoratorConfiguration(
chance)));
return new BCLFeature(id, feature, GenerationStep.Decoration.LAKES, configured);
}
public static BCLFeature makeOreFeature(ResourceLocation id, Block blockOre, int veins, int veinSize, int offset, int minY, int maxY) {
OreConfiguration featureConfig = new OreConfiguration(new BlockMatchTest(Blocks.END_STONE), blockOre.defaultBlockState(), veinSize);
OreConfiguration featureConfig = new OreConfiguration(
new BlockMatchTest(Blocks.END_STONE),
blockOre.defaultBlockState(),
veinSize
);
OreConfiguration config = new OreConfiguration(ANY_TERRAIN, blockOre.defaultBlockState(), 33);
ConfiguredFeature<?, ?> oreFeature = Feature.ORE.configured(featureConfig).rangeUniform(VerticalAnchor.absolute(minY), VerticalAnchor.absolute(maxY)).squared().count(veins);
return new BCLFeature(Feature.ORE, Registry.register(BuiltinRegistries.CONFIGURED_FEATURE, id, oreFeature), GenerationStep.Decoration.UNDERGROUND_ORES);
ConfiguredFeature<?, ?> oreFeature = Feature.ORE.configured(featureConfig)
.rangeUniform(
VerticalAnchor.absolute(minY),
VerticalAnchor.absolute(maxY)
)
.squared()
.count(veins);
return new BCLFeature(
Feature.ORE,
Registry.register(BuiltinRegistries.CONFIGURED_FEATURE, id, oreFeature),
GenerationStep.Decoration.UNDERGROUND_ORES
);
}
public static BCLFeature makeChunkFeature(ResourceLocation id, Feature<NoneFeatureConfiguration> feature) {
ConfiguredFeature<?, ?> configured = feature.configured(FeatureConfiguration.NONE).decorated(FeatureDecorator.COUNT.configured(new CountConfiguration(1)));
ConfiguredFeature<?, ?> configured = feature.configured(FeatureConfiguration.NONE)
.decorated(FeatureDecorator.COUNT.configured(new CountConfiguration(
1)));
return new BCLFeature(id, feature, GenerationStep.Decoration.LOCAL_MODIFICATIONS, configured);
}
public static BCLFeature makeChansedFeature(ResourceLocation id, Feature<NoneFeatureConfiguration> feature, int chance) {
ConfiguredFeature<?, ?> configured = feature.configured(FeatureConfiguration.NONE).decorated(FeatureDecorator.CHANCE.configured(new ChanceDecoratorConfiguration(chance)));
ConfiguredFeature<?, ?> configured = feature.configured(FeatureConfiguration.NONE)
.decorated(FeatureDecorator.CHANCE.configured(new ChanceDecoratorConfiguration(
chance)));
return new BCLFeature(id, feature, GenerationStep.Decoration.SURFACE_STRUCTURES, configured);
}
public static BCLFeature makeCountRawFeature(ResourceLocation id, Feature<NoneFeatureConfiguration> feature, int chance) {
ConfiguredFeature<?, ?> configured = feature.configured(FeatureConfiguration.NONE).decorated(FeatureDecorator.COUNT.configured(new CountConfiguration(chance)));
ConfiguredFeature<?, ?> configured = feature.configured(FeatureConfiguration.NONE)
.decorated(FeatureDecorator.COUNT.configured(new CountConfiguration(
chance)));
return new BCLFeature(id, feature, GenerationStep.Decoration.RAW_GENERATION, configured);
}

View file

@ -93,11 +93,18 @@ public abstract class NBTStructureFeature extends DefaultFeature {
StructureTemplate structure = getStructure(world, center, random);
Rotation rotation = getRotation(world, center, random);
Mirror mirror = getMirror(world, center, random);
BlockPos offset = StructureTemplate.transform(new BlockPos(structure.getSize()), mirror, rotation, BlockPos.ZERO);
BlockPos offset = StructureTemplate.transform(
new BlockPos(structure.getSize()),
mirror,
rotation,
BlockPos.ZERO
);
center = center.offset(0, getYOffset(structure, world, center, random) + 0.5, 0);
BoundingBox bounds = makeBox(center);
StructurePlaceSettings placementData = new StructurePlaceSettings().setRotation(rotation).setMirror(mirror).setBoundingBox(bounds);
StructurePlaceSettings placementData = new StructurePlaceSettings().setRotation(rotation)
.setMirror(mirror)
.setBoundingBox(bounds);
addStructureData(placementData);
center = center.offset(-offset.getX() * 0.5, 0, -offset.getZ() * 0.5);
structure.placeInWorld(world, center, center, placementData, random, 4);
@ -135,7 +142,9 @@ public abstract class NBTStructureFeature extends DefaultFeature {
BlockState stateSt = world.getBlockState(mut);
if (!stateSt.is(TagAPI.GEN_TERRAIN)) {
if (merge == TerrainMerge.SURFACE) {
SurfaceBuilderConfiguration config = world.getBiome(mut).getGenerationSettings().getSurfaceBuilderConfig();
SurfaceBuilderConfiguration config = world.getBiome(mut)
.getGenerationSettings()
.getSurfaceBuilderConfig();
boolean isTop = mut.getY() == surfMax && state.getMaterial().isSolidBlocking();
BlockState top = isTop ? config.getTopMaterial() : config.getUnderMaterial();
BlocksHelper.setWithoutUpdate(world, mut, top);
@ -147,7 +156,9 @@ public abstract class NBTStructureFeature extends DefaultFeature {
else {
if (stateSt.is(TagAPI.END_GROUND) && state.getMaterial().isSolidBlocking()) {
if (merge == TerrainMerge.SURFACE) {
SurfaceBuilderConfiguration config = world.getBiome(mut).getGenerationSettings().getSurfaceBuilderConfig();
SurfaceBuilderConfiguration config = world.getBiome(mut)
.getGenerationSettings()
.getSurfaceBuilderConfig();
BlocksHelper.setWithoutUpdate(world, mut, config.getUnderMaterial());
}
else {

View file

@ -18,7 +18,11 @@ public class DestructionStructureProcessor extends StructureProcessor {
@Override
public StructureBlockInfo processBlock(LevelReader worldView, BlockPos pos, BlockPos blockPos, StructureBlockInfo structureBlockInfo, StructureBlockInfo structureBlockInfo2, StructurePlaceSettings structurePlacementData) {
if (!BlocksHelper.isInvulnerable(structureBlockInfo2.state, worldView, structureBlockInfo2.pos) && MHelper.RANDOM.nextInt(chance) == 0) {
if (!BlocksHelper.isInvulnerable(
structureBlockInfo2.state,
worldView,
structureBlockInfo2.pos
) && MHelper.RANDOM.nextInt(chance) == 0) {
return null;
}
return structureBlockInfo2;

View file

@ -14,7 +14,10 @@ public class TerrainStructureProcessor extends StructureProcessor {
public StructureBlockInfo processBlock(LevelReader worldView, BlockPos pos, BlockPos blockPos, StructureBlockInfo structureBlockInfo, StructureBlockInfo structureBlockInfo2, StructurePlaceSettings structurePlacementData) {
BlockPos bpos = structureBlockInfo2.pos;
if (structureBlockInfo2.state.is(Blocks.END_STONE) && worldView.isEmptyBlock(bpos.above())) {
BlockState top = worldView.getBiome(structureBlockInfo2.pos).getGenerationSettings().getSurfaceBuilderConfig().getTopMaterial();
BlockState top = worldView.getBiome(structureBlockInfo2.pos)
.getGenerationSettings()
.getSurfaceBuilderConfig()
.getTopMaterial();
return new StructureBlockInfo(bpos, top, structureBlockInfo2.nbt);
}
return structureBlockInfo2;

View file

@ -19,7 +19,10 @@ public class BCLStructureFeature {
public BCLStructureFeature(ResourceLocation id, StructureFeature<NoneFeatureConfiguration> structure, GenerationStep.Decoration step, int spacing, int separation) {
this.featureStep = step;
this.structure = FabricStructureBuilder.create(id, structure).step(step).defaultConfig(spacing, separation, RANDOM.nextInt(8192)).register();
this.structure = FabricStructureBuilder.create(id, structure)
.step(step)
.defaultConfig(spacing, separation, RANDOM.nextInt(8192))
.register();
this.featureConfigured = this.structure.configured(NoneFeatureConfiguration.NONE);
BuiltinRegistries.register(BuiltinRegistries.CONFIGURED_STRUCTURE_FEATURE, id, this.featureConfigured);
FlatChunkGeneratorConfigAccessor.getStructureToFeatures().put(this.structure, this.featureConfigured);

View file

@ -47,6 +47,20 @@ public class DoubleBlockSurfaceBuilder extends SurfaceBuilder<SurfaceBuilderBase
@Override
public void apply(Random random, ChunkAccess chunkAccess, Biome biome, int x, int z, int height, double noise, BlockState defaultBlock, BlockState defaultFluid, int l, int m, long seed, SurfaceBuilderBaseConfiguration surfaceBuilderConfiguration) {
noise = NOISE.eval(x * 0.1, z * 0.1) + MHelper.randRange(-0.4, 0.4, random);
SurfaceBuilder.DEFAULT.apply(random, chunkAccess, biome, x, z, height, noise, defaultBlock, defaultFluid, l, m, seed, noise > 0 ? config1 : config2);
SurfaceBuilder.DEFAULT.apply(
random,
chunkAccess,
biome,
x,
z,
height,
noise,
defaultBlock,
defaultFluid,
l,
m,
seed,
noise > 0 ? config1 : config2
);
}
}

Some files were not shown because too many files have changed in this diff Show more