Skip to content
This repository was archived by the owner on Jun 3, 2024. It is now read-only.

Commit fcfff13

Browse files
valoeghesecoderbot16
authored andcommitted
Implement public Biome getRiver() (#35)
* implement public Biome getRiver() * import order * import order 2 * license * failed biome check * fix code * fix concurrentmodificationexception * use an iterator like coderbot suggested * yeet * fuck * update gitignorer * coderbot's changes * @OverRide
1 parent 32eecf8 commit fcfff13

File tree

6 files changed

+176
-0
lines changed

6 files changed

+176
-0
lines changed

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
.settings
99
.project
1010
*.launch
11+
.recommenders
1112

1213
# Intellij/Idea
1314
.factorypath
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
/*
2+
* Minecraft Forge, Patchwork Project
3+
* Copyright (c) 2016-2020, 2019-2020
4+
*
5+
* This library is free software; you can redistribute it and/or
6+
* modify it under the terms of the GNU Lesser General Public
7+
* License as published by the Free Software Foundation version 2.1
8+
* of the License.
9+
*
10+
* This library is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
* Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public
16+
* License along with this library; if not, write to the Free Software
17+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18+
*/
19+
20+
package com.patchworkmc.impl.biomes;
21+
22+
import java.util.Iterator;
23+
import java.util.Set;
24+
25+
import com.google.common.collect.Sets;
26+
27+
import net.minecraft.util.registry.Registry;
28+
import net.minecraft.world.biome.Biome;
29+
import net.minecraft.world.biome.Biomes;
30+
31+
import net.fabricmc.api.ModInitializer;
32+
import net.fabricmc.fabric.api.biomes.v1.OverworldBiomes;
33+
import net.fabricmc.fabric.api.event.registry.RegistryEntryAddedCallback;
34+
import net.fabricmc.fabric.api.event.server.ServerStartCallback;
35+
36+
public final class PatchworkBiomes implements ModInitializer {
37+
private static Set<Biome> failedBiomes = Sets.newHashSet();
38+
39+
@Override
40+
public void onInitialize() {
41+
Registry.BIOME.forEach(PatchworkBiomes::addRivers);
42+
RegistryEntryAddedCallback.event(Registry.BIOME).register((rawid, id, biome) -> {
43+
addRivers(biome);
44+
updateFailedBiomes();
45+
});
46+
ServerStartCallback.EVENT.register(server -> updateFailedBiomes());
47+
}
48+
49+
private static void addRivers(Biome biome) {
50+
Biome river = ((RiverSupplier) biome).getRiver();
51+
52+
if (river == null) {
53+
failedBiomes.add(biome);
54+
return;
55+
}
56+
57+
setRiverIfNotDefault(biome, river);
58+
}
59+
60+
private static void updateFailedBiomes() {
61+
if (!failedBiomes.isEmpty()) {
62+
Iterator<Biome> iterator = failedBiomes.iterator();
63+
64+
while (iterator.hasNext()) {
65+
Biome biome = iterator.next();
66+
Biome river = ((RiverSupplier) biome).getRiver();
67+
68+
if (river == null) {
69+
continue;
70+
}
71+
72+
iterator.remove();
73+
74+
setRiverIfNotDefault(biome, river);
75+
}
76+
}
77+
}
78+
79+
private static void setRiverIfNotDefault(Biome biome, Biome river) {
80+
if (river != getDefaultRiver(biome)) {
81+
OverworldBiomes.setRiverBiome(biome, river);
82+
}
83+
}
84+
85+
public static Biome getDefaultRiver(Biome biome) {
86+
if (biome == Biomes.SNOWY_TUNDRA) {
87+
return Biomes.FROZEN_RIVER;
88+
} else if (biome == Biomes.MUSHROOM_FIELDS || biome == Biomes.MUSHROOM_FIELD_SHORE) {
89+
return Biomes.MUSHROOM_FIELD_SHORE;
90+
}
91+
92+
return Biomes.RIVER;
93+
}
94+
}
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
/*
2+
* Minecraft Forge, Patchwork Project
3+
* Copyright (c) 2016-2020, 2019-2020
4+
*
5+
* This library is free software; you can redistribute it and/or
6+
* modify it under the terms of the GNU Lesser General Public
7+
* License as published by the Free Software Foundation version 2.1
8+
* of the License.
9+
*
10+
* This library is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
* Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public
16+
* License along with this library; if not, write to the Free Software
17+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18+
*/
19+
20+
package com.patchworkmc.impl.biomes;
21+
22+
import net.minecraft.world.biome.Biome;
23+
24+
public interface RiverSupplier {
25+
Biome getRiver();
26+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/*
2+
* Minecraft Forge, Patchwork Project
3+
* Copyright (c) 2016-2020, 2019-2020
4+
*
5+
* This library is free software; you can redistribute it and/or
6+
* modify it under the terms of the GNU Lesser General Public
7+
* License as published by the Free Software Foundation version 2.1
8+
* of the License.
9+
*
10+
* This library is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
* Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public
16+
* License along with this library; if not, write to the Free Software
17+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18+
*/
19+
20+
package com.patchworkmc.mixin.biomes;
21+
22+
import org.spongepowered.asm.mixin.Mixin;
23+
24+
import net.minecraft.world.biome.Biome;
25+
26+
import com.patchworkmc.impl.biomes.RiverSupplier;
27+
import com.patchworkmc.impl.biomes.PatchworkBiomes;
28+
29+
@Mixin(Biome.class)
30+
public class MixinBiome implements RiverSupplier {
31+
@Override
32+
public Biome getRiver() {
33+
Biome self = (Biome) (Object) this;
34+
return PatchworkBiomes.getDefaultRiver(self);
35+
}
36+
}

patchwork-biomes/src/main/resources/fabric.mod.json

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,14 @@
1717
"patchwork-fml": "*"
1818
},
1919
"description": "Implementation of the Forge Biomes API.",
20+
"entrypoints": {
21+
"main": [
22+
"com.patchworkmc.impl.biomes.PatchworkBiomes"
23+
]
24+
},
25+
"mixins": [
26+
"patchwork-biomes.mixins.json"
27+
],
2028
"custom": {
2129
"modmenu:api": true,
2230
"modmenu:parent": "patchwork"
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
{
2+
"required": true,
3+
"package": "com.patchworkmc.mixin.biomes",
4+
"compatibilityLevel": "JAVA_8",
5+
"mixins": [
6+
"MixinBiome"
7+
],
8+
"injectors": {
9+
"defaultRequire": 1
10+
}
11+
}

0 commit comments

Comments
 (0)