This commit is contained in:
modmuss50 2020-05-21 23:00:12 +01:00
parent 436a66ddfa
commit 8c39008636
18 changed files with 115 additions and 122 deletions

View file

@ -10,10 +10,10 @@ buildscript {
}
}
dependencies {
classpath "net.fabricmc:fabric-loom:0.4.+"
classpath "net.fabricmc:fabric-loom:0.4-SNAPSHOT"
classpath "gradle.plugin.net.minecrell:licenser:0.2.1"
classpath 'de.undercouch:gradle-download-task:3.4.3'
classpath "com.wynprice.cursemaven:CurseMaven:2.1.1"
classpath "com.wynprice.cursemaven:CurseMaven:2.1.4"
}
}
@ -72,14 +72,14 @@ license {
group = 'TechReborn'
dependencies {
minecraft "com.mojang:minecraft:20w18a"
mappings "net.fabricmc:yarn:20w18a+build.14:v2"
modImplementation "net.fabricmc:fabric-loader:0.8.2+build.194"
minecraft "com.mojang:minecraft:20w21a"
mappings "net.fabricmc:yarn:20w21a+build.10:v2"
modImplementation "net.fabricmc:fabric-loader:0.8.4+build.198"
//Fabric api
modImplementation "net.fabricmc.fabric-api:fabric-api:0.10.2+build.337-1.16"
modImplementation "net.fabricmc.fabric-api:fabric-api:0.10.10+build.347-1.16"
optionalDependency ("me.shedaniel:RoughlyEnoughItems:4.3.1-unstable")
optionalDependency ("me.shedaniel:RoughlyEnoughItems:4.3.7-unstable")
disabledOptionalDependency ('io.github.cottonmc:LibCD:2.3.0+1.15.2')
disabledOptionalDependency ('com.github.emilyploszaj:trinkets:2.4.2')
@ -90,9 +90,9 @@ dependencies {
include rcVersion
compileOnly "com.google.code.findbugs:jsr305:3.0.2"
modCompileOnly ('curse.maven:towelette:2842017') {
transitive = false
}
// modCompileOnly ('curse.maven:towelette:2952524') {
// transitive = false
// }
modApi 'teamreborn:energy:0.1.0'
}

View file

@ -38,7 +38,6 @@ import net.minecraft.particle.ParticleTypes;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvents;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.AbstractProperty;
import net.minecraft.state.property.BooleanProperty;
import net.minecraft.state.property.Properties;
import net.minecraft.util.ActionResult;
@ -50,8 +49,8 @@ import net.minecraft.util.math.Direction;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.util.shape.VoxelShapes;
import net.minecraft.world.BlockView;
import net.minecraft.world.IWorld;
import net.minecraft.world.World;
import net.minecraft.world.WorldAccess;
import reborncore.api.ToolManager;
import reborncore.common.blocks.BlockWrenchEventHandler;
import reborncore.common.util.WrenchUtils;
@ -101,7 +100,7 @@ public class CableBlock extends BlockWithEntity implements Waterloggable {
cableShapeUtil = new CableShapeUtil(this);
}
public AbstractProperty<Boolean> getProperty(Direction facing) {
public BooleanProperty getProperty(Direction facing) {
switch (facing) {
case EAST:
return EAST;
@ -132,7 +131,7 @@ public class CableBlock extends BlockWithEntity implements Waterloggable {
.with(SOUTH, south).with(WEST, west);
}
private Boolean canConnectTo(IWorld world, BlockPos pos, Direction facing) {
private Boolean canConnectTo(WorldAccess world, BlockPos pos, Direction facing) {
BlockEntity blockEntity = world.getBlockEntity(pos);
if (blockEntity != null && (Energy.valid(blockEntity) || blockEntity instanceof CableBlockEntity)) {
return Boolean.TRUE;
@ -202,7 +201,7 @@ public class CableBlock extends BlockWithEntity implements Waterloggable {
@Override
public BlockState getStateForNeighborUpdate(BlockState ourState, Direction ourFacing, BlockState otherState,
IWorld worldIn, BlockPos ourPos, BlockPos otherPos) {
WorldAccess worldIn, BlockPos ourPos, BlockPos otherPos) {
if (ourState.get(WATERLOGGED)) {
worldIn.getFluidTickScheduler().schedule(ourPos, Fluids.WATER, Fluids.WATER.getTickRate(worldIn));
}
@ -257,7 +256,7 @@ public class CableBlock extends BlockWithEntity implements Waterloggable {
}
@Override
public boolean tryFillWithFluid(IWorld world, BlockPos pos, BlockState state, FluidState fluidState) {
public boolean tryFillWithFluid(WorldAccess world, BlockPos pos, BlockState state, FluidState fluidState) {
return !state.get(COVERED) && Waterloggable.super.tryFillWithFluid(world, pos, state, fluidState);
}

View file

@ -121,10 +121,10 @@ public abstract class EnergyStorageBlock extends BaseBlockEntityProvider {
@SuppressWarnings("deprecation")
@Override
public void onBlockRemoved(BlockState state, World worldIn, BlockPos pos, BlockState newState, boolean isMoving) {
public void onStateReplaced(BlockState state, World worldIn, BlockPos pos, BlockState newState, boolean isMoving) {
if (state.getBlock() != newState.getBlock()) {
ItemHandlerUtils.dropContainedItems(worldIn, pos);
super.onBlockRemoved(state, worldIn, pos, newState, isMoving);
super.onStateReplaced(state, worldIn, pos, newState, isMoving);
}
}

View file

@ -55,7 +55,7 @@ public class LSUStorageBlock extends BaseBlockEntityProvider {
// BaseTileBlock
@Override
public void onBlockRemoved(BlockState state, World worldIn, BlockPos pos, BlockState newState, boolean isMoving) {
public void onStateReplaced(BlockState state, World worldIn, BlockPos pos, BlockState newState, boolean isMoving) {
if (state.getBlock() == newState.getBlock()) {
return;
}
@ -65,7 +65,7 @@ public class LSUStorageBlock extends BaseBlockEntityProvider {
blockEntity.removeFromNetwork();
}
}
super.onBlockRemoved(state, worldIn, pos, newState, isMoving);
super.onStateReplaced(state, worldIn, pos, newState, isMoving);
}
@Override

View file

@ -80,7 +80,7 @@ public class GuiAutoCrafting extends GuiBase<BuiltScreenHandler> {
}
drawOutputSlot(matrixStack, 145, 42, layer);
drawOutputSlot(matrixStack, 95, 42, layer);
drawStringWithShadow(matrixStack, client.textRenderer, new LiteralText("Inventory"), 8, 82, 4210752);
drawTextWithShadow(matrixStack, client.textRenderer, new LiteralText("Inventory"), 8, 82, 4210752);
builder.drawLockButton(matrixStack, this, 145, 4, mouseX, mouseY, layer, blockEntityAutoCraftingTable.locked);
}

View file

@ -117,8 +117,8 @@ public class GuiFusionReactor extends GuiBase<BuiltScreenHandler> {
}
}
method_27535(matrixStack, client.textRenderer, new LiteralText("Size: ").append(String.valueOf(blockEntity.size)), 83, 81, 0xFFFFFF);
method_27535(matrixStack, client.textRenderer,new LiteralText(String.valueOf(blockEntity.getPowerMultiplier())).append("x"), 10, 81, 0xFFFFFF);
drawTextWithShadow(matrixStack, client.textRenderer, new LiteralText("Size: ").append(String.valueOf(blockEntity.size)), 83, 81, 0xFFFFFF);
drawTextWithShadow(matrixStack, client.textRenderer,new LiteralText(String.valueOf(blockEntity.getPowerMultiplier())).append("x"), 10, 81, 0xFFFFFF);
builder.drawMultiEnergyBar(matrixStack, this, 9, 19, (int) this.blockEntity.getEnergy(), (int) this.blockEntity.getMaxPower(), mouseX, mouseY, 0, layer);
}

View file

@ -92,10 +92,10 @@ public class GuiManual extends Screen {
int centerX = (width / 2) - guiWidth / 2;
int centerY = (height / 2) - guiHeight / 2;
drawTexture(matrixStack, centerX, centerY, 0, 0, guiWidth, guiHeight);
textRenderer.draw(matrixStack, text1, ((width / 2) - textRenderer.getStringWidth(text1) / 2), centerY + 40, 4210752);
textRenderer.draw(matrixStack, text2, ((width / 2) - textRenderer.getStringWidth(text2) / 2), centerY + 90, 4210752);
textRenderer.draw(matrixStack, text1, ((width / 2) - textRenderer.getWidth(text1) / 2), centerY + 40, 4210752);
textRenderer.draw(matrixStack, text2, ((width / 2) - textRenderer.getWidth(text2) / 2), centerY + 90, 4210752);
if (TechRebornConfig.allowManualRefund) {
textRenderer.draw(matrixStack, text3, ((width / 2) - textRenderer.getStringWidth(text3) / 2), centerY + 140, 4210752);
textRenderer.draw(matrixStack, text3, ((width / 2) - textRenderer.getWidth(text3) / 2), centerY + 140, 4210752);
}
super.render(matrixStack, mouseX, mouseY, partialTicks);
}

View file

@ -48,10 +48,10 @@ public class GuiTankUnit extends GuiBase<BuiltScreenHandler> {
super.drawBackground(matrixStack, f, mouseX, mouseY);
final GuiBase.Layer layer = GuiBase.Layer.BACKGROUND;
drawStringWithShadow(matrixStack, client.textRenderer, new TranslatableText("gui.techreborn.unit.in"), 100, 43, 4210752);
drawTextWithShadow(matrixStack, client.textRenderer, new TranslatableText("gui.techreborn.unit.in"), 100, 43, 4210752);
drawSlot(matrixStack, 100, 53, layer);
drawStringWithShadow(matrixStack, client.textRenderer, new TranslatableText("gui.techreborn.unit.out"), 140, 43, 4210752);
drawTextWithShadow(matrixStack, client.textRenderer, new TranslatableText("gui.techreborn.unit.out"), 140, 43, 4210752);
drawSlot(matrixStack, 140, 53, layer);
}

View file

@ -37,15 +37,17 @@ public class TowelettePlugin implements ToweletteApi {
private List<Fluid> fluids;
@Override
public boolean isFluidBlacklisted(Fluid fluid, Identifier id) {
if(fluids == null){
fluids = new ArrayList<>();
Arrays.stream(ModFluids.values()).forEach(modFluids -> {
fluids.add(modFluids.getFluid());
fluids.add(modFluids.getFlowingFluid());
});
}
return fluids.contains(fluid);
}
//TODO enable again in 1.16, gradle was being annoying and cba to fix it now
// @Override
// public boolean isFluidBlacklisted(Fluid fluid, Identifier id) {
// if(fluids == null){
// fluids = new ArrayList<>();
// Arrays.stream(ModFluids.values()).forEach(modFluids -> {
// fluids.add(modFluids.getFluid());
// fluids.add(modFluids.getFlowingFluid());
// });
// }
// return fluids.contains(fluid);
// }
}

View file

@ -73,17 +73,17 @@ public class ModLoot {
LootPool poolBasic = FabricLootPoolBuilder.builder().withEntry(copperIngot).withEntry(tinIngot)
.withEntry(leadIngot).withEntry(silverIngot).withEntry(refinedronIngot).withEntry(advancedalloyIngot)
.withEntry(basicFrame).withEntry(basicCircuit).withRolls(UniformLootTableRange.between(1.0f, 2.0f))
.withEntry(basicFrame).withEntry(basicCircuit).rolls(UniformLootTableRange.between(1.0f, 2.0f))
.build();
LootPool poolAdvanced = FabricLootPoolBuilder.builder().withEntry(aluminumIngot).withEntry(electrumIngot)
.withEntry(invarIngot).withEntry(nickelIngot).withEntry(steelIngot).withEntry(zincIngot)
.withEntry(advancedFrame).withEntry(advancedCircuit).withEntry(dataStorageChip).withRolls(UniformLootTableRange.between(1.0f, 3.0f))
.withEntry(advancedFrame).withEntry(advancedCircuit).withEntry(dataStorageChip).rolls(UniformLootTableRange.between(1.0f, 3.0f))
.build();
LootPool poolIndustrial = FabricLootPoolBuilder.builder().withEntry(chromeIngot).withEntry(iridiumIngot)
.withEntry(platinumIngot).withEntry(titaniumIngot).withEntry(tungstenIngot).withEntry(tungstensteelIngot)
.withEntry(industrialFrame).withEntry(industrialCircuit).withEntry(energyFlowChip).withRolls(UniformLootTableRange.between(1.0f, 3.0f))
.withEntry(industrialFrame).withEntry(industrialCircuit).withEntry(energyFlowChip).rolls(UniformLootTableRange.between(1.0f, 3.0f))
.build();
LootTableLoadingCallback.EVENT.register((resourceManager, lootManager, ident, supplier, setter) -> {
@ -138,8 +138,8 @@ public class ModLoot {
*/
private static LootEntry makeEntry(ItemConvertible item) {
return ItemEntry.builder(item).setWeight(5)
.withFunction(SetCountLootFunction.builder(UniformLootTableRange.between(1.0f, 2.0f))).build();
return ItemEntry.builder(item).weight(5)
.apply(SetCountLootFunction.builder(UniformLootTableRange.between(1.0f, 2.0f))).build();
}

View file

@ -38,7 +38,7 @@ import net.minecraft.util.math.BlockPointer;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.Position;
import net.minecraft.world.IWorld;
import net.minecraft.world.WorldAccess;
import reborncore.common.crafting.RebornRecipe;
import techreborn.config.TechRebornConfig;
import techreborn.items.DynamicCellItem;
@ -71,7 +71,7 @@ public class TRDispenserBehavior {
DispenserBlock.registerBehavior(TRContent.CELL, new ItemDispenserBehavior(){
public ItemStack dispenseSilently(BlockPointer pointer, ItemStack stack) {
DynamicCellItem cell = (DynamicCellItem)stack.getItem();
IWorld iWorld = pointer.getWorld();
WorldAccess iWorld = pointer.getWorld();
BlockPos blockPos = pointer.getBlockPos().offset(pointer.getBlockState().get(DispenserBlock.FACING));
BlockState blockState = iWorld.getBlockState(blockPos);
Block block = blockState.getBlock();

View file

@ -52,7 +52,7 @@ import net.minecraft.util.hit.HitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.registry.Registry;
import net.minecraft.world.IWorld;
import net.minecraft.world.WorldAccess;
import net.minecraft.world.RayTraceContext;
import net.minecraft.world.World;
import org.apache.commons.lang3.Validate;
@ -76,7 +76,7 @@ public class DynamicCellItem extends Item implements ItemFluidInfo {
}
// Thanks vanilla :)
private void playEmptyingSound(@Nullable PlayerEntity playerEntity, IWorld world, BlockPos blockPos, Fluid fluid) {
private void playEmptyingSound(@Nullable PlayerEntity playerEntity, WorldAccess world, BlockPos blockPos, Fluid fluid) {
SoundEvent soundEvent = fluid.isIn(FluidTags.LAVA) ? SoundEvents.ITEM_BUCKET_EMPTY_LAVA : SoundEvents.ITEM_BUCKET_EMPTY;
world.playSound(playerEntity, blockPos, soundEvent, SoundCategory.BLOCKS, 1.0F, 1.0F);
}
@ -116,7 +116,7 @@ public class DynamicCellItem extends Item implements ItemFluidInfo {
if (!blockState.isAir() && !canPlace && (!(blockState.getBlock() instanceof FluidFillable) || !((FluidFillable)blockState.getBlock()).canFillWithFluid(world, pos, blockState, fluid))) {
return hitResult != null && this.placeFluid(player, world, hitResult.getBlockPos().offset(hitResult.getSide()), null, filledCell);
} else {
if (world.dimension.doesWaterVaporize() && fluid.isIn(FluidTags.WATER)) {
if (world.getDimension().isUltrawarm() && fluid.isIn(FluidTags.WATER)) {
int i = pos.getX();
int j = pos.getY();
int k = pos.getZ();

View file

@ -27,29 +27,31 @@ package techreborn.items;
import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment;
import net.minecraft.client.item.TooltipContext;
import net.minecraft.datafixer.NbtOps;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemUsageContext;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.text.LiteralText;
import net.minecraft.text.MutableText;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.*;
import net.minecraft.util.dynamic.GlobalPos;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.registry.Registry;
import net.minecraft.util.registry.RegistryKey;
import net.minecraft.world.World;
import net.minecraft.world.dimension.DimensionType;
import reborncore.client.hud.StackInfoElement;
import reborncore.common.chunkloading.ChunkLoaderManager;
import reborncore.common.util.ChatUtils;
import reborncore.common.util.StringUtils;
import techreborn.TechReborn;
import techreborn.init.TRContent;
import techreborn.utils.MessageIDs;
import javax.annotation.Nullable;
import java.util.List;
import java.util.Optional;
import java.util.function.Function;
public class FrequencyTransmitterItem extends Item {
@ -63,14 +65,14 @@ public class FrequencyTransmitterItem extends Item {
BlockPos pos = context.getBlockPos();
ItemStack stack = context.getStack();
stack.setTag(new CompoundTag());
stack.getOrCreateTag().putInt("x", pos.getX());
stack.getOrCreateTag().putInt("y", pos.getY());
stack.getOrCreateTag().putInt("z", pos.getZ());
stack.getOrCreateTag().putInt("dim", world.getDimension().getType().getRawId());
GlobalPos globalPos = GlobalPos.create(ChunkLoaderManager.getDimensionRegistryKey(world), pos);
GlobalPos.CODEC.encodeStart(NbtOps.INSTANCE, globalPos).result()
.ifPresent(tag -> stack.getOrCreateTag().put("pos", tag));
if (!world.isClient) {
new TranslatableText("techreborn.message.setTo")
ChatUtils.sendNoSpamMessages(MessageIDs.freqTransmitterID, new TranslatableText("techreborn.message.setTo")
.append(new LiteralText(" X:").formatted(Formatting.GRAY))
.append(new LiteralText(String.valueOf(pos.getX())).formatted(Formatting.GOLD))
.append(new LiteralText(" Y:").formatted(Formatting.GRAY))
@ -79,11 +81,19 @@ public class FrequencyTransmitterItem extends Item {
.append(new LiteralText(String.valueOf(pos.getZ())).formatted(Formatting.GOLD))
.append(" ")
.append(new TranslatableText("techreborn.message.in").formatted(Formatting.GRAY))
.append(new LiteralText(getDimName(world.getDimension().getType()).toString()).formatted(Formatting.GOLD));
.append(" ")
.append(new LiteralText(getDimName(globalPos.getDimension()).toString()).formatted(Formatting.GOLD)));
}
return ActionResult.SUCCESS;
}
public static Optional<GlobalPos> getPos(ItemStack stack) {
if (!stack.hasTag() || !stack.getOrCreateTag().contains("pos")) {
return Optional.empty();
}
return GlobalPos.CODEC.parse(NbtOps.INSTANCE, stack.getOrCreateTag().getCompound("pos")).result();
}
@Override
public TypedActionResult<ItemStack> use(World world, PlayerEntity player,
Hand hand) {
@ -110,24 +120,17 @@ public class FrequencyTransmitterItem extends Item {
@Environment(EnvType.CLIENT)
@Override
public void appendTooltip(ItemStack stack, @Nullable World worldIn, List<Text> tooltip, TooltipContext flagIn) {
if (stack.hasTag() && stack.getTag() != null && stack.getTag().contains("x") && stack.getTag().contains("y") && stack.getTag().contains("z") && stack.getTag().contains("dim")) {
int x = stack.getTag().getInt("x");
int y = stack.getTag().getInt("y");
int z = stack.getTag().getInt("z");
int dim = stack.getTag().getInt("dim");
tooltip.add(new LiteralText(Formatting.GRAY + "X: " + Formatting.GOLD + x));
tooltip.add(new LiteralText(Formatting.GRAY + "Y: " + Formatting.GOLD + y));
tooltip.add(new LiteralText(Formatting.GRAY + "Z: " + Formatting.GOLD + z));
tooltip.add(new LiteralText(Formatting.DARK_GRAY + getDimName(Registry.DIMENSION_TYPE.get(dim)).toString()));
} else {
tooltip.add(new TranslatableText("techreborn.message.noCoordsSet").formatted(Formatting.GRAY));
}
getPos(stack)
.ifPresent(globalPos -> {
tooltip.add(new LiteralText(Formatting.GRAY + "X: " + Formatting.GOLD + globalPos.getPos().getX()));
tooltip.add(new LiteralText(Formatting.GRAY + "Y: " + Formatting.GOLD + globalPos.getPos().getY()));
tooltip.add(new LiteralText(Formatting.GRAY + "Z: " + Formatting.GOLD + globalPos.getPos().getZ()));
tooltip.add(new LiteralText(Formatting.DARK_GRAY + getDimName(globalPos.getDimension()).toString()));
});
}
private static Identifier getDimName(DimensionType type){
return Registry.DIMENSION_TYPE.getId(type);
private static Identifier getDimName(RegistryKey<DimensionType> dimensionRegistryKey){
return dimensionRegistryKey.getValue();
}
public static class StackInfoFreqTransmitter extends StackInfoElement {
@ -137,21 +140,14 @@ public class FrequencyTransmitterItem extends Item {
@Override
public Text getText(ItemStack stack) {
MutableText text = new LiteralText("");
Formatting gold = Formatting.GOLD;
Formatting grey = Formatting.GRAY;
if (stack.getItem() instanceof FrequencyTransmitterItem) {
if (stack.hasTag() && stack.getTag() != null && stack.getTag().contains("x") && stack.getTag().contains("y") && stack.getTag().contains("z") && stack.getTag().contains("dim")) {
int coordX = stack.getTag().getInt("x");
int coordY = stack.getTag().getInt("y");
int coordZ = stack.getTag().getInt("z");
int coordDim = stack.getTag().getInt("dim");
text = text.append(new LiteralText(grey + "X: " + gold + coordX + grey + " Y: " + gold + coordY + grey + " Z: " + gold + coordZ + grey + " Dim: " + gold + getDimName(Registry.DIMENSION_TYPE.get(coordDim)).toString() + " (" + coordDim + ")"));
} else {
text = text.append(new TranslatableText("techreborn.message.noCoordsSet").formatted(Formatting.GRAY));
}
if (!(stack.getItem() instanceof FrequencyTransmitterItem)) {
return LiteralText.EMPTY;
}
return text;
return getPos(stack)
.map((Function<GlobalPos, Text>) globalPos -> new LiteralText(grey + "X: " + gold + globalPos.getPos().getX() + grey + " Y: " + gold + globalPos.getPos().getY() + grey + " Z: " + gold + globalPos.getPos().getZ() + grey + " Dim: " + gold + getDimName(globalPos.getDimension()).toString()))
.orElse(new TranslatableText("techreborn.message.noCoordsSet").formatted(Formatting.GRAY));
}
}
}

View file

@ -125,7 +125,7 @@ public class QuantumSuitItem extends TRArmourItem implements ItemStackModifiers,
}
@Override
public Multimap<EntityAttribute, EntityAttributeModifier> getModifiers(EquipmentSlot slot) {
public Multimap<EntityAttribute, EntityAttributeModifier> getAttributeModifiers(EquipmentSlot slot) {
return HashMultimap.create();
}

View file

@ -74,7 +74,7 @@ public class DebugToolItem extends Item {
private void sendMessage(ItemUsageContext context, Text string) {
if (!context.getWorld().isClient) {
context.getPlayer().sendSystemMessage(string);
context.getPlayer().sendSystemMessage(string, Util.field_25140);
}
}

View file

@ -1,11 +1,10 @@
package techreborn.world;
import com.mojang.datafixers.Dynamic;
import com.mojang.serialization.Codec;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.Heightmap;
import net.minecraft.world.IWorld;
import net.minecraft.world.WorldAccess;
import net.minecraft.world.gen.chunk.ChunkGenerator;
import net.minecraft.world.gen.chunk.ChunkGeneratorConfig;
import net.minecraft.world.gen.decorator.ChanceDecoratorConfig;
import net.minecraft.world.gen.decorator.Decorator;
@ -16,23 +15,24 @@ import java.util.stream.Stream;
// Big thanks to SuperCoder7979 for this
public class RubberTreeDecorator extends Decorator<ChanceDecoratorConfig> {
public RubberTreeDecorator(Function<Dynamic<?>, ? extends ChanceDecoratorConfig> configDeserializer) {
super(configDeserializer);
}
@Override
public Stream<BlockPos> getPositions(IWorld world, ChunkGenerator<? extends ChunkGeneratorConfig> generator, 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 = world.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(WorldAccess world, ChunkGenerator generator, 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 = world.getTopY(Heightmap.Type.MOTION_BLOCKING, x, z);
return new BlockPos(x, y, z);
});
}
return Stream.empty();
}
}

View file

@ -24,34 +24,30 @@
package techreborn.world;
import com.mojang.datafixers.Dynamic;
import com.mojang.serialization.Codec;
import net.minecraft.block.BlockState;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.ModifiableTestableWorld;
import net.minecraft.world.gen.feature.AbstractTreeFeature;
import net.minecraft.world.gen.feature.TreeFeature;
import net.minecraft.world.gen.feature.TreeFeatureConfig;
import net.minecraft.world.gen.foliage.BlobFoliagePlacer;
import net.minecraft.world.gen.foliage.FoliagePlacerType;
import techreborn.config.TechRebornConfig;
import techreborn.init.TRContent;
import java.util.Random;
import java.util.Set;
import java.util.function.Function;
/**
* @author drcrazy
*
*/
public class RubberTreeFeature extends AbstractTreeFeature {
public class RubberTreeFeature extends TreeFeature {
public RubberTreeFeature(Function<Dynamic<?>, ? extends TreeFeatureConfig> configFactory) {
super(configFactory);
public RubberTreeFeature(Codec<TreeFeatureConfig> codec) {
super(codec);
}
public static class FoliagePlacer extends BlobFoliagePlacer {
public FoliagePlacer(int radius, int randomRadius, int offset, int randomOffset, int height) {

View file

@ -79,8 +79,8 @@ public class WorldGenerator {
}
private static void setupTrees() {
RUBBER_TREE_FEATURE = Registry.register(Registry.FEATURE, new Identifier("techreborn:rubber_tree"), new RubberTreeFeature(TreeFeatureConfig::deserialize));
RUBBER_TREE_DECORATOR = Registry.register(Registry.DECORATOR, new Identifier("techreborn:rubber_tree"), new RubberTreeDecorator(ChanceDecoratorConfig::deserialize));
RUBBER_TREE_FEATURE = Registry.register(Registry.FEATURE, new Identifier("techreborn:rubber_tree"), new RubberTreeFeature(TreeFeatureConfig.field_24921));
RUBBER_TREE_DECORATOR = Registry.register(Registry.DECORATOR, new Identifier("techreborn:rubber_tree"), new RubberTreeDecorator(ChanceDecoratorConfig.field_24980));
WeightedBlockStateProvider logProvider = new WeightedBlockStateProvider();
logProvider.addState(TRContent.RUBBER_LOG.getDefaultState(), 10);