Olive Planks

This commit is contained in:
Halbear
2026-08-03 20:42:54 +01:00
parent 88ece5adf5
commit 5675524d5d
12 changed files with 230 additions and 2 deletions
@@ -0,0 +1,140 @@
package net.halbear.aotg.custom.WorldGen.GenerationFeatures;
import com.mojang.serialization.MapCodec;
import com.mojang.serialization.codecs.RecordCodecBuilder;
import net.halbear.aotg.registries.ModTreeGen;
import net.minecraft.core.BlockPos;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.WorldGenLevel;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.levelgen.feature.configurations.TreeConfiguration;
import net.minecraft.world.level.levelgen.feature.foliageplacers.FoliagePlacer;
import net.minecraft.world.level.levelgen.feature.trunkplacers.TrunkPlacer;
import net.minecraft.world.level.levelgen.feature.trunkplacers.TrunkPlacerType;
import java.util.ArrayList;
import java.util.List;
import java.util.function.BiConsumer;
public class PineTreeTrunkPlacer extends TrunkPlacer {
public PineTreeTrunkPlacer(int baseHeight, int heightRandA, int heightRandB) {
super(baseHeight, heightRandA, heightRandB);
}
public static final MapCodec<PineTreeTrunkPlacer> CODEC = RecordCodecBuilder.mapCodec(instance ->
trunkPlacerParts(instance).apply(instance, PineTreeTrunkPlacer::new)
);
@Override
protected TrunkPlacerType<?> type() {
return ModTreeGen.TALL_TWISTY_TRUNK_PLACER.get();
}
@Override
public List<FoliagePlacer.FoliageAttachment> placeTrunk(WorldGenLevel worldGenLevel, BiConsumer<BlockPos, BlockState> biConsumer, RandomSource randomSource, int freeSpace, BlockPos blockPos, TreeConfiguration treeConfiguration) {
int TRUNK_WIDTH = 3;
List<FoliagePlacer.FoliageAttachment> leafNodes = new ArrayList<>();
int mainHeight = this.getTreeHeight(randomSource);
BlockPos currentPos = blockPos;
for (int i = 0; i < mainHeight; i++) {
TRUNK_WIDTH = (int)Math.max(3 * (1.0-((i*0.75)/(double)mainHeight)),1);
for (int xOffset = 0; xOffset < TRUNK_WIDTH; xOffset++) {
for (int zOffset = 0; zOffset < TRUNK_WIDTH; zOffset++) {
BlockPos thickLogPos = currentPos.offset(xOffset, 0, zOffset);
if(i < 2 && randomSource.nextFloat() < 0.40f){
generateRoots(worldGenLevel, biConsumer, randomSource, thickLogPos, treeConfiguration);
}
if ((randomSource.nextInt(10) < 9) || TRUNK_WIDTH < 3)
this.placeLog(worldGenLevel, biConsumer, randomSource, thickLogPos, treeConfiguration);
else if (randomSource.nextDouble() < 0.1)
leafNodes.add(new FoliagePlacer.FoliageAttachment(thickLogPos, randomSource.nextInt(2), false));
}
}
if (randomSource.nextFloat() < 0.6f && i > 1) {
currentPos = currentPos.offset(randomSource.nextInt(3) - 1, 0, randomSource.nextInt(3) - 1);
this.placeLog(worldGenLevel, biConsumer, randomSource, currentPos.below(), treeConfiguration);
}
if (i > 2 && randomSource.nextFloat() < 0.65) {
BlockPos branchStart = currentPos.offset(randomSource.nextInt(TRUNK_WIDTH), 0, randomSource.nextInt(TRUNK_WIDTH));
BlockPos branchEnd = generateBranch(worldGenLevel, biConsumer, randomSource, branchStart, treeConfiguration,i, leafNodes);
leafNodes.add(new FoliagePlacer.FoliageAttachment(branchEnd, randomSource.nextInt(2) + (Math.max((int)(i/(double)(mainHeight/1.25))*2,1)), false));
} else if(i > 2 && i == mainHeight - 1){
for(int l = 0; l < 2 + randomSource.nextInt(3); l++){
BlockPos branchStart = currentPos.offset(randomSource.nextInt(TRUNK_WIDTH), 0, randomSource.nextInt(TRUNK_WIDTH));
BlockPos branchEnd = generateBranch(worldGenLevel, biConsumer, randomSource, branchStart, treeConfiguration,i, leafNodes);
this.placeLog(worldGenLevel, biConsumer, randomSource, branchStart, treeConfiguration);
leafNodes.add(new FoliagePlacer.FoliageAttachment(branchEnd, randomSource.nextInt(2) + (Math.max((int)(i/(double)(mainHeight/1.25))*2,1)), false));
}
}
currentPos = currentPos.above();
}
for (int xOffset = 0; xOffset < TRUNK_WIDTH; xOffset++) {
for (int zOffset = 0; zOffset < TRUNK_WIDTH; zOffset++) {
leafNodes.add(new FoliagePlacer.FoliageAttachment(currentPos.offset(xOffset, 0, zOffset), 0, false));
}
}
return leafNodes;
}
private BlockPos generateRoots(WorldGenLevel level, BiConsumer<BlockPos, BlockState> blockSetter,
RandomSource random, BlockPos branchStart, TreeConfiguration config) {
int dirX = random.nextBoolean() ? 1 : -1;
int dirZ = random.nextBoolean() ? 1 : -1;
int branchLength = 2 + random.nextInt(6);
BlockPos bPos = branchStart;
for (int b = 0; b < branchLength; b++) {
int stepX = random.nextFloat() < 0.7f ? dirX : 0;
int stepZ = random.nextFloat() < 0.7f ? dirZ : 0;
int stepY = random.nextFloat() < 0.4f ? -1 : 0;
bPos = bPos.offset(stepX, stepY, stepZ);
this.placeLog(level, blockSetter, random, bPos, config);
}
return bPos;
}
private BlockPos generateBranch(WorldGenLevel level, BiConsumer<BlockPos, BlockState> blockSetter,
RandomSource random, BlockPos branchStart, TreeConfiguration config, int CurrentTreeHeight,List<FoliagePlacer.FoliageAttachment> leafNodes) {
int dirX = random.nextBoolean() ? 1 : -1;
int dirZ = random.nextBoolean() ? 1 : -1;
int branchLength = 3 + random.nextInt(Math.min(CurrentTreeHeight,12));
BlockPos bPos = branchStart;
for (int b = 0; b < branchLength; b++) {
int stepX = random.nextFloat() < 0.7f ? dirX : 0;
int stepZ = random.nextFloat() < 0.7f ? dirZ : 0;
int stepY = random.nextFloat() < 0.4f ? 1 : 0;
bPos = bPos.offset(stepX, stepY, stepZ);
if(stepY == 1) this.placeLog(level, blockSetter, random, bPos.below(), config);
this.placeLog(level, blockSetter, random, bPos, config);
if (random.nextDouble() < 0.25) {
leafNodes.add(new FoliagePlacer.FoliageAttachment(bPos, random.nextInt(2), false));
}
}
return bPos;
}
public static int checkPointPosition(double xp, double yp, double xc, double yc, double r) {
double dx = xp - xc;
double dy = yp - yc;
double squaredDistance = (dx * dx) + (dy * dy);
double squaredRadius = r * r * 1.25;
if (squaredDistance < squaredRadius) {
return -1;
} else if (squaredDistance == squaredRadius) {
return 0;
} else {
return 1;
}
}
}
@@ -54,7 +54,7 @@ public class ModBlocks {
));
public static final DeferredBlock<Block> OLIVE_LOG = RegisterBlock("olive_log",
properties -> new RotatedPillarBlock(properties.strength(0.5f)
properties -> new RotatedPillarBlock(properties.strength(0.35f)
.requiresCorrectToolForDrops()
.explosionResistance(1.0f)
.sound(SoundType.WOOD)
@@ -63,13 +63,20 @@ public class ModBlocks {
public static final DeferredBlock<Block> OLIVE_LEAVES = RegisterBlock("olive_leaves",
properties -> new RockCoveredGrassBlock(properties.strength(0.15f)
properties -> new Block(properties.strength(0.15f)
.requiresCorrectToolForDrops()
.explosionResistance(0.5f)
.sound(SoundType.GRASS)
.lightLevel(state -> 0)
.noOcclusion()
));
public static final DeferredBlock<Block> OLIVE_PLANKS = RegisterBlock("olive_planks",
properties -> new Block(properties.strength(0.35f)
.requiresCorrectToolForDrops()
.explosionResistance(1.0f)
.sound(SoundType.WOOD)
.lightLevel(state -> 0)
));
public static final DeferredBlock<Block> SHALE_BLOCK = RegisterBlock("shale_block",
properties -> new RockCoveredGrassBlock(properties.strength(1.5f)
@@ -27,6 +27,7 @@ public class ModItems {
public static final DeferredItem<BlockItem> OLIVE_LOG_ITEM = ITEMS.registerSimpleBlockItem("olive_log", OLIVE_LOG);
public static final DeferredItem<BlockItem> ALLOY_FURNACE_ITEM = ITEMS.registerSimpleBlockItem("alloy_furnace", ALLOY_FURNACE);
public static final DeferredItem<BlockItem> FORGE_WORKBENCH_ITEM = ITEMS.registerSimpleBlockItem("forge", FORGE_WORKBENCH);
public static final DeferredItem<BlockItem> OLIVE_PLANKS_ITEM = ITEMS.registerSimpleBlockItem("olive_planks", OLIVE_PLANKS);
public static final DeferredItem<Item> FLUID_INDICATOR_ITEM = RegisterItem("fluid_indicator_debug_item", properties -> new Item(properties
.fireResistant()
@@ -54,6 +54,7 @@ public class ModTabs {
output.accept(ELECTRUM_INGOT.get());
output.accept(HEPATIZON_INGOT.get());
output.accept(ORICHALCUM_INGOT.get());
output.accept(OLIVE_PLANKS_ITEM.get());
output.accept(HARDENED_SLAG.get());
output.accept(XIPHOS_SWORD.get());
}).build());
@@ -0,0 +1,6 @@
{
"model": {
"type": "minecraft:model",
"model": "ageofthegods:block/olive/olive_planks"
}
}
@@ -0,0 +1,9 @@
{
"variants": {
"": [
{
"model": "ageofthegods:block/olive/olive_planks", "weight": 3
}
]
}
}
@@ -7,14 +7,21 @@
"block.ageofthegods.shale_grass_block": "Grassy Shale",
"block.ageofthegods.olive_leaves": "Olive Leaves",
"block.ageofthegods.olive_log": "Olive Log",
"block.ageofthegods.olive_planks": "Olive Planks",
"block.ageofthegods.alloy_furnace": "Alloy Furnace Segment",
"block.ageofthegods.forge": "Forge",
"block.ageofthegods.silver_ore": "Silver Ore",
"block.ageofthegods.zinc_ore": "Zinc Ore",
"block.ageofthegods.tin_ore": "Tin Ore",
"gui.ageofthegods.alloy_furnace_gui.title": "Alloy Furnace",
"gui.ageofthegods.forge_workbench.title": "Forge",
"item.ageofthegods.xiphos": "Xiphos",
"item.ageofthegods.zinc_ingot": "Zinc Ingot",
"item.ageofthegods.raw_zinc": "Raw Zinc",
"item.ageofthegods.raw_tin": "Raw Tin",
"item.ageofthegods.raw_silver": "Raw Silver",
"item.ageofthegods.tin_ingot": "Tin Ingot",
"item.ageofthegods.silver_ingot": "Silver Ingot",
"item.ageofthegods.bronze_ingot": "Bronze Ingot",
@@ -0,0 +1,6 @@
{
"parent": "block/cube_all",
"textures": {
"all": "ageofthegods:block/olive/olive_planks"
}
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 385 B

@@ -0,0 +1,17 @@
{
"type": "minecraft:crafting_shaped",
"category": "equipment",
"pattern": [
" a ",
" a ",
" b "
],
"key": {
"a": "ageofthegods:bronze_ingot",
"c": "minecraft:stick"
},
"result": {
"id": "ageofthegods:xiphos",
"count": 1
}
}
@@ -0,0 +1,17 @@
{
"type": "minecraft:crafting_shaped",
"category": "equipment",
"pattern": [
"a ",
"a ",
"b "
],
"key": {
"a": "ageofthegods:bronze_ingot",
"c": "minecraft:stick"
},
"result": {
"id": "ageofthegods:xiphos",
"count": 1
}
}
@@ -0,0 +1,17 @@
{
"type": "minecraft:crafting_shaped",
"category": "equipment",
"pattern": [
" a",
" a",
" b"
],
"key": {
"a": "ageofthegods:bronze_ingot",
"c": "minecraft:stick"
},
"result": {
"id": "ageofthegods:xiphos",
"count": 1
}
}