Skip to content

Commit e4a112c

Browse files
committed
Merge branch 'Minecraft-1.20.2' into Neoforge-1.20.4
2 parents 0e55758 + 174047f commit e4a112c

97 files changed

Lines changed: 746 additions & 589 deletions

File tree

Some content is hidden

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

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
## Changelog
22

3+
### 7.10.0 (2026/08/01)
4+
- Added the Orizaba Silkmoth.
5+
36
### 7.9.3 (2026-07-26)
47
- Fixed incorrect Lifespan data being sent over network.
58

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ mod_name=Butterfly Mod
3232
# The license of the mod. Review your options at https://choosealicense.com/. All Rights Reserved is the default.
3333
mod_license=All Rights Reserved
3434
# The mod version. See https://semver.org/
35-
mod_version=7.9.3
35+
mod_version=7.10.0
3636
# The group ID for the mod. It is only important when publishing as an artifact to a Maven repository.
3737
# This should match the base package used for the mod sources.
3838
# See https://maven.apache.org/guides/mini/guide-naming-conventions.html

src/main/java/com/bokmcdok/butterflies/butterfly_data/ButterflyData.java

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
package com.bokmcdok.butterflies.butterfly_data;
22

33
import com.bokmcdok.butterflies.ButterfliesMod;
4-
import com.google.gson.*;
54
import net.minecraft.resources.ResourceLocation;
65
import net.minecraft.tags.BlockTags;
76
import net.minecraft.world.level.block.Blocks;
@@ -21,7 +20,7 @@
2120
* @param caterpillarLifespan The lifespan of the caterpillar phase
2221
* @param chrysalisLifespan The lifespan of the chrysalis phase
2322
* @param butterflyLifespan The lifespan of the butterfly phase
24-
* @param preferredFlower The flower this butterfly prefers
23+
* @param foodSource The flower this butterfly prefers
2524
*/
2625
public record ButterflyData(int butterflyIndex,
2726
String entityId,
@@ -33,7 +32,7 @@ public record ButterflyData(int butterflyIndex,
3332
int caterpillarLifespan,
3433
int chrysalisLifespan,
3534
int butterflyLifespan,
36-
ResourceLocation preferredFlower,
35+
ResourceLocation foodSource,
3736
ButterflyType type,
3837
Diurnality diurnality,
3938
ExtraLandingBlocks extraLandingBlocks,
@@ -57,7 +56,7 @@ public record ButterflyData(int butterflyIndex,
5756
* @param caterpillarLifespan How long it remains in the caterpillar stage.
5857
* @param chrysalisLifespan How long it takes for a chrysalis to hatch.
5958
* @param butterflyLifespan How long it lives as a butterfly.
60-
* @param preferredFlower The flower this butterfly prefers
59+
* @param foodSource The flower this butterfly prefers
6160
*/
6261
public ButterflyData(int butterflyIndex,
6362
String entityId,
@@ -69,7 +68,7 @@ public ButterflyData(int butterflyIndex,
6968
int caterpillarLifespan,
7069
int chrysalisLifespan,
7170
int butterflyLifespan,
72-
ResourceLocation preferredFlower,
71+
ResourceLocation foodSource,
7372
ButterflyType type,
7473
Diurnality diurnality,
7574
ExtraLandingBlocks extraLandingBlocks,
@@ -88,7 +87,7 @@ public ButterflyData(int butterflyIndex,
8887
Objects.requireNonNull(speed, "speed must not be null");
8988
Objects.requireNonNull(rarity, "rarity must not be null");
9089
Objects.requireNonNull(habitats, "habitats must not be null");
91-
Objects.requireNonNull(preferredFlower, "preferredFlower must not be null");
90+
Objects.requireNonNull(foodSource, "foodSource must not be null");
9291
Objects.requireNonNull(type, "type must not be null");
9392
Objects.requireNonNull(diurnality, "diurnality must not be null");
9493
Objects.requireNonNull(extraLandingBlocks, "extraLandingBlocks must not be null");
@@ -110,7 +109,7 @@ public ButterflyData(int butterflyIndex,
110109
this.chrysalisLifespan = chrysalisLifespan;
111110
this.butterflyLifespan = butterflyLifespan;
112111

113-
this.preferredFlower = preferredFlower;
112+
this.foodSource = foodSource;
114113

115114
this.type = type;
116115
this.diurnality = diurnality;
@@ -323,4 +322,16 @@ public boolean isValidLandingBlock(BlockState blockState) {
323322
default -> false;
324323
};
325324
}
325+
326+
/**
327+
* Helper method for getting a food source item from a non-item block.
328+
* @return The Resource Location of the food source item.
329+
*/
330+
public ResourceLocation getFoodSourceItem() {
331+
if (foodSource.getPath().equals("cocoa")) {
332+
return new ResourceLocation("minecraft:cocoa_beans");
333+
}
334+
335+
return foodSource;
336+
}
326337
}

src/main/java/com/bokmcdok/butterflies/butterfly_data/ButterflyDataLoader.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public ButterflyData deserialize(JsonElement json,
8787
ButterflyLifespan chrysalisLifespan = getEnumValue(lifespan, ButterflyLifespan.class, "chrysalis", ButterflyLifespan.MEDIUM);
8888
ButterflyLifespan butterflyLifespan = getEnumValue(lifespan, ButterflyLifespan.class, "butterfly", ButterflyLifespan.MEDIUM);
8989

90-
String preferredFlower = object.get("preferredFlower").getAsString();
90+
String foodSource = object.get("foodSource").getAsString();
9191

9292
ButterflyType type = getEnumValue(object, ButterflyType.class, "type", ButterflyType.BUTTERFLY);
9393
Diurnality diurnality = getEnumValue(object, Diurnality.class, "diurnality", Diurnality.DIURNAL);
@@ -132,7 +132,7 @@ public ButterflyData deserialize(JsonElement json,
132132
LIFESPAN[chrysalisLifespan.getIndex()],
133133
LIFESPAN[butterflyLifespan.getIndex()] == Integer.MAX_VALUE ?
134134
Integer.MAX_VALUE : LIFESPAN[butterflyLifespan.getIndex()] * 2,
135-
new ResourceLocation(preferredFlower),
135+
new ResourceLocation(foodSource),
136136
type,
137137
diurnality,
138138
extraLandingBlocks,

src/main/java/com/bokmcdok/butterflies/butterfly_data/ButterflyInfo.java

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@ public class ButterflyInfo {
6868
"indianmeal",
6969
"luna",
7070
"oak-silk",
71+
"orizaba",
7172
"peppered",
7273
"spongy",
7374
"white-lined-sphinx",
@@ -142,22 +143,33 @@ public class ButterflyInfo {
142143
{}, // No traits for commongrassyellow-dry
143144
{}, // No traits for peacock-pansy-aged
144145
{}, // No traits for peacock-pansy-wet
145-
{}, // No traits for atlas
146-
{}, // No traits for carpet
146+
{
147+
ButterflyTrait.SILK,
148+
},
149+
{
150+
ButterflyTrait.SILK,
151+
},
147152
{}, // No traits for case-bearing-clothes
148153
{
149154
ButterflyTrait.HUMMINGBIRD,
150155
},
151156
{}, // No traits for clothes
152157
{}, // No traits for codling
153158
{}, // No traits for diamondback
154-
{}, // No traits for domestic_silk
159+
{
160+
ButterflyTrait.SILK,
161+
},
155162
{
156163
ButterflyTrait.HUMMINGBIRD,
157164
},
158165
{}, // No traits for indianmeal
159166
{}, // No traits for luna
160-
{}, // No traits for oak-silk
167+
{
168+
ButterflyTrait.SILK,
169+
},
170+
{
171+
ButterflyTrait.SILK,
172+
},
161173
{}, // No traits for peppered
162174
{}, // No traits for spongy
163175
{

src/main/java/com/bokmcdok/butterflies/butterfly_data/ButterflyTrait.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@ public enum ButterflyTrait {
1616
LAVA,
1717
FEARLESS,
1818
PEACEMAKER,
19-
TOUGH
19+
TOUGH,
20+
SILK
2021
}

src/main/java/com/bokmcdok/butterflies/client/gui/screens/ButterflyTextFormatter.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ public static FormattedText getFormattedButterflyData(int butterflyIndex) {
118118
component.append(Component.translatable("gui.butterflies.preferred_flower"));
119119

120120
@SuppressWarnings("deprecation")
121-
Component description = BuiltInRegistries.ITEM.get(entry.preferredFlower()).asItem().getDescription();
121+
Component description = BuiltInRegistries.ITEM.get(entry.getFoodSourceItem()).asItem().getDescription();
122122
component.append(description);
123123

124124
// Fact
Lines changed: 67 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,62 @@
11
package com.bokmcdok.butterflies.data.loot;
22

3-
import com.bokmcdok.butterflies.ButterfliesMod;
43
import com.bokmcdok.butterflies.butterfly_data.ButterflyRegistry;
4+
import com.bokmcdok.butterflies.butterfly_data.ButterflyTrait;
55
import com.bokmcdok.butterflies.registries.ButterflyEntityTypeRegistry;
66
import com.bokmcdok.butterflies.registries.EntityTypeRegistry;
77
import com.bokmcdok.butterflies.registries.ItemRegistry;
8-
import com.bokmcdok.butterflies.butterfly_data.ButterflyData;
98
import net.minecraft.core.registries.BuiltInRegistries;
109
import net.minecraft.data.loot.EntityLootSubProvider;
1110
import net.minecraft.world.entity.EntityType;
1211
import net.minecraft.world.flag.FeatureFlags;
1312
import net.minecraft.world.item.Items;
13+
import net.minecraft.world.level.ItemLike;
1414
import net.minecraft.world.level.storage.loot.LootPool;
1515
import net.minecraft.world.level.storage.loot.LootTable;
1616
import net.minecraft.world.level.storage.loot.entries.LootItem;
17+
import net.minecraft.world.level.storage.loot.functions.LootItemFunction;
1718
import net.minecraft.world.level.storage.loot.functions.LootingEnchantFunction;
1819
import net.minecraft.world.level.storage.loot.functions.SetItemCountFunction;
1920
import net.minecraft.world.level.storage.loot.providers.number.ConstantValue;
21+
import net.minecraft.world.level.storage.loot.providers.number.NumberProvider;
2022
import net.minecraft.world.level.storage.loot.providers.number.UniformGenerator;
21-
import org.apache.commons.lang3.StringUtils;
2223
import org.jetbrains.annotations.NotNull;
2324

24-
import java.util.List;
25-
import java.util.Optional;
25+
import java.util.Set;
26+
import java.util.stream.Collectors;
2627
import java.util.stream.Stream;
27-
import java.util.stream.StreamSupport;
2828

2929
/**
3030
* Adds loot tables for entities.
3131
*/
3232
public class ModEntityLootSubProvider extends EntityLootSubProvider {
33-
private static final List<String> SILK_SPECIES = List.of(
34-
"atlas_chrysalis",
35-
"carpet_chrysalis",
36-
"domestic_silk_chrysalis",
37-
"oak-silk_chrysalis");
33+
34+
private final Set<EntityType<?>> knownEntityTypes;
35+
private final Set<EntityType<?>> silkChrysalises;
3836

3937
/**
4038
* Construction.
4139
*/
4240
public ModEntityLootSubProvider() {
4341
super(FeatureFlags.REGISTRY.allFlags());
42+
43+
this.silkChrysalises = ButterflyRegistry.getButterflyDataCollection().stream()
44+
.filter(data -> data.hasTrait(ButterflyTrait.SILK))
45+
.map(data -> ButterflyEntityTypeRegistry.CHRYSALISES.get(data.butterflyIndex()).get())
46+
.collect(Collectors.toUnmodifiableSet());
47+
48+
this.knownEntityTypes = Stream.concat(
49+
silkChrysalises.stream(),
50+
Stream.of(EntityTypeRegistry.BUTTERFLY_GOLEM.get())
51+
).collect(Collectors.toUnmodifiableSet());
4452
}
4553

4654
/**
4755
* Entry point.
4856
*/
4957
@Override
5058
public void generate() {
51-
SILK_SPECIES.stream()
52-
.map(ButterflyRegistry::getButterflyIndex)
53-
.forEach(this::addChrysalisSilkLoot);
54-
59+
silkChrysalises.forEach(this::addChrysalisSilkLoot);
5560
add(EntityTypeRegistry.BUTTERFLY_GOLEM.get(), createButterflyGolemLoot());
5661
}
5762

@@ -62,7 +67,7 @@ public void generate() {
6267
*/
6368
@Override
6469
protected boolean canHaveLootTable(@NotNull EntityType<?> entityType) {
65-
return super.canHaveLootTable(entityType) || entityType.equals(EntityTypeRegistry.BUTTERFLY_GOLEM.get());
70+
return knownEntityTypes.contains(entityType) || super.canHaveLootTable(entityType);
6671
}
6772

6873
/**
@@ -72,29 +77,19 @@ protected boolean canHaveLootTable(@NotNull EntityType<?> entityType) {
7277
@NotNull
7378
@Override
7479
protected Stream<EntityType<?>> getKnownEntityTypes() {
75-
Stream<EntityType<?>> silkChrysalisesStream = StreamSupport.stream(BuiltInRegistries.ENTITY_TYPE.spliterator(), false)
76-
.filter(entry ->
77-
Optional.of(BuiltInRegistries.ENTITY_TYPE.getKey(entry))
78-
.filter(key -> key.getNamespace().equals(ButterfliesMod.MOD_ID)
79-
&& StringUtils.equalsAny(key.getPath(), SILK_SPECIES.toArray(new String[0])))
80-
.isPresent()
81-
);
82-
83-
return Stream.concat(silkChrysalisesStream, Stream.of(EntityTypeRegistry.BUTTERFLY_GOLEM.get()));
80+
return knownEntityTypes.stream();
8481
}
8582

8683
/**
8784
* Adds a silk drop to a chrysalis.
88-
* @param butterflyIndex The butterfly index.
85+
* @param entityType The entity to add a loot table for.
8986
*/
90-
private void addChrysalisSilkLoot(int butterflyIndex) {
91-
add(ButterflyEntityTypeRegistry.CHRYSALISES.get(butterflyIndex).get(),
92-
LootTable.lootTable()
93-
.withPool(LootPool.lootPool()
94-
.setRolls(ConstantValue.exactly(1.0f))
95-
.add(LootItem.lootTableItem(ItemRegistry.SILK.get())
96-
.apply(SetItemCountFunction.setCount(UniformGenerator.between(1.0f, 3.0f)))
97-
.apply(LootingEnchantFunction.lootingMultiplier(UniformGenerator.between(0.0f, 1.0f))))));
87+
private void addChrysalisSilkLoot(EntityType<?> entityType) {
88+
add(entityType, singleRollCountedLoot(
89+
ItemRegistry.SILK.get(),
90+
UniformGenerator.between(1.0f, 3.0f),
91+
LootingEnchantFunction.lootingMultiplier(UniformGenerator.between(0.0f, 1.0f))
92+
));
9893
}
9994

10095
/**
@@ -103,13 +98,43 @@ private void addChrysalisSilkLoot(int butterflyIndex) {
10398
*/
10499
private LootTable.Builder createButterflyGolemLoot() {
105100
return LootTable.lootTable()
106-
.withPool(LootPool.lootPool()
107-
.setRolls(ConstantValue.exactly(1.0f))
108-
.add(LootItem.lootTableItem(Items.POPPY)
109-
.apply(SetItemCountFunction.setCount(UniformGenerator.between(0.0f, 2.0f)))))
110-
.withPool(LootPool.lootPool()
111-
.setRolls(ConstantValue.exactly(1.0f))
112-
.add(LootItem.lootTableItem(Items.IRON_INGOT)
113-
.apply(SetItemCountFunction.setCount(UniformGenerator.between(3.0f, 5.0f)))));
101+
.withPool(singleRollPool(Items.POPPY, UniformGenerator.between(0.0f, 2.0f)))
102+
.withPool(singleRollPool(Items.IRON_INGOT, UniformGenerator.between(3.0f, 5.0f)));
103+
}
104+
105+
/**
106+
* Creates a single roll for counted loot.
107+
* @param item The item to roll for.
108+
* @param count The count for the loot.
109+
* @param functions Any functions that can be applied to the roll.
110+
* @return A single roll for a loot table.
111+
*/
112+
private LootTable.Builder singleRollCountedLoot(ItemLike item,
113+
NumberProvider count,
114+
LootItemFunction.Builder... functions) {
115+
LootPool.Builder pool = LootPool.lootPool()
116+
.setRolls(ConstantValue.exactly(1.0f))
117+
.add(LootItem.lootTableItem(item).apply(SetItemCountFunction.setCount(count)));
118+
119+
for (LootItemFunction.Builder function : functions) {
120+
pool.apply(function);
121+
}
122+
123+
return LootTable.lootTable().withPool(pool);
124+
}
125+
126+
127+
/**
128+
* Creates a single roll for a loot table.
129+
* @param item The item to roll for.
130+
* @param count The count for the loot.
131+
* @return A single roll for a loot table.
132+
*/
133+
private LootPool.Builder singleRollPool(ItemLike item,
134+
NumberProvider count) {
135+
return LootPool.lootPool()
136+
.setRolls(ConstantValue.exactly(1.0f))
137+
.add(LootItem.lootTableItem(item)
138+
.apply(SetItemCountFunction.setCount(count)));
114139
}
115140
}

src/main/java/com/bokmcdok/butterflies/network/protocol/common/custom/ClientBoundButterflyDataPacket.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public void write(@NotNull FriendlyByteBuf buffer) {
6868
collectionBuffer.writeInt(i.caterpillarLifespan());
6969
collectionBuffer.writeInt(i.chrysalisLifespan());
7070
collectionBuffer.writeInt(i.butterflyLifespan());
71-
collectionBuffer.writeResourceLocation(i.preferredFlower());
71+
collectionBuffer.writeResourceLocation(i.foodSource());
7272
collectionBuffer.writeEnum(i.type());
7373
collectionBuffer.writeEnum(i.diurnality());
7474
collectionBuffer.writeEnum(i.extraLandingBlocks());

0 commit comments

Comments
 (0)