Skip to content

Commit

Permalink
fix: fix various issues with pistons
Browse files Browse the repository at this point in the history
* some code formatting
  • Loading branch information
UltimatChamp committed Feb 25, 2025
1 parent 756b303 commit fc30737
Show file tree
Hide file tree
Showing 13 changed files with 106 additions and 62 deletions.
4 changes: 4 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,7 @@ hs_err_*.log
replay_*.log
*.hprof
*.jfr

# temp files

*~
24 changes: 10 additions & 14 deletions src/main/java/dev/ultimatchamp/bettergrass/BetterGrassify.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,8 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;

public class BetterGrassify {
public static final String MOD_ID = "bettergrass";
Expand All @@ -16,17 +14,15 @@ public class BetterGrassify {
public static List<String> getBlocks() {
BetterGrassifyConfig config = BetterGrassifyConfig.load();

List<String> blocks = Stream.of(
Map.entry(config.grassBlocks, "minecraft:grass_block"),
Map.entry(config.dirtPaths, "minecraft:dirt_path"),
Map.entry(config.farmLands, "minecraft:farmland"),
Map.entry(config.podzol, "minecraft:podzol"),
Map.entry(config.mycelium, "minecraft:mycelium"),
Map.entry(config.crimsonNylium, "minecraft:crimson_nylium"),
Map.entry(config.warpedNylium, "minecraft:warped_nylium")
).filter(Map.Entry::getKey)
.map(Map.Entry::getValue)
.collect(Collectors.toList());
List<String> blocks = new ArrayList<>();

if (config.grassBlocks) blocks.add("minecraft:grass_block");
if (config.dirtPaths) blocks.add("minecraft:dirt_path");
if (config.farmLands) blocks.add("minecraft:farmland");
if (config.podzol) blocks.add("minecraft:podzol");
if (config.mycelium) blocks.add("minecraft:mycelium");
if (config.crimsonNylium) blocks.add("minecraft:crimson_nylium");
if (config.warpedNylium) blocks.add("minecraft:warped_nylium");

blocks.addAll(config.moreBlocks);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -141,21 +141,21 @@ public static BetterGrassifyConfig load() {

try {
if (!Files.exists(CONFIG_PATH)) {
BetterGrassify.LOGGER.info("[{}] Config file not found. Creating a new one...", BetterGrassify.MOD_ID);
BetterGrassify.LOGGER.info("[BetterGrassify] Config file not found. Creating a new one...");
save(config = new BetterGrassifyConfig());
} else {
String configContent = Files.readString(CONFIG_PATH).trim();

if (!configContent.startsWith("{") || !configContent.endsWith("}")) {
BetterGrassify.LOGGER.warn("[{}] Config file is empty or invalid. Creating a new one...", BetterGrassify.MOD_ID);
BetterGrassify.LOGGER.warn("[BetterGrassify] Config file is empty or invalid. Creating a new one...");
save(config = new BetterGrassifyConfig());
} else {
JsonObject configJson = ensureDefaults(JANKSON.load(configContent));
config = JANKSON.fromJson(configJson, BetterGrassifyConfig.class);
}
}
} catch (IOException | SyntaxError e) {
BetterGrassify.LOGGER.error("[{}]", BetterGrassify.MOD_ID, e);
BetterGrassify.LOGGER.error("[BetterGrassify]", e);
save(config = new BetterGrassifyConfig());
}

Expand All @@ -169,7 +169,7 @@ public static void save(BetterGrassifyConfig config) {
Files.writeString(CONFIG_PATH, jsonString);
cachedConfig = config;
} catch (IOException e) {
BetterGrassify.LOGGER.error("[{}]", BetterGrassify.MOD_ID, e);
BetterGrassify.LOGGER.error("[BetterGrassify]", e);
}
}

Expand All @@ -185,12 +185,12 @@ private static JsonObject ensureDefaults(JsonObject configJson) {
Object defaultValue = field.get(defaultConfig);

if (!configJson.containsKey(fieldName)) {
BetterGrassify.LOGGER.info("[{}] Missing config field '{}'. Re-saving as default.", BetterGrassify.MOD_ID, fieldName);
BetterGrassify.LOGGER.info("[BetterGrassify] Missing config field '{}'. Re-saving as default.", fieldName);
configJson.put(fieldName, JANKSON.toJson(defaultValue));
modified = true;
}
} catch (IllegalAccessException e) {
BetterGrassify.LOGGER.error("[{}] Failed to access field '{}'", BetterGrassify.MOD_ID, field.getName(), e);
BetterGrassify.LOGGER.error("[BetterGrassify] Failed to access field '{}'", field.getName(), e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,16 @@ public static Screen createConfigScreen(Screen parent) {
.name(Text.translatable("bettergrass.betterGrassMode"))
.description(OptionDescription.createBuilder()
.text(Text.translatable("bettergrass.betterGrassMode.desc"))
.webpImage(Identifier.of("bettergrass", "textures/images/bettergrassmode.webp"))
.webpImage(Identifier.of("bettergrass",
"textures/images/bettergrassmode.webp"))
.build())
.binding(
BetterGrassifyConfig.BetterGrassMode.FANCY,
() -> config.betterGrassMode,
(value) -> config.betterGrassMode = value
)
.customController(opt -> new EnumController<>(opt, BetterGrassifyConfig.BetterGrassMode.class))
.customController(opt ->
new EnumController<>(opt, BetterGrassifyConfig.BetterGrassMode.class))
.build())
.option(Option.<Boolean>createBuilder()
.name(Text.translatable("bettergrass.resourcePackCompatibilityMode"))
Expand Down Expand Up @@ -170,7 +172,8 @@ public static Screen createConfigScreen(Screen parent) {
(value) -> config.betterSnowMode = value
)
.available(!FabricLoader.getInstance().isModLoaded("wilderwild"))
.customController(opt -> new EnumController<>(opt, BetterGrassifyConfig.BetterSnowMode.class))
.customController(opt ->
new EnumController<>(opt, BetterGrassifyConfig.BetterSnowMode.class))
.build())
.group(ListOption.<String>createBuilder()
.name(Text.translatable("bettergrass.snowLayers"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ public NoYACLWarning(Screen parent) {
protected void init() {
super.init();

ButtonWidget btn = ButtonWidget.builder(Text.translatable("dataPack.validation.back"), button -> this.client.setScreen(parent)).dimensions(this.width / 2 - 100, this.height / 2 + 50, 200, 20).build();
ButtonWidget btn = ButtonWidget.builder(Text.translatable("dataPack.validation.back"),
button -> this.client.setScreen(parent))
.dimensions(this.width / 2 - 100, this.height / 2 + 50, 200, 20)
.build();
this.addDrawableChild(btn);
}

Expand All @@ -27,7 +30,8 @@ public void render(DrawContext context, int mouseX, int mouseY, float delta) {

Text warning = Text.translatable("bettergrass.noyacl.warn");
//? if >1.21.3 {
context.drawWrappedText(this.textRenderer, warning, this.width / 2 - 100, this.height / 2 - 50, 200, 0xFFFFFFFF, true);
context.drawWrappedText(this.textRenderer, warning, this.width / 2 - 100, this.height / 2 - 50, 200,
0xFFFFFFFF, true);
//?} else {
/*context.drawTextWrapped(this.textRenderer, warning, this.width / 2 - 100, this.height / 2 - 50, 200, 0xFFFFFFFF);
*///?}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,15 @@ public void onInitializeClient() {
if (config.betterGrassMode == BetterGrassifyConfig.BetterGrassMode.OFF) {
BetterGrassify.LOGGER.info("[BetterGrassify] Better Grass is disabled.");
} else {
BetterGrassify.LOGGER.info("[BetterGrassify] [{}] Gamers can finally touch grass!?", config.betterGrassMode.toString());
BetterGrassify.LOGGER.info("[BetterGrassify] [{}] Gamers can finally touch grass!?",
config.betterGrassMode.toString());
}

if (FabricLoader.getInstance().isModLoaded("wilderwild")) {
config.snowy = false;
config.betterSnowMode = BetterGrassifyConfig.BetterSnowMode.OFF;
BetterGrassify.LOGGER.warn("[BetterGrassify] WilderWild detected. 'Better Snowy Grass' and 'Better Snow' features have been disabled.");
BetterGrassify.LOGGER.warn("[BetterGrassify] WilderWild detected. " +
"'Better Snowy Grass' and 'Better Snow' features have been disabled.");
}

ModelLoadingPlugin.register(pluginContext -> pluginContext
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,8 @@ public BetterGrassifyNeo(ModContainer modContainer, IEventBus modBus) {
modBus.addListener(this::onClientSetup);
BetterGrassifyConfig.load();
modContainer.registerExtensionPoint(IConfigScreenFactory.class, (client, parent) -> BetterGrassifyConfig.createConfigScreen(parent));
modContainer.registerExtensionPoint(IConfigScreenFactory.class, (client, parent) ->
BetterGrassifyConfig.createConfigScreen(parent));
}
private void onClientSetup(FMLClientSetupEvent event) {
Expand All @@ -25,13 +26,15 @@ private void onClientSetup(FMLClientSetupEvent event) {
if (config.betterGrassMode == BetterGrassifyConfig.BetterGrassMode.OFF) {
BetterGrassify.LOGGER.info("[BetterGrassify] Better Grass is disabled.");
} else {
BetterGrassify.LOGGER.info("[BetterGrassify] [{}] Gamers can finally touch grass!?", config.betterGrassMode.toString());
BetterGrassify.LOGGER.info("[BetterGrassify] [{}] Gamers can finally touch grass!?",
config.betterGrassMode.toString());
}
if (FabricLoader.getInstance().isModLoaded("wilderwild")) {
config.snowy = false;
config.betterSnowMode = BetterGrassifyConfig.BetterSnowMode.OFF;
BetterGrassify.LOGGER.warn("[BetterGrassify] WilderWild detected. 'Better Snowy Grass' and 'Better Snow' features have been disabled.");
BetterGrassify.LOGGER.warn("[BetterGrassify] WilderWild detected. " +
"'Better Snowy Grass' and 'Better Snow' features have been disabled.");
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,11 @@ public class SectionBuilderMixin {
private BlockRenderManager blockRenderManager;

//? if fabric {
@Inject(method = "build", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/block/BlockRenderManager;renderBlock(Lnet/minecraft/block/BlockState;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/world/BlockRenderView;Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumer;ZLnet/minecraft/util/math/random/Random;)V"))
@Inject(method = "build", at = @At(value = "INVOKE",
target = "Lnet/minecraft/client/render/block/BlockRenderManager;renderBlock(Lnet/minecraft/block/BlockState;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/world/BlockRenderView;Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumer;ZLnet/minecraft/util/math/random/Random;)V"))
//?} else if neoforge {
/*@Inject(method = "compile", at = @At(value = "INVOKE", target = "Lnet/minecraft/client/render/block/BlockRenderManager;renderBatched(Lnet/minecraft/block/BlockState;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/world/BlockRenderView;Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumer;ZLnet/minecraft/util/math/random/Random;Lnet/neoforged/neoforge/client/model/data/ModelData;Lnet/minecraft/client/render/RenderLayer;)V"))
/*@Inject(method = "compile", at = @At(value = "INVOKE",
target = "Lnet/minecraft/client/render/block/BlockRenderManager;renderBatched(Lnet/minecraft/block/BlockState;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/world/BlockRenderView;Lnet/minecraft/client/util/math/MatrixStack;Lnet/minecraft/client/render/VertexConsumer;ZLnet/minecraft/util/math/random/Random;Lnet/neoforged/neoforge/client/model/data/ModelData;Lnet/minecraft/client/render/RenderLayer;)V"))
*///?}
private void bettergrass$render(ChunkSectionPos sectionPos,
ChunkRendererRegion renderRegion,
Expand All @@ -58,7 +60,8 @@ public class SectionBuilderMixin {
if (BetterGrassifyBakedModel.canHaveSnowLayer(renderRegion, blockPos.up())) {
matrixStack.push();
matrixStack.translate(0, 1, 0);
blockRenderManager.renderBlock(snowNeighbour.getDefaultState(), blockPos.up(), renderRegion, matrixStack, bufferBuilder, true, random);
blockRenderManager.renderBlock(snowNeighbour.getDefaultState(), blockPos.up(), renderRegion,
matrixStack, bufferBuilder, true, random);
matrixStack.pop();
}
}
Expand All @@ -69,11 +72,13 @@ public class SectionBuilderMixin {
//?} else if neoforge {
/*@ModifyVariable(method = "compile", at = @At("STORE"), ordinal = 0)
*///?}
private BlockState bettergrass$setGrassState(BlockState state, @Local(ordinal = 2) BlockPos blockPos, @Local(argsOnly = true) ChunkRendererRegion renderRegion) {
private BlockState bettergrass$setGrassState(BlockState state, @Local(ordinal = 2) BlockPos blockPos,
@Local(argsOnly = true) ChunkRendererRegion renderRegion) {
if (state.getOrEmpty(Properties.SNOWY).isEmpty()) return state;
if (BetterGrassifyBakedModel.isNeighbourSnow(renderRegion, blockPos.up())) return state;

if (BetterGrassifyBakedModel.canHaveSnowLayer(renderRegion, blockPos.up())) return state.with(Properties.SNOWY, true);
if (BetterGrassifyBakedModel.canHaveSnowLayer(renderRegion, blockPos.up()))
return state.with(Properties.SNOWY, true);

return state;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ public VideoOptionsScreenMixin(Screen parent, GameOptions gameOptions, Text titl
)
)
private void bettergrass$addConfigButton(CallbackInfo ci) {
this.body.addSingleOptionEntry(new SimpleOption<>("bettergrass.title", SimpleOption.constantTooltip(Text.empty()), (arg, object) -> Text.empty(), SimpleOption.BOOLEAN, true, (parent) -> this.client.setScreen(BetterGrassifyConfig.createConfigScreen(this))));
this.body.addSingleOptionEntry(new SimpleOption<>("bettergrass.title",
SimpleOption.constantTooltip(Text.empty()), (arg, object) ->
Text.empty(), SimpleOption.BOOLEAN, true, (parent) ->
this.client.setScreen(BetterGrassifyConfig.createConfigScreen(this))));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,17 @@

@Mixin(value = SodiumGameOptionPages.class, remap = false)
public class SodiumGameOptionsPagesMixin {
@Inject(method = "quality", at = @At(value = "INVOKE", target = "Lnet/caffeinemc/mods/sodium/client/gui/options/OptionGroup;createBuilder()Lnet/caffeinemc/mods/sodium/client/gui/options/OptionGroup$Builder;", ordinal = 1, shift = At.Shift.AFTER), locals = LocalCapture.CAPTURE_FAILSOFT, remap = false)
@Inject(method = "quality", at = @At(value = "INVOKE", target = "Lnet/caffeinemc/mods/sodium/client/gui/options/OptionGroup;createBuilder()Lnet/caffeinemc/mods/sodium/client/gui/options/OptionGroup$Builder;", ordinal = 1,
shift = At.Shift.AFTER), locals = LocalCapture.CAPTURE_FAILSOFT, remap = false)
private static void bettergrass$quality(CallbackInfoReturnable<OptionPage> cir, List<OptionGroup> groups) {
BetterGrassifyConfig config = BetterGrassifyConfig.load();

groups.add(OptionGroup.createBuilder()
.add(OptionImpl.createBuilder(BetterGrassifyConfig.BetterGrassMode.class, SodiumOptionsStorage.INSTANCE)
.setName(Text.translatable("bettergrass.betterGrassMode"))
.setTooltip(Text.translatable("bettergrass.betterGrassMode.desc"))
.setControl((opt) -> new CyclingControl<>(opt, BetterGrassifyConfig.BetterGrassMode.class, new Text[]{
.setControl((opt) ->
new CyclingControl<>(opt, BetterGrassifyConfig.BetterGrassMode.class, new Text[]{
Text.translatable("options.off"),
Text.translatable("options.graphics.fast"),
Text.translatable("options.graphics.fancy")
Expand Down Expand Up @@ -122,7 +124,8 @@ public class SodiumGameOptionsPagesMixin {
).add(OptionImpl.createBuilder(BetterGrassifyConfig.BetterSnowMode.class, SodiumOptionsStorage.INSTANCE)
.setName(Text.translatable("bettergrass.betterSnowMode"))
.setTooltip(Text.translatable("bettergrass.betterSnowMode.desc"))
.setControl((opt) -> new CyclingControl<>(opt, BetterGrassifyConfig.BetterSnowMode.class, new Text[]{
.setControl((opt) ->
new CyclingControl<>(opt, BetterGrassifyConfig.BetterSnowMode.class, new Text[]{
Text.translatable("options.off"),
Text.translatable("bettergrass.betterSnowMode.optifine"),
Text.translatable("bettergrass.betterSnowMode.lambda")
Expand Down
Loading

0 comments on commit fc30737

Please sign in to comment.