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

Commit 41ccb63

Browse files
Make Biomes O' Plenty work (#112)
* make bop work * find replace is hard * Implement harvest levels * Switch from ArrayList to TrackedList in BiomeManager * Use @Accessor to implement getItemColors * Explain confusing line in BiomeManager Co-authored-by: Glitch <glitchieproductionsofficial@gmail.com> * Add TODO for setDirtAt in MixinAbstractTreeFeature Co-authored-by: Glitch <glitchieproductionsofficial@gmail.com> * Add comment with Yarn version of Intermediary AW * Explain hack * Move MixinBlockSettings methods into interface Co-authored-by: Glitch <glitchieproductionsofficial@gmail.com>
1 parent 1bafda1 commit 41ccb63

File tree

16 files changed

+469
-1
lines changed

16 files changed

+469
-1
lines changed

patchwork-biomes/src/main/java/net/minecraftforge/common/BiomeManager.java

Lines changed: 127 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,10 +19,16 @@
1919

2020
package net.minecraftforge.common;
2121

22+
import java.util.Collection;
2223
import java.util.Objects;
24+
import java.util.ArrayList;
25+
import java.util.List;
26+
27+
import com.google.common.collect.ImmutableList;
2328

2429
import net.minecraft.util.WeightedPicker;
2530
import net.minecraft.world.biome.Biome;
31+
import net.minecraft.world.biome.Biomes;
2632

2733
import net.fabricmc.fabric.api.biomes.v1.FabricBiomes;
2834
import net.fabricmc.fabric.api.biomes.v1.OverworldBiomes;
@@ -64,14 +70,135 @@ private OverworldClimate getClimate() {
6470
public static class BiomeEntry extends WeightedPicker.Entry {
6571
public final Biome biome;
6672

73+
public int field_76292_a; // FIXME: workaround for https://github.com/PatchworkMC/patchwork-patcher/issues/57, will likely break things
74+
6775
public BiomeEntry(Biome biome, int weight) {
6876
super(weight);
6977

78+
this.field_76292_a = weight;
7079
this.biome = biome;
7180
}
7281

7382
private int getWeight() {
7483
return this.weight;
7584
}
7685
}
86+
87+
// Biomes O' Plenty pokes Forge internals. Fun
88+
private static TrackedList<BiomeEntry>[] biomes = setupBiomes();
89+
90+
private static TrackedList<BiomeEntry>[] setupBiomes() {
91+
@SuppressWarnings("unchecked")
92+
TrackedList<BiomeEntry>[] currentBiomes = new TrackedList[BiomeType.values().length];
93+
List<BiomeEntry> list = new ArrayList<BiomeEntry>();
94+
95+
list.add(new BiomeEntry(Biomes.FOREST, 10));
96+
list.add(new BiomeEntry(Biomes.DARK_FOREST, 10));
97+
list.add(new BiomeEntry(Biomes.MOUNTAINS, 10));
98+
list.add(new BiomeEntry(Biomes.PLAINS, 10));
99+
list.add(new BiomeEntry(Biomes.BIRCH_FOREST, 10));
100+
list.add(new BiomeEntry(Biomes.SWAMP, 10));
101+
102+
currentBiomes[BiomeType.WARM.ordinal()] = new TrackedList<BiomeEntry>(list);
103+
list.clear();
104+
105+
list.add(new BiomeEntry(Biomes.FOREST, 10));
106+
list.add(new BiomeEntry(Biomes.MOUNTAINS, 10));
107+
list.add(new BiomeEntry(Biomes.TAIGA, 10));
108+
list.add(new BiomeEntry(Biomes.PLAINS, 10));
109+
110+
currentBiomes[BiomeType.COOL.ordinal()] = new TrackedList<BiomeEntry>(list);
111+
list.clear();
112+
113+
list.add(new BiomeEntry(Biomes.SNOWY_TUNDRA, 30));
114+
list.add(new BiomeEntry(Biomes.SNOWY_TAIGA, 10));
115+
116+
currentBiomes[BiomeType.ICY.ordinal()] = new TrackedList<BiomeEntry>(list);
117+
list.clear();
118+
119+
currentBiomes[BiomeType.DESERT.ordinal()] = new TrackedList<BiomeEntry>(list);
120+
121+
return currentBiomes;
122+
}
123+
124+
public static ImmutableList<BiomeEntry> getBiomes(BiomeType type) {
125+
int idx = type.ordinal();
126+
// We want to return null instead of throw an exception if the index is out of bounds.
127+
List<BiomeEntry> list = idx >= biomes.length ? null : biomes[idx];
128+
129+
return list != null ? ImmutableList.copyOf(list) : null;
130+
}
131+
132+
private static class TrackedList<E> extends ArrayList<E> {
133+
private static final long serialVersionUID = 1L;
134+
private boolean isModded = false;
135+
136+
TrackedList(Collection<? extends E> c) {
137+
super(c);
138+
}
139+
140+
@Override
141+
public E set(int index, E element) {
142+
isModded = true;
143+
return super.set(index, element);
144+
}
145+
146+
@Override
147+
public boolean add(E e) {
148+
isModded = true;
149+
return super.add(e);
150+
}
151+
152+
@Override
153+
public void add(int index, E element) {
154+
isModded = true;
155+
super.add(index, element);
156+
}
157+
158+
@Override
159+
public E remove(int index) {
160+
isModded = true;
161+
return super.remove(index);
162+
}
163+
164+
@Override
165+
public boolean remove(Object o) {
166+
isModded = true;
167+
return super.remove(o);
168+
}
169+
170+
@Override
171+
public void clear() {
172+
isModded = true;
173+
super.clear();
174+
}
175+
176+
@Override
177+
public boolean addAll(Collection<? extends E> c) {
178+
isModded = true;
179+
return super.addAll(c);
180+
}
181+
182+
@Override
183+
public boolean addAll(int index, Collection<? extends E> c) {
184+
isModded = true;
185+
return super.addAll(index, c);
186+
}
187+
188+
@Override
189+
public boolean removeAll(Collection<?> c) {
190+
isModded = true;
191+
return super.removeAll(c);
192+
}
193+
194+
@Override
195+
public boolean retainAll(Collection<?> c) {
196+
isModded = true;
197+
return super.retainAll(c);
198+
}
199+
200+
public boolean isModded() {
201+
return isModded;
202+
}
203+
}
77204
}

patchwork-dispatcher/src/main/java/net/patchworkmc/api/redirects/itemgroup/PatchworkItemGroup.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public PatchworkItemGroup(String name) {
3333
public PatchworkItemGroup(int index, String name) {
3434
this(name);
3535

36-
if (index != -1) {
36+
if (index != -1 && index < ItemGroup.GROUPS.length - 1) {
3737
throw new IllegalArgumentException("ItemGroup constructor potentially tried to overwrite an existing creative tab!");
3838
}
3939
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
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 net.minecraftforge.event.terraingen;
21+
22+
import net.minecraftforge.eventbus.api.Event;
23+
24+
import net.minecraft.world.level.LevelGeneratorType;
25+
26+
public class WorldTypeEvent extends Event {
27+
private final LevelGeneratorType worldType;
28+
29+
public WorldTypeEvent(LevelGeneratorType worldType) {
30+
this.worldType = worldType;
31+
}
32+
33+
public LevelGeneratorType getWorldType() {
34+
return worldType;
35+
}
36+
37+
public static class BiomeSize extends WorldTypeEvent {
38+
private final int originalSize;
39+
private int newSize;
40+
41+
public BiomeSize(LevelGeneratorType worldType, int original) {
42+
super(worldType);
43+
originalSize = original;
44+
setNewSize(original);
45+
}
46+
47+
public int getOriginalSize() {
48+
return originalSize;
49+
}
50+
51+
public int getNewSize() {
52+
return newSize;
53+
}
54+
55+
public void setNewSize(int newSize) {
56+
this.newSize = newSize;
57+
}
58+
}
59+
}

patchwork-extensions-block/build.gradle

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,9 @@ version = getSubprojectVersion(project, "0.2.0")
33

44
dependencies {
55
compile project(path: ':patchwork-enum-hacks', configuration: 'dev')
6+
compile project(path: ':patchwork-tooltype', configuration: 'dev')
7+
}
8+
9+
minecraft {
10+
accessWidener "src/main/resources/patchwork-extensions-block.accesswidener"
611
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
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 net.patchworkmc.api.block;
21+
22+
import net.minecraftforge.common.ToolType;
23+
24+
import net.minecraft.block.Block;
25+
26+
public interface IPatchworkBlockSettings {
27+
Block.Settings harvestLevel(int harvestLevel);
28+
Block.Settings harvestTool(ToolType harvestTool);
29+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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 net.patchworkmc.mixin.extensions.block;
21+
22+
import org.spongepowered.asm.mixin.Mixin;
23+
import org.spongepowered.asm.mixin.Unique;
24+
import net.minecraftforge.common.ToolType;
25+
26+
import net.minecraft.block.Block;
27+
import net.minecraft.item.Item;
28+
import net.minecraft.tag.Tag;
29+
30+
import net.fabricmc.fabric.api.block.FabricBlockSettings;
31+
import net.fabricmc.fabric.api.tools.FabricToolTags;
32+
33+
import net.patchworkmc.api.block.IPatchworkBlockSettings;
34+
35+
@Mixin(Block.Settings.class)
36+
public class MixinBlockSettings implements IPatchworkBlockSettings {
37+
@Unique
38+
private Integer miningLevel;
39+
@Unique
40+
private Tag<Item> miningTool;
41+
42+
public Block.Settings harvestLevel(int harvestLevel) {
43+
this.miningLevel = new Integer(harvestLevel);
44+
45+
if (this.miningTool != null) {
46+
FabricBlockSettings fabric = FabricBlockSettings.copyOf((Block.Settings) (Object) this);
47+
return fabric.breakByTool(this.miningTool, harvestLevel).build();
48+
} else {
49+
return (Block.Settings) (Object) this;
50+
}
51+
}
52+
53+
public Block.Settings harvestTool(ToolType harvestTool) {
54+
String name = harvestTool.getName();
55+
56+
switch (name) {
57+
case "axe":
58+
this.miningTool = FabricToolTags.AXES;
59+
break;
60+
case "hoe":
61+
this.miningTool = FabricToolTags.HOES;
62+
break;
63+
case "pickaxe":
64+
this.miningTool = FabricToolTags.PICKAXES;
65+
break;
66+
case "shovel":
67+
this.miningTool = FabricToolTags.SHOVELS;
68+
break;
69+
case "sword":
70+
this.miningTool = FabricToolTags.SWORDS;
71+
break;
72+
}
73+
74+
FabricBlockSettings fabric = FabricBlockSettings.copyOf((Block.Settings) (Object) this);
75+
76+
if (this.miningLevel != null) {
77+
return fabric.breakByTool(this.miningTool, this.miningLevel.intValue()).build();
78+
} else {
79+
return fabric.breakByTool(this.miningTool).build();
80+
}
81+
}
82+
}

patchwork-extensions-block/src/main/resources/fabric.mod.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
"mixins": [
1717
"patchwork-extensions-block.mixins.json"
1818
],
19+
"accessWidener": "patchwork-extensions-block.accesswidener",
1920
"custom": {
2021
"modmenu:api": true,
2122
"modmenu:parent": "patchwork"
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
accessWidener v1 named
2+
3+
accessible method net/minecraft/block/StairsBlock <init> (Lnet/minecraft/block/BlockState;Lnet/minecraft/block/Block$Settings;)V
4+
accessible field net/minecraft/block/Block materialColor Lnet/minecraft/block/MaterialColor;
5+
accessible method net/minecraft/block/DoorBlock <init> (Lnet/minecraft/block/Block$Settings;)V
6+
accessible method net/minecraft/block/TrapdoorBlock <init> (Lnet/minecraft/block/Block$Settings;)V
7+
accessible method net/minecraft/block/WoodButtonBlock <init> (Lnet/minecraft/block/Block$Settings;)V
8+
accessible field net/minecraft/item/AxeItem STRIPPED_BLOCKS Ljava/util/Map;
9+
10+
# accessible method net/minecraft/block/PressurePlateBlock <init> (Lnet/minecraft/block/PressurePlateBlock$ActivationRule;Lnet/minecraft/Block$Settings;)V
11+
accessible method net/minecraft/class_2440 <init> (Lnet/minecraft/class_2440$class_2441;Lnet/minecraft/class_2248$class_2251;)V

patchwork-extensions-block/src/main/resources/patchwork-extensions-block.mixins.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
"FireBlockAccessor",
88
"MixinBedBlock",
99
"MixinBlock",
10+
"MixinBlockSettings",
1011
"MixinBlockState",
1112
"MixinCactusBlock",
1213
"MixinCropBlock",

patchwork-extensions/build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
archivesBaseName = "patchwork-extensions"
22
version = getSubprojectVersion(project, "0.2.0")
3+
4+
dependencies {
5+
compile project(path: ':patchwork-extensions-block', configuration: 'dev')
6+
}

0 commit comments

Comments
 (0)