Port to 1.18-pre2 without worldgen

This commit is contained in:
modmuss50 2021-11-16 22:38:31 +00:00
parent f5c3b85773
commit 4a2e81550f
38 changed files with 132 additions and 158 deletions

View file

@ -145,10 +145,10 @@ public class RenderUtil {
float l = (endColor >> 8 & 0xFF) / 255.0F;
float m = (endColor & 0xFF) / 255.0F;
bufferBuilder.vertex(matrices.peek().getModel(), right, top, zLevel).color(g, h, i, f).next();
bufferBuilder.vertex(matrices.peek().getModel(), left, top, zLevel).color(g, h, i, f).next();
bufferBuilder.vertex(matrices.peek().getModel(), left, bottom, zLevel).color(k, l, m, j).next();
bufferBuilder.vertex(matrices.peek().getModel(), right, bottom, zLevel).color(k, l, m, j).next();
bufferBuilder.vertex(matrices.peek().getPositionMatrix(), right, top, zLevel).color(g, h, i, f).next();
bufferBuilder.vertex(matrices.peek().getPositionMatrix(), left, top, zLevel).color(g, h, i, f).next();
bufferBuilder.vertex(matrices.peek().getPositionMatrix(), left, bottom, zLevel).color(k, l, m, j).next();
bufferBuilder.vertex(matrices.peek().getPositionMatrix(), right, bottom, zLevel).color(k, l, m, j).next();
tessellator.draw();
RenderSystem.disableBlend();

View file

@ -50,7 +50,7 @@ public abstract class BaseBlockEntityProvider extends Block implements BlockEnti
return Optional.empty();
}
ItemStack newStack = stack.copy();
NbtCompound blockEntityData = blockEntity.writeNbt(new NbtCompound());
NbtCompound blockEntityData = blockEntity.createNbt();
stripLocationData(blockEntityData);
if (!newStack.hasNbt()) {
newStack.setNbt(new NbtCompound());

View file

@ -126,12 +126,13 @@ public class MachineBaseBlockEntity extends BlockEntity implements BlockEntityTi
@Nullable
@Override
public BlockEntityUpdateS2CPacket toUpdatePacket() {
return new BlockEntityUpdateS2CPacket(getPos(), 0, toInitialChunkDataNbt());
return BlockEntityUpdateS2CPacket.create(this);
}
@Override
public NbtCompound toInitialChunkDataNbt() {
NbtCompound compound = super.writeNbt(new NbtCompound());
NbtCompound compound = new NbtCompound();
super.writeNbt(compound);
writeNbt(compound);
return compound;
}
@ -257,7 +258,7 @@ public class MachineBaseBlockEntity extends BlockEntity implements BlockEntityTi
}
@Override
public NbtCompound writeNbt(NbtCompound tagCompound) {
public void writeNbt(NbtCompound tagCompound) {
super.writeNbt(tagCompound);
if (getOptionalInventory().isPresent()) {
getOptionalInventory().get().write(tagCompound);
@ -273,7 +274,6 @@ public class MachineBaseBlockEntity extends BlockEntity implements BlockEntityTi
}
upgradeInventory.write(tagCompound, "Upgrades");
tagCompound.put("redstoneConfig", redstoneConfiguration.write());
return tagCompound;
}
private boolean isItemValidForSlot(int index, ItemStack stack) {

View file

@ -125,7 +125,7 @@ public abstract class MultiblockBlockEntityBase extends IMultiblockPart implemen
}
@Override
public NbtCompound writeNbt(NbtCompound data) {
public void writeNbt(NbtCompound data) {
super.writeNbt(data);
if (isMultiblockSaveDelegate() && isConnected()) {
@ -133,7 +133,6 @@ public abstract class MultiblockBlockEntityBase extends IMultiblockPart implemen
this.controller.write(multiblockData);
data.put("multiblockData", multiblockData);
}
return data;
}
@Override
@ -175,7 +174,7 @@ public abstract class MultiblockBlockEntityBase extends IMultiblockPart implemen
public BlockEntityUpdateS2CPacket toUpdatePacket() {
NbtCompound packetData = new NbtCompound();
encodeDescriptionPacket(packetData);
return new BlockEntityUpdateS2CPacket(getPos(), 0, packetData);
return BlockEntityUpdateS2CPacket.create(this);
}
// /// Things to override in most implementations (IMultiblockPart)

View file

@ -556,7 +556,7 @@ public abstract class MultiblockControllerBase {
// Ensure that we save our data, even if the our save
// delegate is in has no TEs.
WorldChunk chunkToSave = this.worldObj.getChunk(x, z);
chunkToSave.markDirty();
chunkToSave.needsSaving();
}
}
}

View file

@ -39,7 +39,7 @@ import java.util.List;
public class ClientBoundPackets {
public static IdentifiedPacket createCustomDescriptionPacket(BlockEntity blockEntity) {
return createCustomDescriptionPacket(blockEntity.getPos(), blockEntity.writeNbt(new NbtCompound()));
return createCustomDescriptionPacket(blockEntity.getPos(), blockEntity.createNbt());
}
public static IdentifiedPacket createCustomDescriptionPacket(BlockPos blockPos, NbtCompound nbt) {

View file

@ -352,12 +352,11 @@ public abstract class PowerAcceptorBlockEntity extends MachineBaseBlockEntity im
}
@Override
public NbtCompound writeNbt(NbtCompound tag) {
public void writeNbt(NbtCompound tag) {
super.writeNbt(tag);
NbtCompound data = new NbtCompound();
data.putLong("energy", getStored());
tag.put("PowerAcceptor", data);
return tag;
}
@Override

View file

@ -79,8 +79,8 @@ allprojects {
apply plugin: "fabric-loom"
apply plugin: "maven-publish"
sourceCompatibility = JavaVersion.VERSION_16
targetCompatibility = JavaVersion.VERSION_16
sourceCompatibility = JavaVersion.VERSION_17
targetCompatibility = JavaVersion.VERSION_17
// Shared deps between TR and RC
dependencies {
@ -91,7 +91,9 @@ allprojects {
//Fabric api
modImplementation "net.fabricmc.fabric-api:fabric-api:${project.fapi_version}"
include(modApi("teamreborn:energy:${project.energy_version}"))
include(modApi("teamreborn:energy:${project.energy_version}")) {
transitive = false
}
}
processResources {
@ -104,7 +106,7 @@ allprojects {
tasks.withType(JavaCompile).configureEach {
it.options.encoding = "UTF-8"
it.options.release = 16
it.options.release = 17
}
java {
@ -149,7 +151,7 @@ dependencies {
api project(path: ":RebornCore", configuration: "namedElements")
include project(":RebornCore")
optionalDependency "me.shedaniel:RoughlyEnoughItems-fabric:${project.rei_version}"
disabledOptionalDependency "me.shedaniel:RoughlyEnoughItems-fabric:${project.rei_version}"
disabledOptionalDependency "com.github.emilyploszaj:trinkets:${project.trinkets_version}"
disabledOptionalDependency "com.github.dexman545:autoswitch-api:${project.autoswitch_version}"
disabledOptionalDependency "net.oskarstrom:DashLoader:${project.dashloader_version}"

View file

@ -6,10 +6,10 @@ org.gradle.jvmargs=-Xmx2G
# Fabric Properties
# check these on https://modmuss50.me/fabric.html
minecraft_version=1.17.1
yarn_version=1.17.1+build.63:v2
minecraft_version=1.18-pre2
yarn_version=1.18-pre2+build.1:v2
loader_version=0.12.5
fapi_version=0.42.1+1.17
fapi_version=0.42.4+1.18
# Dependencies
energy_version=2.0.0-beta1

View file

@ -32,7 +32,7 @@ import techreborn.test.TRGameTest
import techreborn.test.TRTestContext
class GrinderTest extends TRGameTest {
@GameTest(structureName = EMPTY_STRUCTURE, tickLimit = 150)
@GameTest(structureName = "fabric-gametest-api-v1:empty", tickLimit = 150)
def testGrind2OCs(TRTestContext context) {
/**
* Test that grinder with 2 overclocker upgrades grinds coal into coal dust in 116 ticks

View file

@ -85,7 +85,7 @@ public class TechReborn implements ModInitializer {
RecipeCrafter.soundHanlder = new ModSounds.SoundHandler();
}
ModLoot.init();
WorldGenerator.initWorldGen();
// WorldGenerator.initWorldGen();
FluidGeneratorRecipes.init();
//Force loads the block entities at the right time
//noinspection ResultOfMethodCallIgnored

View file

@ -199,14 +199,14 @@ public class CableBlockEntity extends BlockEntity
// BlockEntity
@Override
public NbtCompound toInitialChunkDataNbt() {
return writeNbt(new NbtCompound());
return createNbt();
}
@Override
public BlockEntityUpdateS2CPacket toUpdatePacket() {
NbtCompound nbtTag = new NbtCompound();
writeNbt(nbtTag);
return new BlockEntityUpdateS2CPacket(getPos(), 1, nbtTag);
return BlockEntityUpdateS2CPacket.create(this);
}
@Override
@ -223,13 +223,12 @@ public class CableBlockEntity extends BlockEntity
}
@Override
public NbtCompound writeNbt(NbtCompound compound) {
public void writeNbt(NbtCompound compound) {
super.writeNbt(compound);
compound.putLong("energy", energyContainer.amount);
if (cover != null) {
compound.put("cover", NbtHelper.fromBlockState(cover));
}
return compound;
}
public void neighborUpdate() {

View file

@ -75,7 +75,7 @@ class CableTickManager {
// Make sure we only gather and tick each cable once per tick.
if (current.lastTick == tickCounter) return false;
// Make sure we ignore cables in non-ticking chunks.
if (!(current.getWorld() instanceof ServerWorld sw) || !sw.method_37117(current.getPos())) return false;
if (!(current.getWorld() instanceof ServerWorld sw) || !sw.isChunkLoaded(current.getPos())) return false;
return true;
}

View file

@ -173,10 +173,9 @@ public abstract class BaseFluidGeneratorBlockEntity extends PowerAcceptorBlockEn
}
@Override
public NbtCompound writeNbt(NbtCompound tagCompound) {
public void writeNbt(NbtCompound tagCompound) {
super.writeNbt(tagCompound);
tank.write(tagCompound);
return tagCompound;
}
@Override

View file

@ -159,11 +159,10 @@ public class SolidFuelGeneratorBlockEntity extends PowerAcceptorBlockEntity impl
}
@Override
public NbtCompound writeNbt(NbtCompound tag) {
public void writeNbt(NbtCompound tag) {
super.writeNbt(tag);
tag.putInt("BurnTime", burnTime);
tag.putInt("TotalBurnTime", totalBurnTime);
return tag;
}
// MachineBaseBlockEntity

View file

@ -141,12 +141,11 @@ public abstract class AbstractIronMachineBlockEntity extends MachineBaseBlockEnt
}
@Override
public NbtCompound writeNbt(NbtCompound compoundTag) {
public void writeNbt(NbtCompound compoundTag) {
super.writeNbt(compoundTag);
compoundTag.putInt("BurnTime", burnTime);
compoundTag.putInt("TotalBurnTime", totalBurnTime);
compoundTag.putInt("Progress", progress);
return compoundTag;
}
@Override

View file

@ -149,10 +149,9 @@ public class IronFurnaceBlockEntity extends AbstractIronMachineBlockEntity imple
}
@Override
public NbtCompound writeNbt(NbtCompound compoundTag) {
public void writeNbt(NbtCompound compoundTag) {
super.writeNbt(compoundTag);
compoundTag.putFloat("Experience", experience);
return compoundTag;
}
// IContainerProvider

View file

@ -68,12 +68,11 @@ public class AlarmBlockEntity extends BlockEntity
// BlockEntity
@Override
public NbtCompound writeNbt(NbtCompound compound) {
public void writeNbt(NbtCompound compound) {
if (compound == null) {
compound = new NbtCompound();
}
compound.putInt("selectedSound", this.selectedSound);
return super.writeNbt(compound);
}
@Override

View file

@ -107,10 +107,9 @@ public class FluidReplicatorBlockEntity extends GenericMachineBlockEntity implem
}
@Override
public NbtCompound writeNbt(final NbtCompound tagCompound) {
public void writeNbt(final NbtCompound tagCompound) {
super.writeNbt(tagCompound);
tank.write(tagCompound);
return tagCompound;
}
private static IInventoryAccess<FluidReplicatorBlockEntity> getInventoryAccess() {

View file

@ -371,14 +371,13 @@ public class FusionControlComputerBlockEntity extends GenericMachineBlockEntity
}
@Override
public NbtCompound writeNbt(final NbtCompound tagCompound) {
public void writeNbt(final NbtCompound tagCompound) {
super.writeNbt(tagCompound);
tagCompound.putInt("craftingTickTime", this.craftingTickTime);
tagCompound.putInt("neededPower", this.neededPower);
tagCompound.putBoolean("hasStartedCrafting", this.hasStartedCrafting);
tagCompound.putBoolean("hasActiveRecipe", this.currentRecipe != null);
tagCompound.putInt("size", size);
return tagCompound;
}
//MachineBaseBlockEntity

View file

@ -101,10 +101,9 @@ public class IndustrialGrinderBlockEntity extends GenericMachineBlockEntity impl
}
@Override
public NbtCompound writeNbt(final NbtCompound tagCompound) {
public void writeNbt(final NbtCompound tagCompound) {
super.writeNbt(tagCompound);
tank.write(tagCompound);
return tagCompound;
}
// TileMachineBase

View file

@ -102,10 +102,9 @@ public class IndustrialSawmillBlockEntity extends GenericMachineBlockEntity impl
}
@Override
public NbtCompound writeNbt(final NbtCompound tagCompound) {
public void writeNbt(final NbtCompound tagCompound) {
super.writeNbt(tagCompound);
tank.write(tagCompound);
return tagCompound;
}
// TileMachineBase

View file

@ -407,9 +407,8 @@ public class AutoCraftingTableBlockEntity extends PowerAcceptorBlockEntity
}
@Override
public NbtCompound writeNbt(NbtCompound tag) {
public void writeNbt(NbtCompound tag) {
tag.putBoolean("locked", locked);
return super.writeNbt(tag);
}
@Override

View file

@ -141,11 +141,10 @@ public class PlayerDetectorBlockEntity extends PowerAcceptorBlockEntity implemen
}
@Override
public NbtCompound writeNbt(NbtCompound tag) {
public void writeNbt(NbtCompound tag) {
super.writeNbt(tag);
tag.putString("ownerID", ownerUdid);
tag.putInt("radius", radius);
return tag;
}
// MachineBaseBlockEntity

View file

@ -148,10 +148,8 @@ public class ResinBasinBlockEntity extends MachineBaseBlockEntity {
}
@Override
public NbtCompound writeNbt(NbtCompound tagCompound) {
public void writeNbt(NbtCompound tagCompound) {
super.writeNbt(tagCompound);
return tagCompound;
}
@Override

View file

@ -354,12 +354,11 @@ public class RollingMachineBlockEntity extends PowerAcceptorBlockEntity
}
@Override
public NbtCompound writeNbt(final NbtCompound tagCompound) {
public void writeNbt(final NbtCompound tagCompound) {
super.writeNbt(tagCompound);
tagCompound.putBoolean("isRunning", this.isRunning);
tagCompound.putInt("tickTime", this.tickTime);
tagCompound.putBoolean("locked", locked);
return tagCompound;
}
@Override

View file

@ -123,14 +123,13 @@ public class ChunkLoaderBlockEntity extends MachineBaseBlockEntity implements IT
}
@Override
public NbtCompound writeNbt(NbtCompound tagCompound) {
public void writeNbt(NbtCompound tagCompound) {
super.writeNbt(tagCompound);
tagCompound.putInt("radius", radius);
if (ownerUdid != null && !ownerUdid.isEmpty()){
tagCompound.putString("ownerUdid", ownerUdid);
}
inventory.write(tagCompound);
return tagCompound;
}
@Override

View file

@ -141,10 +141,9 @@ public class AdjustableSUBlockEntity extends EnergyStorageBlockEntity implements
}
@Override
public NbtCompound writeNbt(NbtCompound tagCompound) {
public void writeNbt(NbtCompound tagCompound) {
super.writeNbt(tagCompound);
tagCompound.putInt("output", OUTPUT);
return tagCompound;
}
@Override

View file

@ -129,13 +129,12 @@ public class InterdimensionalSUBlockEntity extends EnergyStorageBlockEntity impl
}
@Override
public NbtCompound writeNbt(NbtCompound nbttagcompound) {
public void writeNbt(NbtCompound nbttagcompound) {
super.writeNbt(nbttagcompound);
if (ownerUdid == null || StringUtils.isEmpty(ownerUdid)) {
return nbttagcompound;
return;
}
nbttagcompound.putString("ownerUdid", this.ownerUdid);
return nbttagcompound;
}
@Override

View file

@ -128,11 +128,10 @@ public class TankUnitBaseBlockEntity extends MachineBaseBlockEntity implements I
}
@Override
public NbtCompound writeNbt(final NbtCompound tagCompound) {
public void writeNbt(final NbtCompound tagCompound) {
super.writeNbt(tagCompound);
tagCompound.putString("unitType", this.type.name());
tank.write(tagCompound);
return tagCompound;
}
@Override

View file

@ -318,7 +318,7 @@ public class StorageUnitBaseBlockEntity extends MachineBaseBlockEntity implement
}
@Override
public NbtCompound writeNbt(NbtCompound tagCompound) {
public void writeNbt(NbtCompound tagCompound) {
super.writeNbt(tagCompound);
tagCompound.putString("unitType", this.type.name());
@ -342,7 +342,6 @@ public class StorageUnitBaseBlockEntity extends MachineBaseBlockEntity implement
}
inventory.write(tagCompound);
return tagCompound;
}
@Override

View file

@ -179,7 +179,7 @@ public class CableBlock extends BlockWithEntity implements Waterloggable {
public BlockState getStateForNeighborUpdate(BlockState ourState, Direction direction, BlockState otherState,
WorldAccess worldIn, BlockPos ourPos, BlockPos otherPos) {
if (ourState.get(WATERLOGGED)) {
worldIn.getFluidTickScheduler().schedule(ourPos, Fluids.WATER, Fluids.WATER.getTickRate(worldIn));
worldIn.createAndScheduleFluidTick(ourPos, Fluids.WATER, Fluids.WATER.getTickRate(worldIn));
}
return ourState;
}

View file

@ -89,12 +89,12 @@ public class StorageUnitRenderer implements BlockEntityRenderer<StorageUnitBaseB
// Render item count
String count = String.valueOf(storage.storedAmount);
xPosition = (float) (-textRenderer.getWidth(count) / 2);
textRenderer.draw(count, xPosition, -4f + 40, 0, false, matrices.peek().getModel(), vertexConsumers, false, 0, light);
textRenderer.draw(count, xPosition, -4f + 40, 0, false, matrices.peek().getPositionMatrix(), vertexConsumers, false, 0, light);
// Render name
String item = stack.getName().asTruncatedString(18);
xPosition = (float) (-textRenderer.getWidth(item) / 2);
textRenderer.draw(item, xPosition, -4f - 40, 0, false, matrices.peek().getModel(), vertexConsumers, false, 0, light);
textRenderer.draw(item, xPosition, -4f - 40, 0, false, matrices.peek().getPositionMatrix(), vertexConsumers, false, 0, light);
matrices.pop();
}

View file

@ -49,26 +49,27 @@ import java.util.function.Predicate;
public class DataDrivenFeature {
private static final Logger LOGGER = LogManager.getLogger();
private final Predicate<BiomeSelectionContext> biomeSelector;
private final ConfiguredFeature<?, ?> configuredFeature;
private final GenerationStep.Feature generationStep;
private final Identifier identifier;
private Predicate<BiomeSelectionContext> biomeSelector;
private ConfiguredFeature<?, ?> configuredFeature;
private GenerationStep.Feature generationStep;
private Identifier identifier;
public DataDrivenFeature(Identifier identifier, Predicate<BiomeSelectionContext> biomeSelector, ConfiguredFeature<?, ?> configuredFeature, GenerationStep.Feature generationStep) {
this.identifier = identifier;
this.biomeSelector = biomeSelector;
this.configuredFeature = configuredFeature;
this.generationStep = generationStep;
}
// public DataDrivenFeature(Identifier identifier, Predicate<BiomeSelectionContext> biomeSelector, ConfiguredFeature<?, ?> configuredFeature, GenerationStep.Feature generationStep) {
// this.identifier = identifier;
// this.biomeSelector = biomeSelector;
// this.configuredFeature = configuredFeature;
// this.generationStep = generationStep;
// }
@Deprecated
public DataDrivenFeature(Identifier identifier, Predicate<BiomeSelectionContext> biomeSelector, RuleTest ruleTest, BlockState blockState, int maxY, int veinSize, int veinCount) {
this(identifier, biomeSelector, Feature.ORE.configure(
new OreFeatureConfig(ruleTest, blockState, veinSize)
)
.uniformRange(YOffset.getBottom(), YOffset.fixed(maxY))
.spreadHorizontally()
.repeat(veinCount), GenerationStep.Feature.UNDERGROUND_ORES);
// this(identifier, biomeSelector, Feature.ORE.configure(
// new OreFeatureConfig(ruleTest, blockState, veinSize)
// ));
// TODO 1.18
// .uniformRange(YOffset.getBottom(), YOffset.fixed(maxY))
// .spreadHorizontally()
// .repeat(veinCount), GenerationStep.Feature.UNDERGROUND_ORES);
}
public static DataDrivenFeature deserialise(Identifier identifier, JsonObject jsonObject) {
@ -97,7 +98,8 @@ public class DataDrivenFeature {
throw new JsonParseException(s);
}).getFeature();
return new DataDrivenFeature(identifier, biomeSelector, configuredFeature, generationStep);
return null;
// return new DataDrivenFeature(identifier, biomeSelector, configuredFeature, generationStep);
}
public JsonObject serialise() {

View file

@ -34,19 +34,13 @@ import net.minecraft.structure.rule.RuleTest;
import net.minecraft.util.Identifier;
import net.minecraft.util.collection.DataPool;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.intprovider.ConstantIntProvider;
import net.minecraft.util.registry.Registry;
import net.minecraft.world.biome.Biome;
import net.minecraft.world.gen.GenerationStep;
import net.minecraft.world.gen.decorator.ChanceDecoratorConfig;
import net.minecraft.world.gen.feature.ConfiguredFeature;
import net.minecraft.world.gen.feature.OreFeatureConfig;
import net.minecraft.world.gen.feature.TreeFeatureConfig;
import net.minecraft.world.gen.feature.size.TwoLayersFeatureSize;
import net.minecraft.world.gen.feature.OreConfiguredFeatures;
import net.minecraft.world.gen.stateprovider.BlockStateProvider;
import net.minecraft.world.gen.stateprovider.SimpleBlockStateProvider;
import net.minecraft.world.gen.stateprovider.WeightedBlockStateProvider;
import net.minecraft.world.gen.trunk.StraightTrunkPlacer;
import org.apache.logging.log4j.util.TriConsumer;
import techreborn.blocks.misc.BlockRubberLog;
import techreborn.init.TRContent;
@ -79,19 +73,21 @@ public class DefaultWorldGen {
BlockStateProvider logProvider = new WeightedBlockStateProvider(logPoolBuilder.build());
TreeFeatureConfig treeFeatureConfig = new TreeFeatureConfig.Builder(
logProvider,
new StraightTrunkPlacer(6, 3, 0),
new SimpleBlockStateProvider(TRContent.RUBBER_LEAVES.getDefaultState()),
new SimpleBlockStateProvider(TRContent.RUBBER_SAPLING.getDefaultState()),
new RubberTreeFeature.FoliagePlacer(ConstantIntProvider.create(2), ConstantIntProvider.create(0), 3, 3, TRContent.RUBBER_LEAVES.getDefaultState()),
new TwoLayersFeatureSize(1, 0, 1)
).build();
// TreeFeatureConfig treeFeatureConfig = new TreeFeatureConfig.Builder(
// logProvider,
// new StraightTrunkPlacer(6, 3, 0),
// BlockStateProvider.of(TRContent.RUBBER_LEAVES.getDefaultState()),
// BlockStateProvider.of(TRContent.RUBBER_SAPLING.getDefaultState()),
// new RubberTreeFeature.FoliagePlacer(ConstantIntProvider.create(2), ConstantIntProvider.create(0), 3, 3, TRContent.RUBBER_LEAVES.getDefaultState()),
// new TwoLayersFeatureSize(1, 0, 1)
// ).build();
return WorldGenerator.RUBBER_TREE_FEATURE.configure(treeFeatureConfig)
.decorate(WorldGenerator.RUBBER_TREE_DECORATOR
.configure(new ChanceDecoratorConfig(50)
));
return null; // TODO 1.18
// return WorldGenerator.RUBBER_TREE_FEATURE.configure(treeFeatureConfig)
// .decorate(WorldGenerator.RUBBER_TREE_DECORATOR
// .configure(new ChanceDecoratorConfig(50)
// ));
}
public static List<DataDrivenFeature> getDefaultFeatures() {
@ -99,31 +95,31 @@ public class DefaultWorldGen {
TriConsumer<Predicate<BiomeSelectionContext>, RuleTest, TRContent.Ores> addOre = (worldTargetType, ruleTest, ore) ->
features.add(ore.asNewOres(new Identifier("techreborn", Registry.BLOCK.getId(ore.block).getPath()), worldTargetType, ruleTest));
addOre.accept(BiomeSelectors.foundInTheNether(), OreFeatureConfig.Rules.BASE_STONE_NETHER, TRContent.Ores.CINNABAR);
addOre.accept(BiomeSelectors.foundInTheNether(), OreFeatureConfig.Rules.BASE_STONE_NETHER, TRContent.Ores.PYRITE);
addOre.accept(BiomeSelectors.foundInTheNether(), OreFeatureConfig.Rules.BASE_STONE_NETHER, TRContent.Ores.SPHALERITE);
addOre.accept(BiomeSelectors.foundInTheNether(), OreConfiguredFeatures.BASE_STONE_NETHER, TRContent.Ores.CINNABAR);
addOre.accept(BiomeSelectors.foundInTheNether(), OreConfiguredFeatures.BASE_STONE_NETHER, TRContent.Ores.PYRITE);
addOre.accept(BiomeSelectors.foundInTheNether(), OreConfiguredFeatures.BASE_STONE_NETHER, TRContent.Ores.SPHALERITE);
addOre.accept(BiomeSelectors.foundInTheEnd(), END_STONE, TRContent.Ores.PERIDOT);
addOre.accept(BiomeSelectors.foundInTheEnd(), END_STONE, TRContent.Ores.SHELDONITE);
addOre.accept(BiomeSelectors.foundInTheEnd(), END_STONE, TRContent.Ores.SODALITE);
addOre.accept(BiomeSelectors.foundInTheEnd(), END_STONE, TRContent.Ores.TUNGSTEN);
addOre.accept(BiomeSelectors.foundInOverworld(), OreFeatureConfig.Rules.BASE_STONE_OVERWORLD, TRContent.Ores.BAUXITE);
addOre.accept(BiomeSelectors.foundInOverworld(), OreFeatureConfig.Rules.BASE_STONE_OVERWORLD, TRContent.Ores.GALENA);
addOre.accept(BiomeSelectors.foundInOverworld(), OreFeatureConfig.Rules.BASE_STONE_OVERWORLD, TRContent.Ores.IRIDIUM);
addOre.accept(BiomeSelectors.foundInOverworld(), OreFeatureConfig.Rules.BASE_STONE_OVERWORLD, TRContent.Ores.LEAD);
addOre.accept(BiomeSelectors.foundInOverworld(), OreFeatureConfig.Rules.BASE_STONE_OVERWORLD, TRContent.Ores.RUBY);
addOre.accept(BiomeSelectors.foundInOverworld(), OreFeatureConfig.Rules.BASE_STONE_OVERWORLD, TRContent.Ores.SAPPHIRE);
addOre.accept(BiomeSelectors.foundInOverworld(), OreFeatureConfig.Rules.BASE_STONE_OVERWORLD, TRContent.Ores.SILVER);
addOre.accept(BiomeSelectors.foundInOverworld(), OreFeatureConfig.Rules.BASE_STONE_OVERWORLD, TRContent.Ores.TIN);
addOre.accept(BiomeSelectors.foundInOverworld(), OreConfiguredFeatures.BASE_STONE_OVERWORLD, TRContent.Ores.BAUXITE);
addOre.accept(BiomeSelectors.foundInOverworld(), OreConfiguredFeatures.BASE_STONE_OVERWORLD, TRContent.Ores.GALENA);
addOre.accept(BiomeSelectors.foundInOverworld(), OreConfiguredFeatures.BASE_STONE_OVERWORLD, TRContent.Ores.IRIDIUM);
addOre.accept(BiomeSelectors.foundInOverworld(), OreConfiguredFeatures.BASE_STONE_OVERWORLD, TRContent.Ores.LEAD);
addOre.accept(BiomeSelectors.foundInOverworld(), OreConfiguredFeatures.BASE_STONE_OVERWORLD, TRContent.Ores.RUBY);
addOre.accept(BiomeSelectors.foundInOverworld(), OreConfiguredFeatures.BASE_STONE_OVERWORLD, TRContent.Ores.SAPPHIRE);
addOre.accept(BiomeSelectors.foundInOverworld(), OreConfiguredFeatures.BASE_STONE_OVERWORLD, TRContent.Ores.SILVER);
addOre.accept(BiomeSelectors.foundInOverworld(), OreConfiguredFeatures.BASE_STONE_OVERWORLD, TRContent.Ores.TIN);
features.add(new DataDrivenFeature(
RubberSaplingGenerator.IDENTIFIER,
BiomeSelectors.categories(Biome.Category.FOREST, Biome.Category.TAIGA, Biome.Category.SWAMP),
getRubberTree(),
GenerationStep.Feature.VEGETAL_DECORATION
));
//
// features.add(new DataDrivenFeature(
// RubberSaplingGenerator.IDENTIFIER,
// BiomeSelectors.categories(Biome.Category.FOREST, Biome.Category.TAIGA, Biome.Category.SWAMP),
// getRubberTree(),
// GenerationStep.Feature.VEGETAL_DECORATION
// ));
return features;
}

View file

@ -27,24 +27,21 @@ package techreborn.world;
import net.minecraft.block.sapling.SaplingGenerator;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.BuiltinRegistries;
import net.minecraft.util.registry.MutableRegistry;
import net.minecraft.world.gen.feature.ConfiguredFeature;
import net.minecraft.world.gen.feature.DecoratedFeatureConfig;
import net.minecraft.world.gen.feature.TreeFeatureConfig;
import org.jetbrains.annotations.Nullable;
import java.util.Random;
import static techreborn.TechReborn.LOGGER;
public class RubberSaplingGenerator extends SaplingGenerator {
public static final Identifier IDENTIFIER = new Identifier("techreborn", "techreborn/features/rubber_tree.json");
@Nullable
@Override
protected ConfiguredFeature<TreeFeatureConfig, ?> getTreeFeature(Random random, boolean bl) {
DecoratedFeatureConfig decoratedFeatureConfig = (DecoratedFeatureConfig) BuiltinRegistries.CONFIGURED_FEATURE.get(IDENTIFIER).getConfig();
//noinspection unchecked
return (ConfiguredFeature<TreeFeatureConfig, ?>) decoratedFeatureConfig.feature.get();
// DecoratedFeatureConfig decoratedFeatureConfig = (DecoratedFeatureConfig) BuiltinRegistries.CONFIGURED_FEATURE.get(IDENTIFIER).getConfig();
// //noinspection unchecked
// return (ConfiguredFeature<TreeFeatureConfig, ?>) decoratedFeatureConfig.feature.get();
return null; // TODO 1.18
}
}

View file

@ -24,11 +24,8 @@
package techreborn.world;
import com.mojang.serialization.Codec;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.Heightmap;
import net.minecraft.world.gen.decorator.ChanceDecoratorConfig;
import net.minecraft.world.gen.decorator.Decorator;
import net.minecraft.world.gen.decorator.DecoratorContext;
import java.util.Random;
@ -36,25 +33,27 @@ import java.util.stream.IntStream;
import java.util.stream.Stream;
// Big thanks to SuperCoder7979 for this
public class RubberTreeDecorator extends Decorator<ChanceDecoratorConfig> {
public class RubberTreeDecorator { // extends Decorator<ChanceDecoratorConfig> {
public RubberTreeDecorator(Codec<ChanceDecoratorConfig> codec) {
super(codec);
}
// TODO 1.18
@Override
public Stream<BlockPos> getPositions(DecoratorContext context, Random random, ChanceDecoratorConfig config, BlockPos pos) {
// Generate tree clusters randomly
if (random.nextInt(config.chance) == 0) {
// Generate 4 - 8 trees
int treeCount = 4 + random.nextInt(5);
return IntStream.range(0, treeCount).mapToObj((i) -> {
int x = random.nextInt(16) + pos.getX();
int z = random.nextInt(16) + pos.getZ();
int y = context.getTopY(Heightmap.Type.MOTION_BLOCKING, x, z);
return new BlockPos(x, y, z);
});
}
return Stream.empty();
}
// public RubberTreeDecorator(Codec<ChanceDecoratorConfig> codec) {
// super(codec);
// }
//
// @Override
// public Stream<BlockPos> getPositions(DecoratorContext context, Random random, ChanceDecoratorConfig config, BlockPos pos) {
// // Generate tree clusters randomly
// if (random.nextInt(config.chance) == 0) {
// // Generate 4 - 8 trees
// int treeCount = 4 + random.nextInt(5);
// return IntStream.range(0, treeCount).mapToObj((i) -> {
// int x = random.nextInt(16) + pos.getX();
// int z = random.nextInt(16) + pos.getZ();
// int y = context.getTopY(Heightmap.Type.MOTION_BLOCKING, x, z);
// return new BlockPos(x, y, z);
// });
// }
// return Stream.empty();
// }
}

View file

@ -30,7 +30,6 @@ import net.fabricmc.fabric.api.biome.v1.ModificationPhase;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.BuiltinRegistries;
import net.minecraft.util.registry.Registry;
import net.minecraft.world.gen.decorator.ChanceDecoratorConfig;
import net.minecraft.world.gen.feature.Feature;
import net.minecraft.world.gen.feature.TreeFeatureConfig;
import net.minecraft.world.gen.foliage.FoliagePlacerType;
@ -38,6 +37,7 @@ import reborncore.mixin.common.AccessorFoliagePlacerType;
import java.util.List;
// TODO 1.18
public class WorldGenerator {
public static Feature<TreeFeatureConfig> RUBBER_TREE_FEATURE;
public static RubberTreeDecorator RUBBER_TREE_DECORATOR;
@ -57,7 +57,7 @@ public class WorldGenerator {
(biomeSelectionContext, biomeModificationContext) -> {
for (DataDrivenFeature feature : features) {
if (feature.getBiomeSelector().test(biomeSelectionContext)) {
biomeModificationContext.getGenerationSettings().addFeature(feature.getGenerationStep(), feature.getRegistryKey());
// biomeModificationContext.getGenerationSettings().addFeature(feature.getGenerationStep(), feature.getRegistryKey());
}
}
});
@ -65,7 +65,7 @@ public class WorldGenerator {
private static void registerTreeDecorators() {
RUBBER_TREE_FEATURE = Registry.register(Registry.FEATURE, new Identifier("techreborn:rubber_tree"), new RubberTreeFeature(TreeFeatureConfig.CODEC));
RUBBER_TREE_DECORATOR = Registry.register(Registry.DECORATOR, new Identifier("techreborn:rubber_tree"), new RubberTreeDecorator(ChanceDecoratorConfig.CODEC));
// RUBBER_TREE_DECORATOR = Registry.register(Registry.DECORATOR, new Identifier("techreborn:rubber_tree"), new RubberTreeDecorator(ChanceDecoratorConfig.CODEC));
RUBBER_TREE_FOLIAGE_PLACER_TYPE = AccessorFoliagePlacerType.register("techreborn:rubber_tree", RubberTreeFeature.FoliagePlacer.CODEC);
}
}