Skip to content

Commit

Permalink
Fix some errors, mostly related to MobEffect -> Holder<MobEffect>
Browse files Browse the repository at this point in the history
  • Loading branch information
artemisSystem committed Oct 20, 2024
1 parent 63a431e commit 83e6ed3
Show file tree
Hide file tree
Showing 17 changed files with 86 additions and 85 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
package vazkii.botania.fabric.block;

import net.minecraft.core.BlockPos;
import net.minecraft.core.Holder;
import net.minecraft.core.particles.DustParticleOptions;
import net.minecraft.util.RandomSource;
import net.minecraft.world.effect.MobEffect;
Expand Down Expand Up @@ -43,7 +44,7 @@ public class FabricSpecialFlowerBlock extends FlowerBlock implements EntityBlock
private static final VoxelShape SHAPE = box(4.8, 0, 4.8, 12.8, 16, 12.8);
private final Supplier<BlockEntityType<? extends SpecialFlowerBlockEntity>> blockEntityType;

public FabricSpecialFlowerBlock(MobEffect stewEffect, int stewDuration, Properties props, Supplier<BlockEntityType<? extends SpecialFlowerBlockEntity>> blockEntityType) {
public FabricSpecialFlowerBlock(Holder<MobEffect> stewEffect, int stewDuration, Properties props, Supplier<BlockEntityType<? extends SpecialFlowerBlockEntity>> blockEntityType) {
super(stewEffect, stewDuration, props);
this.blockEntityType = blockEntityType;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import net.fabricmc.loader.api.FabricLoader;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.Holder;
import net.minecraft.core.NonNullList;
import net.minecraft.core.registries.Registries;
import net.minecraft.network.FriendlyByteBuf;
Expand Down Expand Up @@ -460,7 +461,7 @@ public boolean isSpecialFlowerBlock(Block b) {
}

@Override
public FlowerBlock createSpecialFlowerBlock(MobEffect effect, int effectDuration, BlockBehaviour.Properties props, Supplier<BlockEntityType<? extends SpecialFlowerBlockEntity>> beType) {
public FlowerBlock createSpecialFlowerBlock(Holder<MobEffect> effect, int effectDuration, BlockBehaviour.Properties props, Supplier<BlockEntityType<? extends SpecialFlowerBlockEntity>> beType) {
return new FabricSpecialFlowerBlock(effect, effectDuration, props, beType);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package vazkii.botania.forge.block;

import net.minecraft.core.BlockPos;
import net.minecraft.core.Holder;
import net.minecraft.util.RandomSource;
import net.minecraft.world.effect.MobEffect;
import net.minecraft.world.entity.LivingEntity;
Expand Down Expand Up @@ -33,10 +34,11 @@ public class ForgeSpecialFlowerBlock extends FlowerBlock implements EntityBlock
private static final VoxelShape SHAPE = box(4.8, 0, 4.8, 12.8, 16, 12.8);
private final Supplier<BlockEntityType<? extends SpecialFlowerBlockEntity>> blockEntityType;

public ForgeSpecialFlowerBlock(MobEffect stewEffect, int stewDuration, Properties props, Supplier<BlockEntityType<? extends SpecialFlowerBlockEntity>> blockEntityType) {
public ForgeSpecialFlowerBlock(Holder<MobEffect> stewEffect, int stewDuration, Properties props, Supplier<BlockEntityType<? extends SpecialFlowerBlockEntity>> blockEntityType) {
super(/* the only godforsaken reason why this class needs to be duplicated for each loader
is so that we can add a "() ->" here. Amazing. */
() -> stewEffect, stewDuration, props);
// TODO: I think we can remove this now, the superclass is no longer patched
stewEffect, stewDuration, props);
this.blockEntityType = blockEntityType;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.Holder;
import net.minecraft.core.NonNullList;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.network.protocol.Packet;
Expand Down Expand Up @@ -435,9 +436,9 @@ public boolean isSpecialFlowerBlock(Block b) {
}

@Override
public FlowerBlock createSpecialFlowerBlock(MobEffect effect, int effectDuration,
BlockBehaviour.Properties props,
Supplier<BlockEntityType<? extends SpecialFlowerBlockEntity>> beType) {
public FlowerBlock createSpecialFlowerBlock(Holder<MobEffect> effect, int effectDuration,
BlockBehaviour.Properties props,
Supplier<BlockEntityType<? extends SpecialFlowerBlockEntity>> beType) {
return new ForgeSpecialFlowerBlock(effect, effectDuration, props, beType);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.mojang.serialization.Codec;
import com.mojang.serialization.codecs.RecordCodecBuilder;

import net.minecraft.core.Holder;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.util.ExtraCodecs;
import net.minecraft.world.effect.MobEffect;
Expand All @@ -15,25 +16,25 @@
public class LooniumMobEffectToApply {
public static final Codec<LooniumMobEffectToApply> CODEC = RecordCodecBuilder.create(
instance -> instance.group(
BuiltInRegistries.MOB_EFFECT.byNameCodec().fieldOf("effect").forGetter(me -> me.effect),
BuiltInRegistries.MOB_EFFECT.holderByNameCodec().fieldOf("effect").forGetter(me -> me.effect),
ExtraCodecs.POSITIVE_INT.optionalFieldOf("duration", MobEffectInstance.INFINITE_DURATION)
.forGetter(me -> me.duration),
Codec.intRange(0, 255).optionalFieldOf("amplifier", 0)
.forGetter(me -> me.amplifier)
).apply(instance, LooniumMobEffectToApply::new)
);

private final MobEffect effect;
private final Holder<MobEffect> effect;
private final int duration;
private final int amplifier;

private LooniumMobEffectToApply(MobEffect effect, int duration, int amplifier) {
private LooniumMobEffectToApply(Holder<MobEffect> effect, int duration, int amplifier) {
this.effect = effect;
this.duration = duration;
this.amplifier = amplifier;
}

public static Builder effect(MobEffect effect) {
public static Builder effect(Holder<MobEffect> effect) {
return new Builder(effect);
}

Expand All @@ -51,7 +52,7 @@ public String toString() {
'}';
}

public MobEffect getEffect() {
public Holder<MobEffect> getEffect() {
return effect;
}

Expand All @@ -78,11 +79,11 @@ public int hashCode() {
}

public static class Builder {
private final MobEffect effect;
private final Holder<MobEffect> effect;
private int duration = MobEffectInstance.INFINITE_DURATION;
private int amplifier = 0;

private Builder(MobEffect effect) {
private Builder(Holder<MobEffect> effect) {
this.effect = effect;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
import net.minecraft.resources.ResourceLocation;
import net.minecraft.util.ExtraCodecs;
import net.minecraft.util.random.WeightedRandomList;
import net.minecraft.world.entity.animal.Cod;
import net.minecraft.world.level.levelgen.structure.StructureSpawnOverride;

import vazkii.botania.api.BotaniaAPI;
Expand All @@ -16,45 +17,46 @@
import java.util.Optional;
import java.util.function.Function;

import static vazkii.botania.common.lib.ResourceLocationHelper.prefix;

public class LooniumStructureConfiguration {
public static final int DEFAULT_COST = 35000;
public static final int DEFAULT_MAX_NEARBY_MOBS = 10;
public static final Codec<LooniumStructureConfiguration> CODEC = ExtraCodecs.validate(
RecordCodecBuilder.create(
instance -> instance.group(
ResourceLocation.CODEC.optionalFieldOf("parent")
.forGetter(lsc -> Optional.ofNullable(lsc.parent)),
ExtraCodecs.NON_NEGATIVE_INT.optionalFieldOf("manaCost")
.forGetter(lsc -> Optional.ofNullable(lsc.manaCost)),
ExtraCodecs.POSITIVE_INT.optionalFieldOf("maxNearbyMobs")
.forGetter(lsc -> Optional.ofNullable(lsc.maxNearbyMobs)),
StructureSpawnOverride.BoundingBoxType.CODEC
.optionalFieldOf("boundingBoxType")
.forGetter(lsc -> Optional.ofNullable(lsc.boundingBoxType)),
WeightedRandomList.codec(LooniumMobSpawnData.CODEC)
.optionalFieldOf("spawnedMobs")
.forGetter(lsc -> Optional.ofNullable(lsc.spawnedMobs)),
Codec.list(LooniumMobAttributeModifier.CODEC)
.optionalFieldOf("attributeModifiers")
.forGetter(lsc -> Optional.ofNullable(lsc.attributeModifiers)),
Codec.list(LooniumMobEffectToApply.CODEC)
.optionalFieldOf("effectsToApply")
.forGetter(lsc -> Optional.ofNullable(lsc.effectsToApply))
).apply(instance, LooniumStructureConfiguration::create)
), lsc -> {
if (lsc.parent == null && (lsc.manaCost == null || lsc.boundingBoxType == null || lsc.spawnedMobs == null)) {
return DataResult.error(() -> "Mana cost, bounding box type, and spawned mobs must be specified if there is no parent configuration");
}
if (lsc.spawnedMobs != null && lsc.spawnedMobs.isEmpty()) {
return DataResult.error(() -> "Spawned mobs cannot be empty");
}
if (lsc.manaCost != null && lsc.manaCost > DEFAULT_COST) {
return DataResult.error(() -> "Mana costs above %d are currently not supported"
.formatted(DEFAULT_COST));
}
return DataResult.success(lsc);
});
public static final ResourceLocation DEFAULT_CONFIG_ID = new ResourceLocation(BotaniaAPI.MODID, "default");
public static final Codec<LooniumStructureConfiguration> CODEC = RecordCodecBuilder.<LooniumStructureConfiguration>create(
instance -> instance.group(
ResourceLocation.CODEC.optionalFieldOf("parent")
.forGetter(lsc -> Optional.ofNullable(lsc.parent)),
ExtraCodecs.NON_NEGATIVE_INT.optionalFieldOf("manaCost")
.forGetter(lsc -> Optional.ofNullable(lsc.manaCost)),
ExtraCodecs.POSITIVE_INT.optionalFieldOf("maxNearbyMobs")
.forGetter(lsc -> Optional.ofNullable(lsc.maxNearbyMobs)),
StructureSpawnOverride.BoundingBoxType.CODEC
.optionalFieldOf("boundingBoxType")
.forGetter(lsc -> Optional.ofNullable(lsc.boundingBoxType)),
WeightedRandomList.codec(LooniumMobSpawnData.CODEC)
.optionalFieldOf("spawnedMobs")
.forGetter(lsc -> Optional.ofNullable(lsc.spawnedMobs)),
Codec.list(LooniumMobAttributeModifier.CODEC)
.optionalFieldOf("attributeModifiers")
.forGetter(lsc -> Optional.ofNullable(lsc.attributeModifiers)),
Codec.list(LooniumMobEffectToApply.CODEC)
.optionalFieldOf("effectsToApply")
.forGetter(lsc -> Optional.ofNullable(lsc.effectsToApply))
).apply(instance, LooniumStructureConfiguration::create)
).validate(lsc -> {
if (lsc.parent == null && (lsc.manaCost == null || lsc.boundingBoxType == null || lsc.spawnedMobs == null)) {
return DataResult.error(() -> "Mana cost, bounding box type, and spawned mobs must be specified if there is no parent configuration");
}
if (lsc.spawnedMobs != null && lsc.spawnedMobs.isEmpty()) {
return DataResult.error(() -> "Spawned mobs cannot be empty");
}
if (lsc.manaCost != null && lsc.manaCost > DEFAULT_COST) {
return DataResult.error(() -> "Mana costs above %d are currently not supported"
.formatted(DEFAULT_COST));
}
return DataResult.success(lsc);
});
public static final ResourceLocation DEFAULT_CONFIG_ID = prefix("default");

public final Integer manaCost;
public final Integer maxNearbyMobs;
Expand Down
17 changes: 2 additions & 15 deletions Xplat/src/main/java/vazkii/botania/common/block/BotaniaBlocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -1577,14 +1577,7 @@ protected ItemStack execute(@NotNull BlockSource source, @NotNull ItemStack stac
DispenserBlock.registerBehavior(BotaniaItems.corporeaSpark, behavior);
DispenserBlock.registerBehavior(BotaniaItems.corporeaSparkMaster, behavior);
DispenserBlock.registerBehavior(BotaniaItems.corporeaSparkCreative, behavior);
DispenserBlock.registerBehavior(BotaniaItems.enderAirBottle, new AbstractProjectileDispenseBehavior() {
@NotNull
@Override
protected Projectile getProjectile(@NotNull Level world, @NotNull Position pos, @NotNull ItemStack stack) {
return new EnderAirBottleEntity(pos.x(), pos.y(), pos.z(), world);
}
});

DispenserBlock.registerBehavior(BotaniaItems.enderAirBottle, new ProjectileDispenseBehavior(BotaniaItems.enderAirBottle));
behavior = DispenserBlockAccessor.getDispenserRegistry().get(Items.GLASS_BOTTLE);
DispenserBlock.registerBehavior(Items.GLASS_BOTTLE, new EnderAirBottlingBehavior(behavior));

Expand All @@ -1606,13 +1599,7 @@ protected Projectile getProjectile(@NotNull Level world, @NotNull Position pos,

DispenserBlock.registerBehavior(BotaniaItems.manasteelShears, new ShearsDispenseItemBehavior());
DispenserBlock.registerBehavior(BotaniaItems.elementiumShears, new ShearsDispenseItemBehavior());
DispenserBlock.registerBehavior(BotaniaItems.vineBall, new AbstractProjectileDispenseBehavior() {
@NotNull
@Override
protected Projectile getProjectile(@NotNull Level world, @NotNull Position pos, @NotNull ItemStack stack) {
return new VineBallEntity(pos.x(), pos.y(), pos.z(), world);
}
});
DispenserBlock.registerBehavior(BotaniaItems.vineBall, new ProjectileDispenseBehavior(BotaniaItems.vineBall));

SeedBehaviors.init();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
package vazkii.botania.common.block;

import net.minecraft.core.BlockPos;
import net.minecraft.core.Holder;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.RandomSource;
import net.minecraft.world.effect.MobEffect;
Expand Down Expand Up @@ -37,7 +38,7 @@ protected BotaniaFlowerBlock(DyeColor color, Properties builder) {
this.color = color;
}

private static MobEffect effectForFlower(DyeColor color) {
private static Holder<MobEffect> effectForFlower(DyeColor color) {
return switch (color) {
case WHITE -> MobEffects.MOVEMENT_SPEED;
case ORANGE -> MobEffects.FIRE_RESISTANCE;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
*/
package vazkii.botania.common.block;

import net.minecraft.core.Holder;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.effect.MobEffect;
Expand Down Expand Up @@ -311,7 +312,7 @@ private static ResourceLocation getId(Block b) {
}

private static FlowerBlock createSpecialFlowerBlock(
MobEffect effect, int effectDuration,
Holder<MobEffect> effect, int effectDuration,
BlockBehaviour.Properties props,
Supplier<BlockEntityType<? extends SpecialFlowerBlockEntity>> beType) {
return XplatAbstractions.INSTANCE.createSpecialFlowerBlock(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
package vazkii.botania.common.block.decor;

import net.minecraft.ChatFormatting;
import net.minecraft.core.Holder;
import net.minecraft.network.chat.Component;
import net.minecraft.world.effect.MobEffect;
import net.minecraft.world.item.CreativeModeTab;
Expand All @@ -27,7 +28,7 @@
public class FlowerMotifBlock extends FlowerBlock implements CustomCreativeTabContents {
private final boolean hidden;

public FlowerMotifBlock(MobEffect effect, int effectDuration, Properties properties, boolean hidden) {
public FlowerMotifBlock(Holder<MobEffect> effect, int effectDuration, Properties properties, boolean hidden) {
super(effect, effectDuration, properties);
this.hidden = hidden;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,7 +259,7 @@ private void spawnMob(ServerLevel world, LooniumMobSpawnData pickedMobType,
looniumComponent.setDrop(lootStack);
}

mob.finalizeSpawn(world, world.getCurrentDifficultyAt(mob.blockPosition()), MobSpawnType.SPAWNER, null, null);
mob.finalizeSpawn(world, world.getCurrentDifficultyAt(mob.blockPosition()), MobSpawnType.SPAWNER, null);
if (Boolean.FALSE.equals(pickedMobType.spawnAsBaby) && mob.isBaby()) {
// Note: might have already affected initial equipment/attribute selection, or even caused a special
// mob configuration (such as chicken jockey) to spawn, which may look weird when reverting to adult.
Expand All @@ -278,7 +278,7 @@ private void spawnMob(ServerLevel world, LooniumMobSpawnData pickedMobType,
equipmentTable.getRandomItems(lootParams, equipmentStack -> {
EquipmentSlot slot = equipmentStack.is(BotaniaTags.Items.LOONIUM_OFFHAND_EQUIPMENT)
? EquipmentSlot.OFFHAND
: LivingEntity.getEquipmentSlotForItem(equipmentStack);
: mob.getEquipmentSlotForItem(equipmentStack);
if (equippedSlots.contains(slot)) {
slot = equippedSlots.contains(EquipmentSlot.MAINHAND)
&& !(equipmentStack.getItem() instanceof TieredItem)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import net.minecraft.client.resources.sounds.AbstractTickableSoundInstance;
import net.minecraft.client.resources.sounds.SoundInstance;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Holder;
import net.minecraft.core.particles.ParticleTypes;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.nbt.CompoundTag;
Expand Down Expand Up @@ -267,7 +268,7 @@ public static boolean spawn(Player player, ItemStack stack, Level world, BlockPo
}

e.playSound(BotaniaSounds.gaiaSummon, 1F, 1F);
e.finalizeSpawn((ServerLevelAccessor) world, world.getCurrentDifficultyAt(e.blockPosition()), MobSpawnType.EVENT, null, null);
e.finalizeSpawn((ServerLevelAccessor) world, world.getCurrentDifficultyAt(e.blockPosition()), MobSpawnType.EVENT, null);
world.addFreshEntity(e);

for (Player nearbyPlayer : playersAround) {
Expand Down Expand Up @@ -661,9 +662,9 @@ private void smashBlocksAround(int centerX, int centerY, int centerZ, int radius
}

private void clearPotions(Player player) {
Set<MobEffect> effectsToRemove = new HashSet<>();
Set<Holder<MobEffect>> effectsToRemove = new HashSet<>();
for (var effectInstance : player.getActiveEffects()) {
if (effectInstance.getDuration() < 160 && effectInstance.isAmbient() && effectInstance.getEffect().getCategory() != MobEffectCategory.HARMFUL) {
if (effectInstance.getDuration() < 160 && effectInstance.isAmbient() && effectInstance.getEffect().value().getCategory() != MobEffectCategory.HARMFUL) {
effectsToRemove.add(effectInstance.getEffect());
}
}
Expand Down Expand Up @@ -709,7 +710,7 @@ private void spawnMobs(List<Player> players) {
pixie.setProps(players.get(random.nextInt(players.size())), this, 1, 8);
pixie.setPos(getX() + getBbWidth() / 2, getY() + 2, getZ() + getBbWidth() / 2);
pixie.finalizeSpawn((ServerLevelAccessor) level(), level().getCurrentDifficultyAt(pixie.blockPosition()),
MobSpawnType.MOB_SUMMONED, null, null);
MobSpawnType.MOB_SUMMONED, null);
level().addFreshEntity(pixie);
}
}
Expand All @@ -726,7 +727,7 @@ private void spawnMobs(List<Player> players) {
entity.setPos(getX() + 0.5 + Math.random() * range - range / 2, getY() - 1,
getZ() + 0.5 + Math.random() * range - range / 2);
entity.finalizeSpawn((ServerLevelAccessor) level(), level().getCurrentDifficultyAt(entity.blockPosition()),
MobSpawnType.MOB_SUMMONED, null, null);
MobSpawnType.MOB_SUMMONED, null);
if (entity instanceof WitherSkeleton && hardMode) {
entity.setItemSlot(EquipmentSlot.MAINHAND, new ItemStack(BotaniaItems.elementiumSword));
}
Expand Down Expand Up @@ -861,7 +862,7 @@ public void aiStep() {
pixie.setProps(players.get(random.nextInt(players.size())), this, 1, 8);
pixie.setPos(getX() + getBbWidth() / 2, getY() + 2, getZ() + getBbWidth() / 2);
pixie.finalizeSpawn((ServerLevelAccessor) level(), level().getCurrentDifficultyAt(pixie.blockPosition()),
MobSpawnType.MOB_SUMMONED, null, null);
MobSpawnType.MOB_SUMMONED, null);
level().addFreshEntity(pixie);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ public static void onDamageTaken(Player player, DamageSource source) {

pixie.setProps(livingSource, player, 0, dmg);
pixie.finalizeSpawn((ServerLevelAccessor) player.level(), player.level().getCurrentDifficultyAt(pixie.blockPosition()),
MobSpawnType.EVENT, null, null);
MobSpawnType.EVENT, null);
player.level().addFreshEntity(pixie);
}
}
Expand Down
Loading

0 comments on commit 83e6ed3

Please sign in to comment.