Skip to content

Commit

Permalink
port to 1.19-pre1
Browse files Browse the repository at this point in the history
  • Loading branch information
Fourmisain committed May 19, 2022
1 parent 319d1d8 commit 66dd485
Show file tree
Hide file tree
Showing 8 changed files with 27 additions and 34 deletions.
12 changes: 6 additions & 6 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,9 @@ org.gradle.jvmargs=-Xmx1G

# Fabric Properties
# check these on https://fabricmc.net/versions.html
minecraft_version=1.18.2
yarn_mappings=1.18.2+build.3
loader_version=0.13.3
minecraft_version=1.19-pre1
yarn_mappings=1.19-pre1+build.1
loader_version=0.14.5

# Mod Properties
mod_version=1.11.1
Expand All @@ -14,8 +14,8 @@ mod_id=fallingleaves
archives_base_name=fallingleaves

# Required Dependencies
fabric_api_version=0.51.1+1.18.2
cloth_config_version=6.2.57
fabric_api_version=0.52.4+1.19
cloth_config_version=7.0.65

# Suggested Dependencies
modmenu_version=3.1.1
modmenu_version=4.0.0-beta.4
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import me.shedaniel.autoconfig.util.Utils;
import me.shedaniel.clothconfig2.api.AbstractConfigListEntry;
import me.shedaniel.clothconfig2.api.ConfigEntryBuilder;
import net.minecraft.text.TranslatableText;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;

import java.lang.reflect.Field;
Expand All @@ -20,7 +20,7 @@ public List<AbstractConfigListEntry> get(String i13n, Field field, Object config
return Collections.singletonList(
ConfigEntryBuilder.create()
.startStrField(
new TranslatableText(i13n),
Text.translatable(i13n),
Utils.<Identifier>getUnsafely(field, config).toString()
)
.setDefaultValue(() -> Utils.<Identifier>getUnsafely(field, defaults).toString())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import me.shedaniel.autoconfig.util.Utils;
import me.shedaniel.clothconfig2.api.AbstractConfigListEntry;
import me.shedaniel.clothconfig2.api.ConfigEntryBuilder;
import net.minecraft.text.TranslatableText;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;

import java.lang.reflect.Field;
Expand Down Expand Up @@ -38,7 +38,7 @@ public List<AbstractConfigListEntry> get(String i13n, Field field, Object config
return Collections.singletonList(
ConfigEntryBuilder.create()
.startStrList(
new TranslatableText(i13n),
Text.translatable(i13n),
Utils.<Set<Identifier>>getUnsafely(field, config).stream()
.map(Identifier::toString)
.collect(toList())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@
import me.shedaniel.clothconfig2.impl.builders.IntSliderBuilder;
import me.shedaniel.clothconfig2.impl.builders.SubCategoryBuilder;
import net.minecraft.block.Block;
import net.minecraft.text.MutableText;
import net.minecraft.text.Text;
import net.minecraft.text.TranslatableText;
import net.minecraft.util.Identifier;
import randommcsomethin.fallingleaves.config.ConfigDefaults;
import randommcsomethin.fallingleaves.config.LeafSettingsEntry;
Expand All @@ -27,7 +27,7 @@
import static randommcsomethin.fallingleaves.util.RegistryUtil.getBlock;

public class LeafSettingsGuiProvider implements GuiProvider {
private static final TranslatableText RESET_TEXT = new TranslatableText("text.cloth-config.reset_value");
private static final MutableText RESET_TEXT = Text.translatable("text.cloth-config.reset_value");

@SuppressWarnings({"rawtypes", "unchecked", "ConstantConditions"})
@Override
Expand All @@ -45,7 +45,7 @@ public List<AbstractConfigListEntry> get(String i13n, Field field, Object config
LeafSettingsEntry leafEntry = e.getValue();
Block block = getBlock(blockId);

TranslatableText text = new TranslatableText(block.getTranslationKey());
MutableText text = Text.translatable(block.getTranslationKey());
if (!leafEntry.isDefault(blockId)) {
text.append("*");
}
Expand Down Expand Up @@ -79,20 +79,20 @@ private static IntegerSliderEntry buildSpawnRateFactorSlider(Identifier blockId,
currentValue /= stepSize;
defaultValue /= stepSize;

return new IntSliderBuilder(RESET_TEXT, new TranslatableText("config.fallingleaves.spawn_rate_factor"), currentValue, min, max)
return new IntSliderBuilder(RESET_TEXT, Text.translatable("config.fallingleaves.spawn_rate_factor"), currentValue, min, max)
.setDefaultValue(defaultValue)
.setSaveConsumer((Integer value) -> {
entry.spawnRateFactor = (value * stepSize) / 100.0;
})
.setTextGetter((Integer value) -> {
return Text.of((value * stepSize) + "%");
})
.setTooltip(new TranslatableText("config.fallingleaves.spawn_rate_factor.@Tooltip"))
.setTooltip(Text.translatable("config.fallingleaves.spawn_rate_factor.@Tooltip"))
.build();
}

private static BooleanListEntry buildIsConiferLeavesToggle(Identifier blockId, LeafSettingsEntry entry) {
return new BooleanToggleBuilder(RESET_TEXT, new TranslatableText("config.fallingleaves.is_conifer"), entry.isConiferBlock)
return new BooleanToggleBuilder(RESET_TEXT, Text.translatable("config.fallingleaves.is_conifer"), entry.isConiferBlock)
.setDefaultValue(ConfigDefaults.isConifer(blockId))
.setSaveConsumer((Boolean isConiferBlock) -> {
entry.isConiferBlock = isConiferBlock;
Expand Down
5 changes: 2 additions & 3 deletions src/main/java/randommcsomethin/fallingleaves/init/Leaves.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.random.AbstractRandom;
import net.minecraft.world.World;
import randommcsomethin.fallingleaves.config.LeafSettingsEntry;
import randommcsomethin.fallingleaves.particle.FallingLeafParticle;
import randommcsomethin.fallingleaves.util.LeafUtil;
import randommcsomethin.fallingleaves.util.RegistryUtil;
import randommcsomethin.fallingleaves.util.TextureCache;

import java.util.Random;

import static randommcsomethin.fallingleaves.FallingLeavesClient.LOGGER;
import static randommcsomethin.fallingleaves.init.Config.CONFIG;
import static randommcsomethin.fallingleaves.util.LeafUtil.getLeafSettingsEntry;
Expand Down Expand Up @@ -73,7 +72,7 @@ public Identifier getFabricId() {

/** Spawn between 0 and 3 leaves on hitting a leaf block */
private static void registerAttackBlockLeaves() {
Random random = new Random();
AbstractRandom random = AbstractRandom.create();

AttackBlockCallback.EVENT.register((PlayerEntity player, World world, Hand hand, BlockPos pos, Direction direction) -> {
if (world.isClient) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,13 @@
import net.minecraft.block.BlockState;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.random.AbstractRandom;
import net.minecraft.util.registry.Registry;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import randommcsomethin.fallingleaves.config.LeafSettingsEntry;
import randommcsomethin.fallingleaves.util.LeafUtil;

import java.util.Objects;
import java.util.Random;

import static randommcsomethin.fallingleaves.init.Config.CONFIG;
import static randommcsomethin.fallingleaves.util.LeafUtil.*;
Expand All @@ -23,7 +19,7 @@
public class BlockMixin {

@Inject(method = "randomDisplayTick", at = @At("HEAD"))
private void randomLeafBlockTick(BlockState state, World world, BlockPos pos, Random random, CallbackInfo info) {
private void randomLeafBlockTick(BlockState state, World world, BlockPos pos, AbstractRandom random, CallbackInfo ci) {
// not a leaf spawner?
Identifier id = Registry.BLOCK.getId(state.getBlock());
if (!CONFIG.leafSpawners.contains(id))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,15 @@
import net.minecraft.client.world.ClientWorld;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.random.AbstractRandom;
import net.minecraft.world.World;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
import randommcsomethin.fallingleaves.FallingLeavesClient;
import randommcsomethin.fallingleaves.config.LeafSettingsEntry;
import randommcsomethin.fallingleaves.util.LeafUtil;

import java.util.Random;

import static randommcsomethin.fallingleaves.init.Config.CONFIG;
import static randommcsomethin.fallingleaves.util.LeafUtil.getLeafSettingsEntry;
import static randommcsomethin.fallingleaves.util.LeafUtil.trySpawnLeafParticle;
Expand All @@ -28,7 +26,7 @@
public abstract class LeafTickMixin {

@Inject(method = "randomDisplayTick", at = @At("HEAD"))
private void randomLeafBlockTick(BlockState state, World world, BlockPos pos, Random random, CallbackInfo info) {
private void randomLeafBlockTick(BlockState state, World world, BlockPos pos, AbstractRandom random, CallbackInfo ci) {
LeafSettingsEntry leafSettings = getLeafSettingsEntry(state);

// Every leaf block has a settings entry, but some blocks are considered leaves when they technically aren't
Expand All @@ -44,7 +42,7 @@ private void randomLeafBlockTick(BlockState state, World world, BlockPos pos, Ra

// TODO this only runs server-side and will thus only work in singleplayer
@Inject(method = "randomTick", at = @At(value = "INVOKE", target = "Lnet/minecraft/server/world/ServerWorld;removeBlock(Lnet/minecraft/util/math/BlockPos;Z)Z"))
public void randomTick(BlockState state, ServerWorld world, BlockPos pos, Random random, CallbackInfo ci) {
public void randomTick(BlockState state, ServerWorld world, BlockPos pos, AbstractRandom random, CallbackInfo ci) {
if (CONFIG.maxDecayLeaves == 0)
return;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import net.minecraft.util.math.Box;
import net.minecraft.util.math.Direction;
import net.minecraft.util.math.Vec3i;
import net.minecraft.util.math.random.AbstractRandom;
import net.minecraft.util.registry.Registry;
import net.minecraft.world.World;
import org.jetbrains.annotations.Nullable;
Expand All @@ -30,7 +31,6 @@
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Random;
import java.util.function.Function;
import java.util.stream.Collectors;

Expand All @@ -40,7 +40,7 @@

public class LeafUtil {

private static final Random renderRandom = new Random();
private static final AbstractRandom renderRandom = AbstractRandom.create();

public static double getModifiedSpawnChance(BlockState state, LeafSettingsEntry leafSettings) {
double spawnChance = leafSettings.getSpawnChance();
Expand All @@ -64,7 +64,7 @@ public static double getModifiedSpawnChance(BlockState state, LeafSettingsEntry
return spawnChance;
}

public static void trySpawnLeafParticle(BlockState state, World world, BlockPos pos, Random random) {
public static void trySpawnLeafParticle(BlockState state, World world, BlockPos pos, AbstractRandom random) {
if (CONFIG.startingSpawnRadius > 0) {
assert MinecraftClient.getInstance().player != null; // guaranteed when called from randomDisplayTick

Expand All @@ -82,7 +82,7 @@ public static void trySpawnLeafParticle(BlockState state, World world, BlockPos
}
}

public static void spawnLeafParticles(int count, boolean spawnInsideBlock, BlockState state, World world, BlockPos pos, Random random, LeafSettingsEntry leafSettings) {
public static void spawnLeafParticles(int count, boolean spawnInsideBlock, BlockState state, World world, BlockPos pos, AbstractRandom random, LeafSettingsEntry leafSettings) {
if (count == 0) return;

BlockStateParticleEffect params = new BlockStateParticleEffect(leafSettings.isConiferBlock ? Leaves.FALLING_CONIFER_LEAF : Leaves.FALLING_LEAF, state);
Expand Down

0 comments on commit 66dd485

Please sign in to comment.