Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/14.1-features' into 14.1-features
Browse files Browse the repository at this point in the history
  • Loading branch information
LtxProgrammer committed Nov 7, 2024
2 parents b2c422a + 7f4c486 commit 0981f4e
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 6 deletions.
41 changes: 41 additions & 0 deletions src/main/java/net/ltxprogrammer/changed/entity/MiningStrength.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package net.ltxprogrammer.changed.entity;

import com.mojang.serialization.Codec;
import com.mojang.serialization.DataResult;
import net.minecraft.util.StringRepresentable;
import net.minecraft.world.effect.MobEffect;
import net.minecraft.world.effect.MobEffects;

import java.util.Arrays;
import java.util.function.Predicate;

public enum MiningStrength implements StringRepresentable, Predicate<MobEffect> {
STRONG("strong", MobEffects.DIG_SPEED::equals),
NORMAL("normal", effect -> false),
WEAK("weak", MobEffects.DIG_SLOWDOWN::equals);

public static Codec<MiningStrength> CODEC = Codec.STRING.comapFlatMap(MiningStrength::fromSerial, MiningStrength::getSerializedName).orElse(NORMAL);

public final String serialName;
public final Predicate<MobEffect> shouldHaveEffect;

MiningStrength(String serialName, Predicate<MobEffect> shouldHaveEffect) {
this.serialName = serialName;
this.shouldHaveEffect = shouldHaveEffect;
}

@Override
public String getSerializedName() {
return serialName;
}

public static DataResult<MiningStrength> fromSerial(String name) {
return Arrays.stream(values()).filter(type -> type.serialName.equals(name))
.findFirst().map(DataResult::success).orElseGet(() -> DataResult.error(name + " is not a valid mining strength"));
}

@Override
public boolean test(MobEffect effect) {
return shouldHaveEffect.test(effect);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public enum UseItemMode implements IExtensibleEnum {
/**
* The variant can only hold one item out, in their mouth.
*/
MOUTH(true, true, false, true, false),
MOUTH(true, true, false, true, true),
/**
* The variant can't hold any items out, nor use them.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ public String toString() {
public final boolean reducedFall;
public final boolean canClimb;
public final VisionType visionType;
public final MiningStrength miningStrength;
public final int legCount;
public final boolean hasLegs;
public final UseItemMode itemUseMode;
Expand All @@ -185,13 +186,14 @@ public String toString() {
public TransfurVariant(Supplier<EntityType<T>> ctor, LatexType type,
float jumpStrength, BreatheMode breatheMode, float stepSize, boolean canGlide, int extraJumpCharges,
boolean reducedFall, boolean canClimb,
VisionType visionType, int legCount, UseItemMode itemUseMode, List<Class<? extends PathfinderMob>> scares, TransfurMode transfurMode,
VisionType visionType, MiningStrength miningStrength, int legCount, UseItemMode itemUseMode, List<Class<? extends PathfinderMob>> scares, TransfurMode transfurMode,
List<Function<EntityType<?>, ? extends AbstractAbility<?>>> abilities, float cameraZOffset, ResourceLocation sound) {
this.ctor = ctor;
this.type = type;
this.jumpStrength = jumpStrength;
this.breatheMode = breatheMode;
this.stepSize = stepSize;
this.miningStrength = miningStrength;
this.visionType = visionType;
this.canGlide = canGlide;
this.extraJumpCharges = extraJumpCharges;
Expand Down Expand Up @@ -361,6 +363,7 @@ public static class Builder<T extends ChangedEntity> {
boolean reducedFall = false;
boolean canClimb = false;
VisionType visionType = VisionType.NORMAL;
MiningStrength miningStrength = MiningStrength.NORMAL;
int legCount = 2;
UseItemMode itemUseMode = UseItemMode.NORMAL;
List<Class<? extends PathfinderMob>> scares = new ArrayList<>(ImmutableList.of(AbstractVillager.class));
Expand Down Expand Up @@ -504,6 +507,18 @@ public Builder<T> visionType(VisionType type) {
this.visionType = type; return this;
}

public Builder<T> weakMining() {
this.miningStrength = MiningStrength.WEAK; return this;
}

public Builder<T> weakMining(boolean v) {
this.miningStrength = v ? MiningStrength.WEAK : miningStrength; return this;
}

public Builder<T> miningStrength(MiningStrength strength) {
this.miningStrength = strength; return this;
}

public Builder<T> transfurMode(TransfurMode mode) {
this.transfurMode = mode; return this;
}
Expand Down Expand Up @@ -548,7 +563,7 @@ public Builder<T> sound(ResourceLocation event) {

public TransfurVariant<T> build() {
return new TransfurVariant<>(entityType, type, jumpStrength, breatheMode, stepSize, canGlide, extraJumpCharges,
reducedFall, canClimb, visionType, legCount, itemUseMode, scares, transfurMode, abilities, cameraZOffset, sound);
reducedFall, canClimb, visionType, miningStrength, legCount, itemUseMode, scares, transfurMode, abilities, cameraZOffset, sound);
}
}

Expand Down Expand Up @@ -623,6 +638,7 @@ public static TransfurVariant<?> fromJson(ResourceLocation id, JsonObject root,
List<Function<EntityType<?>, ? extends AbstractAbility<?>>> nAbilitiesList = abilities.stream().map(a -> (Function<EntityType<?>, AbstractAbility<?>>) type -> a).collect(Collectors.toList());

boolean nightVision = GsonHelper.getAsBoolean(root, "nightVision", false);
boolean weakMining = GsonHelper.getAsBoolean(root, "weakMining", false);
float speed = GsonHelper.getAsFloat(root, "groundSpeed", 1.0F) * 0.1f;
float swimSpeed = GsonHelper.getAsFloat(root, "swimSpeed", 1.0F);
int additionalHealth = GsonHelper.getAsInt(root, "additionalHealth", 4);
Expand All @@ -639,6 +655,8 @@ public static TransfurVariant<?> fromJson(ResourceLocation id, JsonObject root,
GsonHelper.getAsBoolean(root, "canClimb", false),
VisionType.fromSerial(GsonHelper.getAsString(root, "visionType", (nightVision ? VisionType.NIGHT_VISION : VisionType.NORMAL).getSerializedName()))
.result().orElse(VisionType.NORMAL),
MiningStrength.fromSerial(GsonHelper.getAsString(root, "miningStrength", (weakMining ? MiningStrength.WEAK : MiningStrength.NORMAL).getSerializedName()))
.result().orElse(MiningStrength.NORMAL),
GsonHelper.getAsInt(root, "legCount", 2),
UseItemMode.valueOf(GsonHelper.getAsString(root, "itemUseMode", UseItemMode.NORMAL.toString())),
scares,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@ public class TransfurVariantInstance<T extends ChangedEntity> {
public boolean abilityKeyState = false;
public TransfurMode transfurMode;
public VisionType visionType;
public MiningStrength miningStrength;
public int ageAsVariant = 0;
protected int air = -100;
protected int jumpCharges = 0;
Expand Down Expand Up @@ -219,6 +220,7 @@ public TransfurVariantInstance(TransfurVariant<T> parent, Player host) {

this.transfurMode = parent.transfurMode;
this.visionType = parent.visionType;
this.miningStrength = parent.miningStrength;

var builder = new ImmutableMap.Builder<AbstractAbility<?>, AbstractAbilityInstance>();
parent.abilities.forEach(abilityFunction -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ public class ChangedTransfurVariants {
public static final RegistryObject<TransfurVariant<GasWolf>> GAS_WOLF = register("form_gas_wolf",
TransfurVariant.Builder.of(ChangedEntities.GAS_WOLF).stepSize(0.7f).sound(ChangedSounds.SOUND3.getLocation()));
public static final RegistryObject<TransfurVariant<PooltoyWolf>> POOLTOY_WOLF = register("form_pooltoy_wolf",
TransfurVariant.Builder.of(ChangedEntities.POOLTOY_WOLF).breatheMode(TransfurVariant.BreatheMode.NONE).transfurMode(TransfurMode.NONE).stepSize(0.7f));
TransfurVariant.Builder.of(ChangedEntities.POOLTOY_WOLF).breatheMode(TransfurVariant.BreatheMode.NONE).weakMining().transfurMode(TransfurMode.NONE).stepSize(0.7f));
public static final RegistryObject<TransfurVariant<Beifeng>> BEIFENG = register("form_beifeng",
TransfurVariant.Builder.of(ChangedEntities.BEIFENG).stepSize(0.7f).sound(ChangedSounds.SOUND3.getLocation()));
public static final RegistryObject<TransfurVariant<WhiteLatexWolfFemale>> WHITE_LATEX_WOLF_FEMALE = register("form_white_latex_wolf/female",
Expand All @@ -42,7 +42,7 @@ public class ChangedTransfurVariants {
public static final RegistryObject<TransfurVariant<PhageLatexWolfMale>> PHAGE_LATEX_WOLF_MALE = register("form_phage_latex_wolf/male",
TransfurVariant.Builder.of(ChangedEntities.PHAGE_LATEX_WOLF_MALE).stepSize(0.7f).faction(LatexType.DARK_LATEX).addAbility(ChangedAbilities.TOGGLE_WAVE_VISION));
public static final RegistryObject<TransfurVariant<DarkLatexWolfPup>> DARK_LATEX_WOLF_PUP = register("form_dark_latex_wolf_pup",
TransfurVariant.Builder.of(ChangedEntities.DARK_LATEX_WOLF_PUP).stepSize(0.7f).faction(LatexType.DARK_LATEX).addAbility(ChangedAbilities.TOGGLE_WAVE_VISION).transfurMode(TransfurMode.NONE).holdItemsInMouth().reducedFall().addAbility(ChangedAbilities.PUDDLE));
TransfurVariant.Builder.of(ChangedEntities.DARK_LATEX_WOLF_PUP).stepSize(0.7f).faction(LatexType.DARK_LATEX).weakMining().addAbility(ChangedAbilities.TOGGLE_WAVE_VISION).transfurMode(TransfurMode.NONE).holdItemsInMouth().reducedFall().addAbility(ChangedAbilities.PUDDLE));
public static final RegistryObject<TransfurVariant<DarkLatexWolfPartial>> DARK_LATEX_WOLF_PARTIAL = register("form_dark_latex_wolf_partial",
TransfurVariant.Builder.of(ChangedEntities.DARK_LATEX_WOLF_PARTIAL).faction(LatexType.DARK_LATEX).transfurMode(TransfurMode.NONE));
public static final RegistryObject<TransfurVariant<DarkLatexYufeng>> DARK_LATEX_YUFENG = register("form_dark_latex_yufeng",
Expand All @@ -52,7 +52,7 @@ public class ChangedTransfurVariants {
public static final RegistryObject<TransfurVariant<LatexBee>> LATEX_BEE = register("form_latex_bee",
TransfurVariant.Builder.of(ChangedEntities.LATEX_BEE).extraJumps(4).reducedFall().extraHands().addAbility(ChangedAbilities.CREATE_HONEYCOMB).breatheMode(TransfurVariant.BreatheMode.WEAK).absorbing());
public static final RegistryObject<TransfurVariant<LatexBenignWolf>> LATEX_BENIGN_WOLF = register("form_latex_benign_wolf",
TransfurVariant.Builder.of(ChangedEntities.BENIGN_LATEX_WOLF).noVision().absorbing().disableItems().jumpStrength(0.5F));
TransfurVariant.Builder.of(ChangedEntities.BENIGN_LATEX_WOLF).noVision().absorbing().disableItems().weakMining().jumpStrength(0.5F));
public static final RegistryObject<TransfurVariant<LatexBlueDragon>> LATEX_BLUE_DRAGON = register("form_latex_blue_dragon",
TransfurVariant.Builder.of(ChangedEntities.BLUE_LATEX_DRAGON).stepSize(0.7f));
public static final RegistryObject<TransfurVariant<LatexBlueWolf>> LATEX_BLUE_WOLF = register("form_latex_blue_wolf",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,9 @@ public void hasEffect(MobEffect effect, CallbackInfoReturnable<Boolean> callback
if (variant.visionType.test(effect))
callback.setReturnValue(true);

if (variant.miningStrength.test(effect))
callback.setReturnValue(true);

if (effect.equals(MobEffects.NIGHT_VISION)) {
if (variant.getChangedEntity().getLatexType() == LatexType.WHITE_LATEX && WhiteLatexTransportInterface.isEntityInWhiteLatex(player))
callback.setReturnValue(true);
Expand All @@ -137,6 +140,9 @@ public void getEffect(MobEffect effect, CallbackInfoReturnable<MobEffectInstance
if (variant.visionType.test(effect))
callback.setReturnValue(new MobEffectInstance(effect, 300, 1, false, false));

if (variant.miningStrength.test(effect))
callback.setReturnValue(new MobEffectInstance(effect, 300, 1, false, false));

if (effect.equals(MobEffects.NIGHT_VISION)) {
if (variant.getChangedEntity().getLatexType() == LatexType.WHITE_LATEX && WhiteLatexTransportInterface.isEntityInWhiteLatex(player))
callback.setReturnValue(new MobEffectInstance(MobEffects.NIGHT_VISION, 300, 1, false, false));
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 0981f4e

Please sign in to comment.