Skip to content

Commit

Permalink
Merge branch '1.19.2' into 1.19.2-damage-source-backport
Browse files Browse the repository at this point in the history
  • Loading branch information
iron431 committed Oct 27, 2023
2 parents 7a857ea + d50d8d6 commit 599421b
Show file tree
Hide file tree
Showing 103 changed files with 456 additions and 466 deletions.
17 changes: 13 additions & 4 deletions LATEST_CHANGES.MD
Original file line number Diff line number Diff line change
@@ -1,10 +1,19 @@
### Additions
-

- Added Mana Regen attribute
- Added the Amethyst Resonance Charm, a craftable necklace that gives +15% mana regeneration
- Added InscribeSpellEvent for developers, courtesy of Silvertide7
- Added ChangeManaEvent for developers

### Changes
- Buff Magic Arrow's base damage by 5
- Add CastSource to SpellCastEvent
- Add CastSource to SpellCastEvent for developers
- Rework Priest Armor Texture, courtesy of Crydigo
- Tweak most jewelry textures
- Any armor can now be upgraded instead of only mage armor (can_be_upgraded tag has been removed)
- Spectral Hammer debris reduced

### Fixes
- Fix inconsistent Magic Arrow block penetration
- Fixed inconsistent Magic Arrow block penetration
- Fixed the two-handed sword models when using left hand mode
- Mobs can no longer detect your armor when affected by True Invisibility
- Fixed geckolib armor anchor points causing misaligned armor models when the player is animating
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package io.redspace.ironsspellbooks.api.events;


import io.redspace.ironsspellbooks.api.magic.MagicData;
import io.redspace.ironsspellbooks.capabilities.spell.SpellData;
import net.minecraft.world.entity.player.Player;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.player.PlayerEvent;
import net.minecraftforge.eventbus.api.Cancelable;

/**
* ChangeManaEvent is fired whenever a {@link Player}'s mana is changed via {@link io.redspace.ironsspellbooks.api.magic.MagicData#setMana(float)}.<br>
* <br>
* This event is {@link Cancelable}.<br>
* If this event is canceled, the player's mana does not change.<br>
* <br>
* This event does not have a result. {@link HasResult}<br>
* <br>
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.<br>
**/
public class ChangeManaEvent extends PlayerEvent {
private final MagicData magicData;
private final float oldMana;
private float newMana;

public ChangeManaEvent(Player player, MagicData magicData, float oldMana, float newMana) {
super(player);
this.magicData = magicData;
this.oldMana = oldMana;
this.newMana = newMana;
}

@Override
public boolean isCancelable() {
return true;
}

public MagicData getMagicData() {
return magicData;
}

public float getOldMana() {
return oldMana;
}

public float getNewMana() {
return newMana;
}

public void setNewMana(float newMana) {
this.newMana = newMana;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package io.redspace.ironsspellbooks.api.events;


import io.redspace.ironsspellbooks.capabilities.spell.SpellData;
import net.minecraft.world.entity.player.Player;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.player.PlayerEvent;
import net.minecraftforge.eventbus.api.Cancelable;

/**
* InscribeSpellEvent is fired whenever a {@link Player} inscribes a spell into a spellbook.<br>
* <br>
* This event is {@link Cancelable}.<br>
* If this event is canceled, the spell is not inscribed.<br>
* <br>
* This event does not have a result. {@link HasResult}<br>
* <br>
* This event is fired on the {@link MinecraftForge#EVENT_BUS}.<br>
**/
public class InscribeSpellEvent extends PlayerEvent {
private final SpellData spellData;
public InscribeSpellEvent(Player player, SpellData spellData)
{
super(player);
this.spellData = spellData;
}

@Override
public boolean isCancelable() { return true; }
public SpellData getSpellData() { return this.spellData; }
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package io.redspace.ironsspellbooks.api.magic;

import io.redspace.ironsspellbooks.IronsSpellbooks;
import io.redspace.ironsspellbooks.api.entity.IMagicEntity;
import io.redspace.ironsspellbooks.api.events.ChangeManaEvent;
import io.redspace.ironsspellbooks.api.registry.SpellRegistry;
import io.redspace.ironsspellbooks.api.spells.*;
import io.redspace.ironsspellbooks.capabilities.magic.PlayerCooldowns;
Expand All @@ -13,6 +15,7 @@
import net.minecraft.server.level.ServerPlayer;
import net.minecraft.world.entity.LivingEntity;
import net.minecraft.world.item.ItemStack;
import net.minecraftforge.common.MinecraftForge;
import org.jetbrains.annotations.Nullable;

public class MagicData {
Expand Down Expand Up @@ -51,11 +54,15 @@ public int getMana() {
}

public void setMana(float mana) {
this.mana = mana;
//Event does will not get posted if the server player is null
ChangeManaEvent e = new ChangeManaEvent(this.serverPlayer, this, this.mana, mana);
if (this.serverPlayer == null || !MinecraftForge.EVENT_BUS.post(e)) {
this.mana = e.getNewMana();
}
}

public void addMana(float mana) {
this.mana += mana;
setMana(this.mana + mana);
}

/********* SYNC DATA *******************************************************/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -343,9 +343,9 @@ public void onCast(Level level, int spellLevel, LivingEntity entity, MagicData p

protected void playSound(Optional<SoundEvent> sound, Entity entity, boolean playDefaultSound) {
if (sound.isPresent()) {
entity.playSound(sound.get(), 2.0f, .9f + entity.level.random.nextFloat() * .2f);
entity.playSound(sound.get(), 2.0f, .9f + Utils.random.nextFloat() * .2f);
} else if (playDefaultSound) {
entity.playSound(defaultCastSound(), 2.0f, .9f + entity.level.random.nextFloat() * .2f);
entity.playSound(defaultCastSound(), 2.0f, .9f + Utils.random.nextFloat() * .2f);
}
}

Expand Down
31 changes: 16 additions & 15 deletions src/main/java/io/redspace/ironsspellbooks/api/util/Utils.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,18 +41,17 @@
import net.minecraft.world.entity.*;
import net.minecraft.world.entity.ai.attributes.Attributes;
import net.minecraft.world.entity.item.ItemEntity;
import net.minecraft.world.entity.monster.Enemy;
import net.minecraft.world.entity.monster.Monster;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.AxeItem;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.item.SwordItem;
import net.minecraft.world.item.*;
import net.minecraft.world.item.enchantment.EnchantmentHelper;
import net.minecraft.world.level.BlockCollisions;
import net.minecraft.world.level.ClipContext;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.ServerLevelAccessor;
import net.minecraft.world.level.biome.Biomes;
import net.minecraft.world.level.levelgen.ThreadSafeLegacyRandomSource;
import net.minecraft.world.phys.*;
import net.minecraftforge.entity.PartEntity;
import org.jetbrains.annotations.NotNull;
Expand All @@ -66,6 +65,7 @@

public class Utils {

public static final RandomSource random = RandomSource.createThreadSafe();
public static String getStackTraceAsString() {
var trace = Arrays.stream(Thread.currentThread().getStackTrace());
StringBuffer sb = new StringBuffer();
Expand All @@ -87,7 +87,7 @@ public static void spawnInWorld(Level level, BlockPos pos, ItemStack remaining)

public static boolean canBeUpgraded(ItemStack stack) {
return !ServerConfigs.UPGRADE_BLACKLIST.get().contains(Registry.ITEM.getKey(stack.getItem()).toString())
&& (stack.getItem() instanceof SpellBook || stack.is(ModTags.CAN_BE_UPGRADED)
&& (stack.getItem() instanceof SpellBook || stack.getItem() instanceof ArmorItem
|| ServerConfigs.UPGRADE_WHITELIST.get().contains(Registry.ITEM.getKey(stack.getItem()).toString())
);
}
Expand Down Expand Up @@ -379,10 +379,10 @@ public static void throwTarget(LivingEntity attacker, LivingEntity target, float
if (!(d2 <= 0.0D)) {
double d3 = target.getX() - attacker.getX();
double d4 = target.getZ() - attacker.getZ();
float f = (float) (attacker.level.random.nextInt(21) - 10);
double d5 = d2 * (double) (attacker.level.random.nextFloat() * 0.5F + 0.2F);
float f = (float) (Utils.random.nextInt(21) - 10);
double d5 = d2 * (double) (Utils.random.nextFloat() * 0.5F + 0.2F);
Vec3 vec3 = (new Vec3(d3, 0.0D, d4)).normalize().scale(d5).yRot(f);
double d6 = d2 * (double) attacker.level.random.nextFloat() * 0.5D;
double d6 = d2 * (double) Utils.random.nextFloat() * 0.5D;
target.push(vec3.x, d6, vec3.z);
target.hurtMarked = true;
}
Expand All @@ -409,24 +409,25 @@ public static Vector3f getRandomVec3f(double scale) {
}

public static boolean shouldHealEntity(LivingEntity healer, LivingEntity target) {
if (healer instanceof NeutralMob neutralMob && neutralMob.isAngryAt(target))
if (healer instanceof NeutralMob neutralMob && neutralMob.isAngryAt(target)) {
return false;
if (healer == target)
} else if (healer == target) {
return true;
if (target.getType().is(ModTags.ALWAYS_HEAL) && !(healer.getMobType() == MobType.UNDEAD || healer.getMobType() == MobType.ILLAGER))
} else if (target.getType().is(ModTags.ALWAYS_HEAL) && !(healer instanceof Enemy)) {
//This tag is for things like iron golems, villagers, farm animals, etc
return true;
if (healer.isAlliedTo(target))
} else if (healer.isAlliedTo(target)) {
//Generic ally-check. Precursory team check plus some mobs override it, such as summons
return true;
if (healer.getTeam() != null)
} else if (healer.getTeam() != null) {
//If we are on a team, only heal teammates
return target.isAlliedTo(healer.getTeam());
if (healer instanceof Player) {
} else if (healer instanceof Player) {
//If we are a player and not on a team, we only want to heal other players
return target instanceof Player;
} else {
return healer.getMobType() == target.getMobType();
//Otherwise, heal like kind (ie undead to undead), but also xor check "enemy" status (most mob types are undefined)
return healer.getMobType() == target.getMobType() && (healer instanceof Enemy ^ target instanceof Enemy);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.redspace.ironsspellbooks.block;

import io.redspace.ironsspellbooks.api.util.Utils;
import io.redspace.ironsspellbooks.capabilities.magic.MagicManager;
import io.redspace.ironsspellbooks.damage.DamageSources;
import io.redspace.ironsspellbooks.util.ParticleHelper;
Expand Down Expand Up @@ -54,7 +55,7 @@ public static void attemptCookEntity(BlockState blockState, Level level, BlockPo
if (entity instanceof LivingEntity livingEntity && livingEntity.getBoundingBox().intersects(cauldron.getInteractionShape(blockState, level, pos).bounds().move(pos))) {
if (livingEntity.hurt(DamageSources.CAULDRON, 2)) {
MagicManager.spawnParticles(level, ParticleHelper.BLOOD, entity.getX(), entity.getY() + entity.getBbHeight() / 2, entity.getZ(), 20, .05, .05, .05, .1, false);
if (level.random.nextDouble() <= .5 && !isCauldronFull(blockState)) {
if (Utils.random.nextDouble() <= .5 && !isCauldronFull(blockState)) {
execution.execute();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public static void serverTick(Level level, BlockPos pos, BlockState blockState,
cauldronTile.cooktimes[i] = 0;
}
}
var random = level.getRandom();
var random = Utils.random;
if (AlchemistCauldronBlock.isBoiling(blockState)) {
float waterLevel = Mth.lerp(AlchemistCauldronBlock.getLevel(blockState) / (float) AlchemistCauldronBlock.MAX_LEVELS, .25f, .9f);
MagicManager.spawnParticles(level, ParticleTypes.BUBBLE_POP, pos.getX() + Mth.randomBetween(random, .2f, .8f), pos.getY() + waterLevel, pos.getZ() + Mth.randomBetween(random, .2f, .8f), 1, 0, 0, 0, 0, false);
Expand Down Expand Up @@ -122,7 +122,7 @@ public void meltComponent(ItemStack itemStack) {
boolean shouldMelt = false;
boolean success = true;
if (itemStack.is(ItemRegistry.SCROLL.get()) && !isFull(resultItems)) {
if (level.random.nextFloat() < ServerConfigs.SCROLL_RECYCLE_CHANCE.get()) {
if (Utils.random.nextFloat() < ServerConfigs.SCROLL_RECYCLE_CHANCE.get()) {
ItemStack result = new ItemStack(getInkFromScroll(itemStack));
appendItem(resultItems, result);
} else {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.redspace.ironsspellbooks.block.arcane_anvil;

import io.redspace.ironsspellbooks.api.util.Utils;
import io.redspace.ironsspellbooks.gui.arcane_anvil.ArcaneAnvilMenu;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
Expand Down Expand Up @@ -54,7 +55,7 @@ protected void falling(FallingBlockEntity pFallingEntity) {

public void onLand(Level pLevel, BlockPos pPos, BlockState pState, BlockState pReplaceableState, FallingBlockEntity pFallingBlock) {
if (!pFallingBlock.isSilent()) {
pLevel.playSound(null,pPos, SoundEvents.ANVIL_LAND, SoundSource.BLOCKS, .3F, pLevel.random.nextFloat() * 0.1F + 0.9F);
pLevel.playSound(null,pPos, SoundEvents.ANVIL_LAND, SoundSource.BLOCKS, .3F, Utils.random.nextFloat() * 0.1F + 0.9F);
}

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ public class MagicManager implements IMagicManager {
public static final int MANA_REGEN_TICKS = 10;
public static final int CONTINUOUS_CAST_TICK_INTERVAL = 10;

/**
* Deprecated Helper Method. Use {@link MagicData#setMana(float)} instead.
*/
@Deprecated
public void setPlayerCurrentMana(ServerPlayer serverPlayer, int newManaValue) {
var playerMagicData = MagicData.getPlayerMagicData(serverPlayer);
playerMagicData.setMana(newManaValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
import net.minecraft.resources.ResourceLocation;
import net.minecraftforge.common.ForgeConfigSpec;
import net.minecraftforge.common.util.LazyOptional;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.event.config.ModConfigEvent;
import net.minecraftforge.registries.ForgeRegistries;

import java.util.*;
import java.util.function.Supplier;
Expand Down Expand Up @@ -113,7 +116,18 @@ public static SpellConfigParameters getSpellConfig(AbstractSpell abstractSpell)
public static Map<String, SpellConfigParameters> getSpellConfigs() {
return SPELL_CONFIGS;
}

//TODO:
// private static boolean validateItemName(final Object obj) {
// return obj instanceof final String itemName && ForgeRegistries.ITEMS.containsKey(new ResourceLocation(itemName));
// }
// @SubscribeEvent
// static void onLoad(final ModConfigEvent event) {
// // convert the list of strings into a set of items
// items = ITEM_STRINGS.get().stream()
// .map(itemName -> ForgeRegistries.ITEMS.getValue(new ResourceLocation(itemName)))
// .collect(Collectors.toSet());
// }
//
private static void createSpellConfig(AbstractSpell spell) {
DefaultConfig config = spell.getDefaultConfig();
//IronsSpellbooks.LOGGER.debug("CFG: createSpellConfig");
Expand Down Expand Up @@ -148,7 +162,7 @@ private static String createSpellConfigTitle(String str) {
// }

public static class SpellConfigParameters {

//why did i do all this manually why isnt it a record :D
final Supplier<Boolean> ENABLED;
final Supplier<String> SCHOOL;
final LazyOptional<SchoolType> ACTUAL_SCHOOL;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.redspace.ironsspellbooks.entity.mobs;

import io.redspace.ironsspellbooks.api.util.Utils;
import io.redspace.ironsspellbooks.capabilities.magic.MagicManager;
import io.redspace.ironsspellbooks.entity.mobs.goals.GenericFollowOwnerGoal;
import io.redspace.ironsspellbooks.registries.EntityRegistry;
Expand Down Expand Up @@ -27,13 +28,13 @@
public class SummonedHorse extends AbstractHorse implements MagicSummon {
public SummonedHorse(EntityType<? extends AbstractHorse> pEntityType, Level pLevel) {
super(pEntityType, pLevel);
//randomizeAttributes(level.random);
//randomizeAttributes(Utils.random);

}

public SummonedHorse(Level pLevel) {
this(EntityRegistry.SPECTRAL_STEED.get(), pLevel);
//randomizeAttributes(level.random);
//randomizeAttributes(Utils.random);

}

Expand Down Expand Up @@ -116,7 +117,7 @@ protected SoundEvent getAngrySound() {
public void spawnParticles() {

if (level.isClientSide) {
if (level.getRandom().nextFloat() < .25f) {
if (Utils.random.nextFloat() < .25f) {
float radius = .75f;
Vec3 vec = new Vec3(
random.nextFloat() * 2 * radius - radius,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ protected boolean isSunBurnTick() {

@Override
public SpawnGroupData finalizeSpawn(ServerLevelAccessor pLevel, DifficultyInstance pDifficulty, MobSpawnType pReason, @Nullable SpawnGroupData pSpawnData, @Nullable CompoundTag pDataTag) {
RandomSource randomsource = pLevel.getRandom();
RandomSource randomsource = Utils.random;
this.populateDefaultEquipmentSlots(randomsource, pDifficulty);
if (randomsource.nextDouble() < .3)
this.setItemSlot(EquipmentSlot.MAINHAND, new ItemStack(Items.IRON_SWORD));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ public SummonedVex(Level pLevel, LivingEntity owner) {
public void registerGoals() {
this.goalSelector.addGoal(0, new FloatGoal(this));
this.goalSelector.addGoal(4, new VexChargeAttackGoal());
this.goalSelector.addGoal(7, new GenericFollowOwnerGoal(this, this::getSummoner, .65f, 15, 5, true, 25));
this.goalSelector.addGoal(7, new GenericFollowOwnerGoal(this, this::getSummoner, .65f, 35, 10, true, 50));
this.goalSelector.addGoal(9, new LookAtPlayerGoal(this, Player.class, 3.0F, 1.0F));
this.goalSelector.addGoal(10, new LookAtPlayerGoal(this, Mob.class, 8.0F));
this.goalSelector.addGoal(16, new VexRandomMoveGoal());
Expand Down
Loading

0 comments on commit 599421b

Please sign in to comment.