Skip to content

Commit f782597

Browse files
committed
Fix #105 and #106
1 parent c7151ae commit f782597

File tree

7 files changed

+62
-49
lines changed

7 files changed

+62
-49
lines changed

CHANGELOG.txt

Lines changed: 0 additions & 1 deletion
This file was deleted.

LICENSE

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
Copyright (c) 2016-2020 Skyler James
1+
Copyright (c) 2016-2022 Skyler James
22

33
This software is provided 'as-is', without any express or implied warranty. In no event will the author(s) be held liable for any damages arising from the use of this software.
44

gradle.properties

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,14 @@ mappings_version=1.19.2
1212
# Mod properties
1313
mod_name=Extra-Golems
1414
mod_id=golems
15-
mod_version=19.2.0
15+
mod_version=19.2.1
1616
mod_authors="skyjay1 and the MMD Team"
1717
mod_description="Adds dozens of golems with unique textures and abilities!"
1818
maven_group=com.mcmoddev.golems
1919
archives_base_name=extragolems
2020
# Dependencies
21-
forge_version=43.0.2
22-
forge_version_range=[42,)
23-
loader_version_range=[42,)
21+
forge_version=43.1.2
22+
forge_version_range=[43.1,)
23+
loader_version_range=[43,)
2424
top_proj=245211
2525
top_file=3871444

src/main/java/com/mcmoddev/golems/EGConfig.java

Lines changed: 25 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,11 @@
11
package com.mcmoddev.golems;
22

3-
import com.mcmoddev.golems.container.GolemContainer;
4-
import net.minecraft.ResourceLocationException;
53
import net.minecraft.resources.ResourceLocation;
64
import net.minecraftforge.common.ForgeConfigSpec;
75

86
import java.time.LocalDateTime;
97
import java.time.Month;
10-
import java.util.ArrayList;
118
import java.util.List;
12-
import java.util.Optional;
139

1410
public final class EGConfig {
1511

@@ -22,11 +18,21 @@ public final class EGConfig {
2218
private final ForgeConfigSpec.IntValue VILLAGER_GOLEM_SPAWN_CHANCE;
2319
private final ForgeConfigSpec.ConfigValue<List<? extends String>> VILLAGER_GOLEM_SPAWN_LIST;
2420
private static final String[] defaultVillagerGolemSpawns = {
25-
"golems:bookshelf", "golems:clay", "golems:coal", "golems:crafting",
26-
"golems:glass", "golems:glowstone", "golems:hay", "golems:leaves",
27-
"golems:log", "golems:melon", "golems:moss", "golems:mushroom", "golems:obsidian",
28-
"golems:quartz", "golems:red_sandstone", "golems:sandstone",
29-
"golems:terracotta", "golems:wool"
21+
new ResourceLocation(ExtraGolems.MODID, "bookshelf").toString(),
22+
new ResourceLocation(ExtraGolems.MODID, "clay").toString(),
23+
new ResourceLocation(ExtraGolems.MODID, "coal").toString(),
24+
new ResourceLocation(ExtraGolems.MODID, "crafting").toString(),
25+
new ResourceLocation(ExtraGolems.MODID, "glass").toString(),
26+
new ResourceLocation(ExtraGolems.MODID, "glowstone").toString(),
27+
new ResourceLocation(ExtraGolems.MODID, "hay").toString(),
28+
new ResourceLocation(ExtraGolems.MODID, "leaves").toString(),
29+
new ResourceLocation(ExtraGolems.MODID, "log").toString(),
30+
new ResourceLocation(ExtraGolems.MODID, "melon").toString(),
31+
new ResourceLocation(ExtraGolems.MODID, "moss").toString(),
32+
new ResourceLocation(ExtraGolems.MODID, "mushroom").toString(),
33+
new ResourceLocation(ExtraGolems.MODID, "obsidian").toString(),
34+
new ResourceLocation(ExtraGolems.MODID, "terracotta").toString(),
35+
new ResourceLocation(ExtraGolems.MODID, "wool").toString()
3036
};
3137

3238
private boolean aprilFirst;
@@ -44,23 +50,23 @@ public final class EGConfig {
4450
public EGConfig(final ForgeConfigSpec.Builder builder) {
4551
// Global values
4652
builder.push("general");
47-
this.BEDROCK_GOLEM_CREATIVE_ONLY = builder.comment("When true, only players in creative mode can use a Bedrock Golem spawn item")
53+
BEDROCK_GOLEM_CREATIVE_ONLY = builder.comment("When true, only players in creative mode can use a Bedrock Golem spawn item")
4854
.define("bedrock_golem_creative_only", true);
49-
this.PUMPKIN_BUILDS_GOLEMS = builder.comment("When true, pumpkins can be used to build this mod's golems")
55+
PUMPKIN_BUILDS_GOLEMS = builder.comment("When true, pumpkins can be used to build this mod's golems")
5056
.define("pumpkin_builds_golems", false);
51-
this.ENABLE_FRIENDLY_FIRE = builder.comment("When enabled, attacking a player-built entity will make it attack you")
57+
ENABLE_FRIENDLY_FIRE = builder.comment("When enabled, attacking a player-built entity will make it attack you")
5258
.define("friendly_fire", true);
53-
this.ENABLE_USE_SPELL_ITEM = builder
59+
ENABLE_USE_SPELL_ITEM = builder
5460
.comment("When enabled, players can use the spell item on a carved pumpkin to convert it to a golem head in-world")
5561
.define("use_spell", true);
56-
this.ENABLE_HOLIDAYS = builder.comment("Super secret special days")
62+
ENABLE_HOLIDAYS = builder.comment("Super secret special days")
5763
.define("holidays", true);
58-
this.VILLAGER_GOLEM_SPAWN_CHANCE = builder.comment("Percent chance for a villager to summon an Extra Golems entity")
64+
VILLAGER_GOLEM_SPAWN_CHANCE = builder.comment("Percent chance for a villager to summon an Extra Golems entity")
5965
.defineInRange("villager_summon_chance", 60, 0, 100);
60-
this.ENABLE_HEAL_GOLEMS = builder.comment("When enabled, giving blocks and items to golems can restore health")
66+
ENABLE_HEAL_GOLEMS = builder.comment("When enabled, giving blocks and items to golems can restore health")
6167
.define("heal_golems", true);
62-
this.VILLAGER_GOLEM_SPAWN_LIST = builder.comment("Golems that can be summoned by villagers", "(Duplicate entries increase chances)")
63-
.defineList("villager_summon_golems", List.of(defaultVillagerGolemSpawns), o -> o instanceof String);
68+
VILLAGER_GOLEM_SPAWN_LIST = builder.comment("Golems that can be summoned by villagers", "(Duplicate entries increase chances)")
69+
.defineList("villager_summon_golems", List.of(defaultVillagerGolemSpawns), o -> o instanceof String s && ResourceLocation.tryParse(s) != null);
6470

6571
builder.pop();
6672
}
@@ -114,25 +120,6 @@ public void bake() {
114120
enableHolidays = ENABLE_HOLIDAYS.get();
115121
enableHealGolems = ENABLE_HEAL_GOLEMS.get();
116122
villagerGolemSpawnChance = VILLAGER_GOLEM_SPAWN_CHANCE.get();
117-
villagerGolemSpawnList = loadVillagerGolemList(VILLAGER_GOLEM_SPAWN_LIST.get());
118-
}
119-
120-
121-
private static List<ResourceLocation> loadVillagerGolemList(List<? extends String> config) {
122-
final List<ResourceLocation> list = new ArrayList<>();
123-
// load all villager golem candidates from config
124-
for (final String s : config) {
125-
// parse each entry as resource location with error-catching
126-
if (s != null && !s.isEmpty()) {
127-
try {
128-
ResourceLocation golemId = ResourceLocation.tryParse(s);
129-
final Optional<GolemContainer> container = ExtraGolems.GOLEM_CONTAINERS.get(golemId);
130-
container.ifPresent(c -> list.add(new ResourceLocation(s)));
131-
} catch (ResourceLocationException e) {
132-
ExtraGolems.LOGGER.error("Invalid golem ID in config file for villager_summon_golems: \"" + s + "\"");
133-
}
134-
}
135-
}
136-
return list;
123+
villagerGolemSpawnList = VILLAGER_GOLEM_SPAWN_LIST.get().stream().map(ResourceLocation::tryParse).toList();
137124
}
138125
}

src/main/java/com/mcmoddev/golems/entity/GolemBase.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@
6969

7070
import javax.annotation.Nullable;
7171
import java.util.List;
72+
import java.util.Optional;
7273

7374
/**
7475
* Base class for all golems in this mod.
@@ -128,10 +129,15 @@ public void setMaterial(final ResourceLocation materialIn) {
128129
if (materialIn.equals(material)) {
129130
return;
130131
}
132+
Optional<GolemContainer> oContainer = ExtraGolems.GOLEM_CONTAINERS.get(materialIn);
133+
if(!oContainer.isPresent()) {
134+
ExtraGolems.LOGGER.error("Failed to load golem container for '" + materialIn.toString() + "'");
135+
return;
136+
}
131137
// update material and container
132138
this.getEntityData().set(MATERIAL, materialIn.toString());
133139
this.material = materialIn;
134-
this.container = ExtraGolems.GOLEM_CONTAINERS.get(materialIn).orElse(GolemContainer.EMPTY);
140+
this.container = oContainer.get();
135141
this.attributes = new AttributeMap(container.getAttributeSupplier().get().build());
136142
this.setInvulnerable(container.getAttributes().getArmor() > MAX_ARMOR);
137143
// clear description

src/main/java/com/mcmoddev/golems/event/EGForgeEvents.java

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@
1717
import net.minecraft.util.RandomSource;
1818
import net.minecraft.util.SpawnUtil;
1919
import net.minecraft.world.entity.EntityType;
20+
import net.minecraft.world.entity.LivingEntity;
2021
import net.minecraft.world.entity.Mob;
2122
import net.minecraft.world.entity.MobSpawnType;
23+
import net.minecraft.world.entity.ai.memory.MemoryModuleType;
2224
import net.minecraft.world.entity.ai.sensing.GolemSensor;
2325
import net.minecraft.world.entity.animal.IronGolem;
2426
import net.minecraft.world.entity.npc.Villager;
@@ -110,6 +112,7 @@ public static void onLivingUpdate(final LivingEvent.LivingTickEvent event) {
110112
&& event.getEntity() instanceof Villager villager
111113
&& !villager.isSleeping()
112114
&& villager.tickCount % 90L == 0L
115+
&& !checkForNearbyGolem(villager)
113116
&& villager.wantsToSpawnGolem(villager.tickCount)
114117
&& villager.getRandom().nextInt(100) < ExtraGolems.CONFIG.villagerSummonChance()) {
115118
// locate nearby villagers who also want to summon a golem
@@ -145,8 +148,26 @@ public static void onLivingUpdate(final LivingEvent.LivingTickEvent event) {
145148
* @return a random golem material from the config, or the empty material if the config is empty
146149
*/
147150
private static ResourceLocation getGolemToSpawn(final BlockPos pos, final RandomSource random) {
148-
final List<ResourceLocation> options = ExtraGolems.CONFIG.getVillagerGolems();
151+
final List<? extends ResourceLocation> options = ExtraGolems.CONFIG.getVillagerGolems();
149152
final ResourceLocation choice = options.isEmpty() ? GolemContainer.EMPTY_MATERIAL : options.get(random.nextInt(options.size()));
150153
return choice;
151154
}
155+
156+
/**
157+
* Checks if the nearest living entity memory contains any golem or subclass.
158+
* Required because the version used by villagers only checks entity type.
159+
* @param villager the villager
160+
* @return true if a nearby golem was detected.
161+
*/
162+
private static boolean checkForNearbyGolem(LivingEntity villager) {
163+
Optional<List<LivingEntity>> optional = villager.getBrain().getMemory(MemoryModuleType.NEAREST_LIVING_ENTITIES);
164+
if (optional.isPresent()) {
165+
boolean flag = optional.get().stream().anyMatch(e -> e instanceof IronGolem);
166+
if (flag) {
167+
GolemSensor.golemDetected(villager);
168+
return true;
169+
}
170+
}
171+
return false;
172+
}
152173
}

src/main/resources/META-INF/mods.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
# The name of the mod loader type to load
22
modLoader="javafml"
33
# A version range to match for said mod loader
4-
loaderVersion="[42,)"
4+
loaderVersion="[43,)"
55
# The license for your mod. This is mandatory metadata and allows for easier comprehension of your redistributive properties.
66
license="zlib License"
77
# A URL to refer people to when problems occur with this mod
88
issueTrackerURL="https://github.com/MinecraftModDevelopmentMods/Extra-Golems/issues"
99

1010
[[mods]]
1111
modId="golems"
12-
version="19.2.0"
12+
version="19.2.1"
1313
displayName="Extra Golems"
1414
credits="TheGlitch76, jriwanek, AtelierAmber, and translators - Thanks!"
1515
authors="skyjay1 and the MMD Team"
@@ -18,6 +18,6 @@ issueTrackerURL="https://github.com/MinecraftModDevelopmentMods/Extra-Golems/iss
1818
[[dependencies.golems]]
1919
modId="forge"
2020
mandatory=true
21-
versionRange="[42,)"
21+
versionRange="[43.1,)"
2222
ordering="NONE"
2323
side="BOTH"

0 commit comments

Comments
 (0)