Skip to content

Commit ff8d7b4

Browse files
committed
Merge branch '1.21.1-neoforge-heartache' into 1.21.1-neoforge
2 parents 135b053 + 763def6 commit ff8d7b4

9 files changed

Lines changed: 140 additions & 9 deletions

File tree

‎src/main/java/de/dafuqs/spectrum/SpectrumCommon.java‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,8 @@ public SpectrumCommon(ModContainer container, IEventBus modBus) {
223223
SpectrumEventListeners.register();
224224
logInfo("Registering Tree Decorator Types...");
225225
SpectrumTreeDecoratorTypes.register(modBus);
226+
logInfo("Registering Cat Variants...");
227+
SpectrumCatVariants.register(modBus);
226228

227229
logInfo("Registering Attachments...");
228230
SpectrumAttachmentTypes.register(modBus);
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
package de.dafuqs.spectrum.mixin;
2+
3+
import de.dafuqs.spectrum.registries.*;
4+
import net.minecraft.core.*;
5+
import net.minecraft.tags.*;
6+
import net.minecraft.util.*;
7+
import net.minecraft.world.entity.*;
8+
import net.minecraft.world.entity.ai.goal.*;
9+
import net.minecraft.world.entity.ai.util.*;
10+
import net.minecraft.world.entity.animal.*;
11+
import net.minecraft.world.entity.animal.axolotl.*;
12+
import net.minecraft.world.entity.monster.*;
13+
import net.minecraft.world.level.*;
14+
import net.minecraft.world.level.block.state.*;
15+
import net.minecraft.world.level.pathfinder.*;
16+
import net.minecraft.world.phys.*;
17+
import org.spongepowered.asm.mixin.*;
18+
import org.spongepowered.asm.mixin.injection.*;
19+
import org.spongepowered.asm.mixin.injection.callback.*;
20+
21+
import javax.annotation.*;
22+
import java.util.*;
23+
import java.util.function.*;
24+
25+
@Mixin(Cat.class)
26+
public abstract class CatMixin extends TamableAnimal {
27+
28+
protected CatMixin(EntityType<? extends TamableAnimal> entityType, Level level) {
29+
super(entityType, level);
30+
}
31+
32+
@Inject(method = "setVariant(Lnet/minecraft/core/Holder;)V", at = @At("HEAD"))
33+
public void setVariant(Holder<CatVariant> variant, CallbackInfo ci) {
34+
if(variant.equals(SpectrumCatVariants.CATUS)) {
35+
this.setPathfindingMalus(PathType.WATER_BORDER, 0.0F);
36+
37+
goalSelector.getAvailableGoals().stream()
38+
.filter( wrappedGoal -> wrappedGoal != null && wrappedGoal.getGoal() instanceof WaterAvoidingRandomStrollGoal)
39+
.forEach(wrappedGoal -> goalSelector.removeGoal(wrappedGoal.getGoal()));
40+
goalSelector.addGoal(5, new CatusStrollGoal((Cat) (Object) this, 1.0F));
41+
} else if(variant.equals(SpectrumCatVariants.FELIS)) {
42+
goalSelector.getAvailableGoals().stream()
43+
.filter(wrappedGoal -> wrappedGoal != null && wrappedGoal.getGoal() instanceof TemptGoal)
44+
.forEach(wrappedGoal -> goalSelector.removeGoal(wrappedGoal.getGoal()));
45+
goalSelector.addGoal(4, new TemptGoal(this, 1.75, (stack) -> stack.is(ItemTags.CAT_FOOD), false));
46+
}
47+
}
48+
49+
private static class CatusStrollGoal extends RandomStrollGoal {
50+
51+
private static final int HORIZONTAL_RADIUS = 10;
52+
private static final int VERTICAL_DISTANCE_SOLID = 2;
53+
54+
private static final int HORIZONTAL_RADIUS_WATER = 7;
55+
private static final int VERTICAL_DISTANCE_WATER = 1;
56+
57+
public CatusStrollGoal(PathfinderMob mob, double speedModifier) {
58+
super(mob, speedModifier);
59+
}
60+
61+
@Nullable
62+
protected Vec3 getPosition() {
63+
List<BlockPos> validShore = new ArrayList<>();
64+
65+
for(BlockPos pos : BlockPos.betweenClosed(Mth.floor(this.mob.getX() - HORIZONTAL_RADIUS_WATER), Mth.floor(this.mob.getY() - VERTICAL_DISTANCE_WATER), Mth.floor(this.mob.getZ() - HORIZONTAL_RADIUS_WATER), Mth.floor(this.mob.getX() + HORIZONTAL_RADIUS_WATER), this.mob.getBlockY() + VERTICAL_DISTANCE_WATER, Mth.floor(this.mob.getZ() + HORIZONTAL_RADIUS_WATER))) {
66+
if (this.mob.level().getFluidState(pos).is(FluidTags.WATER)) {
67+
for(Direction direction : Direction.Plane.HORIZONTAL) {
68+
BlockPos relativePos = pos.relative(direction);
69+
BlockState relativeState = this.mob.level().getBlockState(relativePos);
70+
if(relativeState.isSolid()) {
71+
validShore.add(relativePos);
72+
}
73+
}
74+
}
75+
}
76+
77+
if(!validShore.isEmpty()) {
78+
RandomSource random = this.mob.getRandom();
79+
return Vec3.atCenterOf(validShore.get(random.nextInt(validShore.size())));
80+
}
81+
82+
return DefaultRandomPos.getPos(this.mob, HORIZONTAL_RADIUS, VERTICAL_DISTANCE_SOLID);
83+
}
84+
85+
}
86+
87+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
package de.dafuqs.spectrum.registries;
2+
3+
import de.dafuqs.spectrum.*;
4+
import net.minecraft.core.*;
5+
import net.minecraft.core.registries.*;
6+
import net.minecraft.resources.*;
7+
import net.minecraft.world.entity.animal.*;
8+
import net.neoforged.bus.api.*;
9+
import net.neoforged.neoforge.registries.*;
10+
11+
import java.util.function.*;
12+
13+
public class SpectrumCatVariants {
14+
15+
private static final DeferredRegister<CatVariant> REGISTRAR = DeferredRegister.create(Registries.CAT_VARIANT, SpectrumCommon.MOD_ID);
16+
17+
public static final Holder<CatVariant> FELIS = register("felis", () -> new CatVariant(SpectrumCommon.locate("textures/entity/cat/felis.png")));
18+
public static final Holder<CatVariant> CATUS = register("catus", () -> new CatVariant(SpectrumCommon.locate("textures/entity/cat/catus.png")));
19+
20+
private static Holder<CatVariant> register(String id, Supplier<CatVariant> entry) {
21+
return REGISTRAR.register(id, entry);
22+
}
23+
24+
public static void register(IEventBus modBus) {
25+
REGISTRAR.register(modBus);
26+
}
27+
28+
}

‎src/main/java/de/dafuqs/spectrum/registries/SpectrumEventListeners.java‎

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -134,24 +134,28 @@ public static InteractionResult exchangeBlock(PlayerInteractEvent.LeftClickBlock
134134

135135
@SubscribeEvent
136136
public static void playerInteraction(PlayerInteractEvent.EntityInteractSpecific event) {
137-
if (event.getLevel().isClientSide()) return;
138-
139137
Entity target = event.getTarget();
140138
Component entityCustomName = target.getCustomName();
141-
if (entityCustomName == null || !(target instanceof Cat cat)) return;
139+
if (!(target instanceof Cat cat)) return;
142140

143141
Player player = event.getEntity();
144142
InteractionHand hand = event.getHand();
145143
ItemStack itemStack = player.getItemInHand(hand);
146144

145+
if(cat.getVariant().equals(SpectrumCatVariants.FELIS) && cat.isFood(itemStack)) {
146+
cat.playSound(SoundEvents.CAT_PURR);
147+
cat.handleEntityEvent(EntityEvent.TAMING_SUCCEEDED);
148+
}
149+
150+
if (entityCustomName == null) return;
151+
if (event.getLevel().isClientSide()) return;
152+
147153
String customName = target.getCustomName().getString().toUpperCase(Locale.ROOT);
148154
boolean howMany = customName.equals("AAA") || customName.equals("AAA ❣");
149-
if (player instanceof ServerPlayer serverPlayerEntity) {
150-
if (itemStack.is(SpectrumItems.STRATINE_GEM) && cat.hasEffect(MobEffects.LEVITATION) && howMany) {
151-
Support.grantAdvancementCriterion(serverPlayerEntity, ResourceLocation.fromNamespaceAndPath("spectrum", "midgame/become_enlightened"), "confirmed");
152-
cat.removeEffect(MobEffects.LEVITATION);
153-
cat.addEffect(new MobEffectInstance(MobEffects.SLOW_FALLING, 600, 1));
154-
}
155+
if (howMany && player instanceof ServerPlayer serverPlayerEntity && itemStack.is(SpectrumItems.STRATINE_GEM) && cat.hasEffect(MobEffects.LEVITATION)) {
156+
Support.grantAdvancementCriterion(serverPlayerEntity, ResourceLocation.fromNamespaceAndPath("spectrum", "midgame/become_enlightened"), "confirmed");
157+
cat.removeEffect(MobEffects.LEVITATION);
158+
cat.addEffect(new MobEffectInstance(MobEffects.SLOW_FALLING, 600, 1));
155159
}
156160
}
157161

4.9 KB
Loading
1.55 KB
Loading
4.18 KB
Binary file not shown.

‎src/main/resources/data/spectrum/worldgen/template_pool/city_below/buildings.json‎

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,15 @@
108108
"location": "spectrum:city_below/streets/trees",
109109
"processors": "minecraft:empty"
110110
}
111+
},
112+
{
113+
"weight": 1,
114+
"element": {
115+
"element_type": "minecraft:single_pool_element",
116+
"projection": "rigid",
117+
"location": "spectrum:city_below/catus",
118+
"processors": "minecraft:empty"
119+
}
111120
}
112121
]
113122
}

‎src/main/resources/spectrum.mixins.json‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
"BlockMixin",
1515
"BrainMixin",
1616
"BrewingRecipeRegistryMixin",
17+
"CatMixin",
1718
"ChunkNoiseSamplerMixin",
1819
"CropAndStemBlockMixin",
1920
"EatBerriesGoalMixin",

0 commit comments

Comments
 (0)