Skip to content

Commit 0db7a07

Browse files
Reyeet
1 parent 3bf5cfe commit 0db7a07

45 files changed

Lines changed: 842 additions & 844 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

src/main/java/org/dimdev/vanillafix/VanillaFix.java

Lines changed: 71 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -22,82 +22,82 @@
2222
import net.fabricmc.loader.api.ModContainer;
2323

2424
public class VanillaFix implements ModInitializer {
25-
public static final Logger LOGGER = LogManager.getLogger();
26-
public static final ModContainer MOD = FabricLoader.getInstance().getModContainer("vanillafix").orElseThrow(IllegalStateException::new);
27-
private static ModConfig MOD_CONFIG;
28-
private static final Path PATH = FabricLoader.getInstance().getConfigDir().resolve("vanillafix.json5");
29-
public static final Jankson JANKSON = Jankson.builder().build();
30-
public static final Map<String, ConfigPair> MIXIN_CONFIGS;
25+
public static final Logger LOGGER = LogManager.getLogger();
26+
public static final ModContainer MOD = FabricLoader.getInstance().getModContainer("vanillafix").orElseThrow(IllegalStateException::new);
27+
private static ModConfig MOD_CONFIG;
28+
private static final Path PATH = FabricLoader.getInstance().getConfigDir().resolve("vanillafix.json5");
29+
public static final Jankson JANKSON = Jankson.builder().build();
30+
public static final Map<String, ConfigPair> MIXIN_CONFIGS;
3131

32-
@Override
33-
public void onInitialize() {
34-
if (MOD.getMetadata().getVersion().getFriendlyString().contains("beta")) {
35-
LOGGER.warn("================================================");
36-
LOGGER.warn("You are running a beta version of VanillaFix!");
37-
LOGGER.warn("VanillaFix Version: {}", MOD.getMetadata().getVersion().getFriendlyString());
38-
LOGGER.warn("================================================");
39-
}
40-
}
32+
@Override
33+
public void onInitialize() {
34+
if (MOD.getMetadata().getVersion().getFriendlyString().contains("beta")) {
35+
LOGGER.warn("================================================");
36+
LOGGER.warn("You are running a beta version of VanillaFix!");
37+
LOGGER.warn("VanillaFix Version: {}", MOD.getMetadata().getVersion().getFriendlyString());
38+
LOGGER.warn("================================================");
39+
}
40+
}
4141

42-
static {
43-
try {
44-
if (Files.exists(PATH)) {
45-
MOD_CONFIG = JANKSON.fromJson(JANKSON.load(Files.newInputStream(PATH)), ModConfig.class);
46-
} else {
47-
Files.createFile(PATH);
48-
Files.write(PATH, JANKSON.toJson(MOD_CONFIG).toJson(true, true).getBytes());
49-
}
50-
} catch (IOException e) {
51-
LOGGER.error("Error loading config. Using default values");
52-
e.printStackTrace();
53-
MOD_CONFIG = new ModConfig();
54-
} catch (SyntaxError e) {
55-
LOGGER.error("Caught a Syntax error when loading config. Using default values");
56-
LOGGER.error(e.getCompleteMessage());
57-
e.printStackTrace();
58-
MOD_CONFIG = new ModConfig();
59-
}
42+
static {
43+
try {
44+
if (Files.exists(PATH)) {
45+
MOD_CONFIG = JANKSON.fromJson(JANKSON.load(Files.newInputStream(PATH)), ModConfig.class);
46+
} else {
47+
Files.createFile(PATH);
48+
Files.write(PATH, JANKSON.toJson(MOD_CONFIG).toJson(true, true).getBytes());
49+
}
50+
} catch (IOException e) {
51+
LOGGER.error("Error loading config. Using default values");
52+
e.printStackTrace();
53+
MOD_CONFIG = new ModConfig();
54+
} catch (SyntaxError e) {
55+
LOGGER.error("Caught a Syntax error when loading config. Using default values");
56+
LOGGER.error(e.getCompleteMessage());
57+
e.printStackTrace();
58+
MOD_CONFIG = new ModConfig();
59+
}
6060

61-
ImmutableMap.Builder<String, ConfigPair> builder = ImmutableMap.builder();
62-
try (InputStream stream = VanillaFix.class.getResourceAsStream("/data/vanillafix/mixin_configs.json")) {
63-
JsonObject jsonObject = JANKSON.load(stream);
64-
//noinspection UnstableApiUsage
65-
builder.putAll(jsonObject.entrySet()
66-
.stream()
67-
.filter(entry -> entry.getValue() instanceof JsonObject)
68-
.map(entry -> new Map.Entry<String, ConfigPair>() {
69-
@Override
70-
public String getKey() {
71-
return entry.getKey();
72-
}
61+
ImmutableMap.Builder<String, ConfigPair> builder = ImmutableMap.builder();
62+
try (InputStream stream = VanillaFix.class.getResourceAsStream("/data/vanillafix/mixin_configs.json")) {
63+
JsonObject jsonObject = JANKSON.load(stream);
64+
//noinspection UnstableApiUsage
65+
builder.putAll(jsonObject.entrySet()
66+
.stream()
67+
.filter(entry -> entry.getValue() instanceof JsonObject)
68+
.map(entry -> new Map.Entry<String, ConfigPair>() {
69+
@Override
70+
public String getKey() {
71+
return entry.getKey();
72+
}
7373

74-
@Override
75-
public ConfigPair getValue() {
76-
return ConfigPair.CODEC.parse(JanksonOps.INSTANCE, entry.getValue()).getOrThrow(false, System.err::println);
77-
}
74+
@Override
75+
public ConfigPair getValue() {
76+
return ConfigPair.CODEC.parse(JanksonOps.INSTANCE, entry.getValue()).getOrThrow(false, System.err::println);
77+
}
7878

79-
@Override
80-
public ConfigPair setValue(ConfigPair value) {
81-
throw new UnsupportedOperationException();
82-
}
83-
}).collect(Collectors.toSet()));
84-
} catch (IOException | SyntaxError e) {
85-
throw new AssertionError(e);
86-
}
87-
MIXIN_CONFIGS = builder.build();
88-
}
79+
@Override
80+
public ConfigPair setValue(ConfigPair value) {
81+
throw new UnsupportedOperationException();
82+
}
83+
}).collect(Collectors.toSet()));
84+
} catch (IOException | SyntaxError e) {
85+
throw new AssertionError(e);
86+
}
87+
MIXIN_CONFIGS = builder.build();
88+
}
8989

90-
public static void save() {
91-
String json = JANKSON.toJson(MOD_CONFIG).toJson(true, true);
92-
try {
93-
Files.write(PATH, json.getBytes());
94-
} catch (IOException e) {
95-
LOGGER.error("Error saving config");
96-
e.printStackTrace();
97-
}
98-
}
90+
public static void save() {
91+
String json = JANKSON.toJson(MOD_CONFIG).toJson(true, true);
92+
try {
93+
Files.write(PATH, json.getBytes());
94+
} catch (IOException e) {
95+
LOGGER.error("Error saving config");
96+
e.printStackTrace();
97+
}
98+
}
9999

100-
public static ModConfig config() {
101-
return MOD_CONFIG;
102-
}
100+
public static ModConfig config() {
101+
return MOD_CONFIG;
102+
}
103103
}

src/main/java/org/dimdev/vanillafix/VanillaFixEarlyRiser.java

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,23 +5,23 @@
55
import net.fabricmc.loader.api.FabricLoader;
66

77
public class VanillaFixEarlyRiser implements Runnable {
8-
@Override
9-
public void run() {
10-
if (VanillaFix.config().clientOnly.optimizedAnimatedTextures ||
11-
// sodium already does this
12-
!(FabricLoader.getInstance().isModLoaded("sodium"))) {
13-
VanillaFix.LOGGER.debug("Registering Animated Texture Optimization Mixins");
14-
Mixins.addConfiguration("vanillafix.textures.mixins.json");
15-
}
16-
if (VanillaFix.config().clientOnly.cullParticles ||
17-
// sodium already does this too
18-
!(FabricLoader.getInstance().isModLoaded("sodium"))) {
19-
VanillaFix.LOGGER.debug("Registering Particle Optimization Mixins");
20-
Mixins.addConfiguration("vanillafix.particles.mixins.json");
21-
}
22-
if (VanillaFix.config().general.profilerImprovements) {
23-
VanillaFix.LOGGER.debug("Registering Profiler Improvements Mixins");
24-
Mixins.addConfiguration("vanillafix.profiler.mixins.json");
25-
}
26-
}
8+
@Override
9+
public void run() {
10+
if (VanillaFix.config().clientOnly.optimizedAnimatedTextures ||
11+
// sodium already does this
12+
!(FabricLoader.getInstance().isModLoaded("sodium"))) {
13+
VanillaFix.LOGGER.debug("Registering Animated Texture Optimization Mixins");
14+
Mixins.addConfiguration("vanillafix.textures.mixins.json");
15+
}
16+
if (VanillaFix.config().clientOnly.cullParticles ||
17+
// sodium already does this too
18+
!(FabricLoader.getInstance().isModLoaded("sodium"))) {
19+
VanillaFix.LOGGER.debug("Registering Particle Optimization Mixins");
20+
Mixins.addConfiguration("vanillafix.particles.mixins.json");
21+
}
22+
if (VanillaFix.config().general.profilerImprovements) {
23+
VanillaFix.LOGGER.debug("Registering Profiler Improvements Mixins");
24+
Mixins.addConfiguration("vanillafix.profiler.mixins.json");
25+
}
26+
}
2727
}

src/main/java/org/dimdev/vanillafix/bugs/BugFixMixinPlugin.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@
99
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin;
1010
import org.spongepowered.asm.mixin.extensibility.IMixinInfo;
1111

12-
import static org.dimdev.vanillafix.VanillaFix.config;
13-
1412
public class BugFixMixinPlugin implements IMixinConfigPlugin {
1513
@Override
1614
public void onLoad(String mixinPackage) {

src/main/java/org/dimdev/vanillafix/bugs/mixins/BuiltinBiomesMixin.java

Lines changed: 20 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -20,26 +20,26 @@
2020
@MixinConfigValue(category = "bugFixes", value = "fixStoneShoreColors")
2121
@Mixin(BuiltinBiomes.class)
2222
public class BuiltinBiomesMixin {
23-
@Shadow
24-
@Final
25-
private static Int2ObjectMap<RegistryKey<Biome>> BY_RAW_ID;
23+
@Shadow
24+
@Final
25+
private static Int2ObjectMap<RegistryKey<Biome>> BY_RAW_ID;
2626

27-
/**
28-
* Fixes a bug where stone shores, despite being a cold biome
29-
* do not have the cold water color
30-
* Bug Fixed
31-
* - https://bugs.mojang.com/browse/MC-200634
32-
*/
33-
@Inject(method = "register", at = @At("HEAD"), cancellable = true)
34-
private static void interceptRegister(int rawId, RegistryKey<Biome> registryKey, Biome biome, CallbackInfoReturnable<Biome> cir) {
35-
if (registryKey.equals(BiomeKeys.STONE_SHORE)) {
36-
cir.setReturnValue(registerUnsafely(rawId, registryKey, DefaultBiomeCreator.createBeach(0.1F, 0.8F, 0.2F, 0.3F, 0x3d57d6, false, true)));
37-
}
38-
}
27+
/**
28+
* Fixes a bug where stone shores, despite being a cold biome
29+
* do not have the cold water color
30+
* Bug Fixed
31+
* - https://bugs.mojang.com/browse/MC-200634
32+
*/
33+
@Inject(method = "register", at = @At("HEAD"), cancellable = true)
34+
private static void interceptRegister(int rawId, RegistryKey<Biome> registryKey, Biome biome, CallbackInfoReturnable<Biome> cir) {
35+
if (registryKey.equals(BiomeKeys.STONE_SHORE)) {
36+
cir.setReturnValue(registerUnsafely(rawId, registryKey, DefaultBiomeCreator.createBeach(0.1F, 0.8F, 0.2F, 0.3F, 0x3d57d6, false, true)));
37+
}
38+
}
3939

40-
@Unique
41-
private static Biome registerUnsafely(int rawId, RegistryKey<Biome> registryKey, Biome biome) {
42-
BY_RAW_ID.put(rawId, registryKey);
43-
return BuiltinRegistries.set(BuiltinRegistries.BIOME, rawId, registryKey, biome);
44-
}
40+
@Unique
41+
private static Biome registerUnsafely(int rawId, RegistryKey<Biome> registryKey, Biome biome) {
42+
BY_RAW_ID.put(rawId, registryKey);
43+
return BuiltinRegistries.set(BuiltinRegistries.BIOME, rawId, registryKey, biome);
44+
}
4545
}

src/main/java/org/dimdev/vanillafix/bugs/mixins/EntityMixin.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,16 @@
1414
@MixinConfigValue(category = "bugFixes", value = "updateFallDistance")
1515
@Mixin(Entity.class)
1616
public class EntityMixin {
17-
@Shadow
18-
public float fallDistance;
17+
@Shadow
18+
public float fallDistance;
1919

20-
/**
21-
* @reason Fixes a vanilla bug where the entity's fall distance is not updated before invoking the
22-
* block's onFallenUpon when it falls on the ground, meaning that the last fall state update won't
23-
* be included in the fall distance.
24-
*/
25-
@Inject(method = "fall", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/Block;onLandedUpon(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/entity/Entity;F)V"))
26-
private void beforeOnFallenUpon(double y, boolean onGroundIn, BlockState state, BlockPos pos, CallbackInfo ci) {
27-
if (y < 0) this.fallDistance -= y;
28-
}
20+
/**
21+
* @reason Fixes a vanilla bug where the entity's fall distance is not updated before invoking the
22+
* block's onFallenUpon when it falls on the ground, meaning that the last fall state update won't
23+
* be included in the fall distance.
24+
*/
25+
@Inject(method = "fall", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/Block;onLandedUpon(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/entity/Entity;F)V"))
26+
private void beforeOnFallenUpon(double y, boolean onGroundIn, BlockState state, BlockPos pos, CallbackInfo ci) {
27+
if (y < 0) this.fallDistance -= y;
28+
}
2929
}

src/main/java/org/dimdev/vanillafix/bugs/mixins/ItemStackMixin.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -14,15 +14,15 @@
1414
@MixinConfigValue(category = "bugFixes", value = "doNotConsumeFoodOnDeath")
1515
@Mixin(ItemStack.class)
1616
public class ItemStackMixin {
17-
/**
18-
* Prevents consuming food if the entity is dead
19-
* Bugs Fixed:
20-
* - https://bugs.mojang.com/browse/MC-133218
21-
*/
22-
@Inject(method = "finishUsing", at = @At("HEAD"), cancellable = true)
23-
public void interceptFinishUsing(World world, LivingEntity user, CallbackInfoReturnable<ItemStack> cir) {
24-
if ((!user.isAlive() || user.isDead()) && VanillaFix.config().bugFixes.doNotConsumeFoodOnDeath) {
25-
cir.setReturnValue((ItemStack) (Object) this);
26-
}
27-
}
17+
/**
18+
* Prevents consuming food if the entity is dead
19+
* Bugs Fixed:
20+
* - https://bugs.mojang.com/browse/MC-133218
21+
*/
22+
@Inject(method = "finishUsing", at = @At("HEAD"), cancellable = true)
23+
public void interceptFinishUsing(World world, LivingEntity user, CallbackInfoReturnable<ItemStack> cir) {
24+
if ((!user.isAlive() || user.isDead()) && VanillaFix.config().bugFixes.doNotConsumeFoodOnDeath) {
25+
cir.setReturnValue((ItemStack) (Object) this);
26+
}
27+
}
2828
}

src/main/java/org/dimdev/vanillafix/bugs/mixins/MinecraftServerMixin.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,12 @@
1010
@MixinConfigValue(category = "bugFixes", value = "disableInitialChunkLoad")
1111
@Mixin(MinecraftServer.class)
1212
public class MinecraftServerMixin {
13-
/**
14-
* @reason Disable initial chunk load. This makes world load much faster, but in exchange
15-
* the player may see incomplete chunks (like when teleporting to a new area).
16-
* @author ?
17-
*/
18-
@Overwrite
19-
private void prepareStartRegion(WorldGenerationProgressListener worldGenerationProgressListener) {
20-
}
13+
/**
14+
* @reason Disable initial chunk load. This makes world load much faster, but in exchange
15+
* the player may see incomplete chunks (like when teleporting to a new area).
16+
* @author ?
17+
*/
18+
@Overwrite
19+
private void prepareStartRegion(WorldGenerationProgressListener worldGenerationProgressListener) {
20+
}
2121
}

src/main/java/org/dimdev/vanillafix/bugs/mixins/PhantomSpawnerMixin.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -17,12 +17,12 @@
1717
*/
1818
@Mixin(PhantomSpawner.class)
1919
public class PhantomSpawnerMixin {
20-
@Inject(method = "spawn", at = @At(value = "INVOKE_ASSIGN", target = "Ljava/util/List;iterator()Ljava/util/Iterator;", remap = false), cancellable = true)
21-
public void preventSpawn(ServerWorld world, boolean spawnMonsters, boolean spawnAnimals, CallbackInfoReturnable<Integer> cir) {
22-
if (!(VanillaFix.config().bugFixes.phantomMobCap < 0)) {
23-
if (world.getEntitiesByType(EntityType.PHANTOM, e -> true).size() > VanillaFix.config().bugFixes.phantomMobCap) {
24-
cir.setReturnValue(0);
25-
}
26-
}
27-
}
20+
@Inject(method = "spawn", at = @At(value = "INVOKE_ASSIGN", target = "Ljava/util/List;iterator()Ljava/util/Iterator;", remap = false), cancellable = true)
21+
public void preventSpawn(ServerWorld world, boolean spawnMonsters, boolean spawnAnimals, CallbackInfoReturnable<Integer> cir) {
22+
if (!(VanillaFix.config().bugFixes.phantomMobCap < 0)) {
23+
if (world.getEntitiesByType(EntityType.PHANTOM, e -> true).size() > VanillaFix.config().bugFixes.phantomMobCap) {
24+
cir.setReturnValue(0);
25+
}
26+
}
27+
}
2828
}

src/main/java/org/dimdev/vanillafix/bugs/mixins/PlayerInventoryMixin.java

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -11,16 +11,16 @@
1111
@MixinConfigValue(category = "bugFixes", value = "fixRecipeBookIngredientsWithTags")
1212
@Mixin(PlayerInventory.class)
1313
public class PlayerInventoryMixin {
14-
/**
15-
* Compare items by item type rather than NBT when looking for items for the crafting
16-
* recipe. Note that the item is still checked (in findSlotMatchingUnusedItem) to
17-
* make sure it is not enchanted or renamed.
18-
* <p>
19-
* Bugs fixed:
20-
* - https://bugs.mojang.com/browse/MC-129057
21-
*/
22-
@Redirect(method = "method_7371", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerInventory;areItemsEqual(Lnet/minecraft/item/ItemStack;Lnet/minecraft/item/ItemStack;)Z"))
23-
private boolean stackEqualExact(PlayerInventory inventoryPlayer, ItemStack stack1, ItemStack stack2) {
24-
return stack1.getItem() == stack2.getItem();
25-
}
14+
/**
15+
* Compare items by item type rather than NBT when looking for items for the crafting
16+
* recipe. Note that the item is still checked (in findSlotMatchingUnusedItem) to
17+
* make sure it is not enchanted or renamed.
18+
* <p>
19+
* Bugs fixed:
20+
* - https://bugs.mojang.com/browse/MC-129057
21+
*/
22+
@Redirect(method = "method_7371", at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/player/PlayerInventory;areItemsEqual(Lnet/minecraft/item/ItemStack;Lnet/minecraft/item/ItemStack;)Z"))
23+
private boolean stackEqualExact(PlayerInventory inventoryPlayer, ItemStack stack1, ItemStack stack2) {
24+
return stack1.getItem() == stack2.getItem();
25+
}
2626
}

0 commit comments

Comments
 (0)