From 07d1d44f522892c4954bf0458076ef925b50922b Mon Sep 17 00:00:00 2001 From: TheBrokenRail Date: Sat, 7 Mar 2020 15:12:46 -0500 Subject: [PATCH] 1.0.11 Allow Spells to Affect Blocks Add Cooling Spell --- CHANGELOG.md | 4 ++ README.md | 1 + gradle.properties | 2 +- .../client/entity/SpellEntityRenderer.java | 6 +-- .../sorcerycraft/entity/SpellEntity.java | 35 ++++++------- .../sorcerycraft/item/SpellItem.java | 2 +- .../sorcerycraft/spell/CoolingSpell.java | 50 +++++++++++++++++++ .../sorcerycraft/spell/FlameSpell.java | 12 +++++ .../sorcerycraft/spell/InwardSpell.java | 6 --- .../sorcerycraft/spell/SteadfastSpell.java | 6 --- .../sorcerycraft/spell/registry/Spell.java | 10 +++- .../sorcerycraft/spell/registry/Spells.java | 4 +- .../sorcerycraft/spell/util/SpellTag.java | 10 ++-- .../assets/sorcerycraft/lang/en_us.json | 3 +- 14 files changed, 104 insertions(+), 47 deletions(-) create mode 100644 src/main/java/com/thebrokenrail/sorcerycraft/spell/CoolingSpell.java diff --git a/CHANGELOG.md b/CHANGELOG.md index 79d6df3..1085941 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,9 @@ ### Changelog +**1.0.11** +* Allow Spells to Affect Blocks +* Add Cooling Spell + **1.0.10** * Add Issues Link diff --git a/README.md b/README.md index 18e7153..adce772 100644 --- a/README.md +++ b/README.md @@ -59,6 +59,7 @@ You can apply Spells to blank or existing Spells in the Casting Table. Doing so | Steadfast | 1 | Prevents Spell from rebounding. | | Teleport | 2 | Teleports target to random location. | | Inward | 1 | Causes the Spell to target the player. If the Spell fails instead of rebounding, it will just do nothing. | +| Cooling | 1 | Extinguish the target if they are on fire. | ## ```/spell``` Command This command requires OP permissions. diff --git a/gradle.properties b/gradle.properties index a44aacf..3a23bcb 100644 --- a/gradle.properties +++ b/gradle.properties @@ -10,7 +10,7 @@ org.gradle.jvmargs = -Xmx1G loader_version = 0.7.8+build.186 # Mod Properties - mod_version = 1.0.10 + mod_version = 1.0.11 maven_group = com.thebrokenrail archives_base_name = sorcerycraft diff --git a/src/main/java/com/thebrokenrail/sorcerycraft/client/entity/SpellEntityRenderer.java b/src/main/java/com/thebrokenrail/sorcerycraft/client/entity/SpellEntityRenderer.java index 63e7527..5133c7c 100644 --- a/src/main/java/com/thebrokenrail/sorcerycraft/client/entity/SpellEntityRenderer.java +++ b/src/main/java/com/thebrokenrail/sorcerycraft/client/entity/SpellEntityRenderer.java @@ -1,21 +1,21 @@ package com.thebrokenrail.sorcerycraft.client.entity; +import com.thebrokenrail.sorcerycraft.entity.SpellEntity; import net.fabricmc.api.EnvType; import net.fabricmc.api.Environment; import net.minecraft.client.render.entity.EntityRenderDispatcher; import net.minecraft.client.render.entity.EntityRenderer; import net.minecraft.container.PlayerContainer; -import net.minecraft.entity.AreaEffectCloudEntity; import net.minecraft.util.Identifier; @Environment(EnvType.CLIENT) -public class SpellEntityRenderer extends EntityRenderer { +public class SpellEntityRenderer extends EntityRenderer { public SpellEntityRenderer(EntityRenderDispatcher entityRenderDispatcher) { super(entityRenderDispatcher); } @Override - public Identifier getTexture(AreaEffectCloudEntity areaEffectCloudEntity) { + public Identifier getTexture(SpellEntity spellEntity) { return PlayerContainer.BLOCK_ATLAS_TEXTURE; } } \ No newline at end of file diff --git a/src/main/java/com/thebrokenrail/sorcerycraft/entity/SpellEntity.java b/src/main/java/com/thebrokenrail/sorcerycraft/entity/SpellEntity.java index a357428..44772ec 100644 --- a/src/main/java/com/thebrokenrail/sorcerycraft/entity/SpellEntity.java +++ b/src/main/java/com/thebrokenrail/sorcerycraft/entity/SpellEntity.java @@ -5,8 +5,6 @@ import com.thebrokenrail.sorcerycraft.spell.registry.Spell; import com.thebrokenrail.sorcerycraft.spell.registry.SpellRegistry; import com.thebrokenrail.sorcerycraft.spell.util.SpellTag; import com.thebrokenrail.sorcerycraft.spell.registry.Spells; -import net.fabricmc.api.EnvType; -import net.fabricmc.api.Environment; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityType; import net.minecraft.entity.LivingEntity; @@ -16,12 +14,12 @@ import net.minecraft.item.Item; import net.minecraft.network.Packet; import net.minecraft.network.packet.s2c.play.EntitySpawnS2CPacket; import net.minecraft.particle.ParticleTypes; -import net.minecraft.server.command.ParticleCommand; import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.world.ServerWorld; import net.minecraft.sound.SoundCategory; import net.minecraft.sound.SoundEvents; import net.minecraft.util.Identifier; +import net.minecraft.util.hit.BlockHitResult; import net.minecraft.util.hit.EntityHitResult; import net.minecraft.util.hit.HitResult; import net.minecraft.world.World; @@ -39,8 +37,6 @@ public class SpellEntity extends ThrownItemEntity { super(SorceryCraft.SPELL_ENTITY, owner, world); } - private boolean firstTick = true; - public SpellEntity(World world, double x, double y, double z) { super(SorceryCraft.SPELL_ENTITY, x, y, z, world); } @@ -51,19 +47,21 @@ public class SpellEntity extends ThrownItemEntity { @Override protected void onCollision(HitResult hitResult) { - Map spells = SpellTag.getSpells(getItem()); - if (!spells.containsKey(Spells.INWARD_SPELL)) { - if (hitResult.getType() == HitResult.Type.BLOCK) { - remove(); - } else if (hitResult.getType() == HitResult.Type.ENTITY) { - Entity entity = ((EntityHitResult) hitResult).getEntity(); - + if (!getEntityWorld().isClient()) { + Map spells = SpellTag.getSpells(getItem()); + if (!spells.containsKey(Spells.INWARD_SPELL)) { boolean success = didSpellSucceed(spells); for (Map.Entry entry : spells.entrySet()) { - Spell spell = SpellRegistry.getSpell(entry.getKey(), entry.getValue()); + Spell spell = SpellRegistry.getSpell(entry); if (spell != null) { if (success) { - spell.execute(entity, this, getOwner()); + if (hitResult.getType() == HitResult.Type.BLOCK) { + BlockHitResult blockHitResult = (BlockHitResult) hitResult; + spell.execute(getEntityWorld(), blockHitResult); + } else if (hitResult.getType() == HitResult.Type.ENTITY) { + Entity entity = ((EntityHitResult) hitResult).getEntity(); + spell.execute(entity, this, getOwner()); + } } else if (getOwner() != null) { if (getOwner() instanceof PlayerEntity) { PlayerEntity player = (PlayerEntity) getOwner(); @@ -73,7 +71,6 @@ public class SpellEntity extends ThrownItemEntity { } } } - remove(); } } @@ -82,14 +79,13 @@ public class SpellEntity extends ThrownItemEntity { @Override public void tick() { super.tick(); - if (firstTick) { - firstTick = false; + if (!getEntityWorld().isClient()) { Map spells = SpellTag.getSpells(getItem()); if (spells.containsKey(Spells.INWARD_SPELL)) { if (getOwner() != null) { boolean success = didSpellSucceed(spells); for (Map.Entry entry : spells.entrySet()) { - Spell spell = SpellRegistry.getSpell(entry.getKey(), entry.getValue()); + Spell spell = SpellRegistry.getSpell(entry); if (spell != null) { if (success) { spell.execute(getOwner(), this, getOwner()); @@ -103,8 +99,7 @@ public class SpellEntity extends ThrownItemEntity { remove(); return; } - } - if (!getEntityWorld().isClient()) { + List viewers = Objects.requireNonNull(getServer()).getPlayerManager().getPlayerList(); for (ServerPlayerEntity viewer : viewers) { ((ServerWorld) getEntityWorld()).spawnParticles(viewer, ParticleTypes.WITCH, true, getX(), getY(), getZ(), 8, 0.01d, 0.01d, 0.01d, 0.5d); diff --git a/src/main/java/com/thebrokenrail/sorcerycraft/item/SpellItem.java b/src/main/java/com/thebrokenrail/sorcerycraft/item/SpellItem.java index b584516..e934361 100644 --- a/src/main/java/com/thebrokenrail/sorcerycraft/item/SpellItem.java +++ b/src/main/java/com/thebrokenrail/sorcerycraft/item/SpellItem.java @@ -52,7 +52,7 @@ public class SpellItem extends Item { @Override public boolean hasEnchantmentGlint(ItemStack stack) { Map spells = SpellTag.getSpells(stack); - return spells.size() > 0; + return spells.size() > 0 || super.hasEnchantmentGlint(stack); } @Override diff --git a/src/main/java/com/thebrokenrail/sorcerycraft/spell/CoolingSpell.java b/src/main/java/com/thebrokenrail/sorcerycraft/spell/CoolingSpell.java new file mode 100644 index 0000000..9756e2c --- /dev/null +++ b/src/main/java/com/thebrokenrail/sorcerycraft/spell/CoolingSpell.java @@ -0,0 +1,50 @@ +package com.thebrokenrail.sorcerycraft.spell; + +import com.thebrokenrail.sorcerycraft.spell.registry.Spell; +import net.minecraft.entity.Entity; +import net.minecraft.item.ItemStack; +import net.minecraft.item.Items; +import net.minecraft.tag.BlockTags; +import net.minecraft.util.Identifier; +import net.minecraft.util.hit.BlockHitResult; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; + +public class CoolingSpell extends Spell { + public CoolingSpell(Identifier id, int level) { + super(id, level); + } + + @Override + public void execute(Entity target, Entity source, Entity attacker) { + target.setFireTicks(0); + } + + @Override + public void execute(World world, BlockHitResult hitResult) { + BlockPos blockPos = hitResult.getBlockPos(); + if (world.getBlockState(blockPos).matches(BlockTags.FIRE)) { + world.removeBlock(blockPos, false); + } + + BlockPos sideBlockPos = blockPos.offset(hitResult.getSide()); + if (world.getBlockState(sideBlockPos).matches(BlockTags.FIRE)) { + world.removeBlock(sideBlockPos, false); + } + } + + @Override + public int getXPCost() { + return 13; + } + + @Override + public ItemStack getItemCost() { + return new ItemStack(Items.ICE); + } + + @Override + public int getMaxLevel() { + return 1; + } +} diff --git a/src/main/java/com/thebrokenrail/sorcerycraft/spell/FlameSpell.java b/src/main/java/com/thebrokenrail/sorcerycraft/spell/FlameSpell.java index 9de5414..c0acdd9 100644 --- a/src/main/java/com/thebrokenrail/sorcerycraft/spell/FlameSpell.java +++ b/src/main/java/com/thebrokenrail/sorcerycraft/spell/FlameSpell.java @@ -1,10 +1,14 @@ package com.thebrokenrail.sorcerycraft.spell; import com.thebrokenrail.sorcerycraft.spell.registry.Spell; +import net.minecraft.block.AbstractFireBlock; import net.minecraft.entity.Entity; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; import net.minecraft.util.Identifier; +import net.minecraft.util.hit.BlockHitResult; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; public class FlameSpell extends Spell { public FlameSpell(Identifier id, int level) { @@ -16,6 +20,14 @@ public class FlameSpell extends Spell { target.setFireTicks(400 + (getLevel() * 200)); } + @Override + public void execute(World world, BlockHitResult hitResult) { + BlockPos blockPos = hitResult.getBlockPos().offset(hitResult.getSide()); + if (world.isAir(blockPos)) { + world.setBlockState(blockPos, AbstractFireBlock.getState(world, blockPos)); + } + } + @Override public int getXPCost() { switch (getLevel()) { diff --git a/src/main/java/com/thebrokenrail/sorcerycraft/spell/InwardSpell.java b/src/main/java/com/thebrokenrail/sorcerycraft/spell/InwardSpell.java index 2a6ee96..11750d9 100644 --- a/src/main/java/com/thebrokenrail/sorcerycraft/spell/InwardSpell.java +++ b/src/main/java/com/thebrokenrail/sorcerycraft/spell/InwardSpell.java @@ -1,7 +1,6 @@ package com.thebrokenrail.sorcerycraft.spell; import com.thebrokenrail.sorcerycraft.spell.registry.Spell; -import net.minecraft.entity.Entity; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; import net.minecraft.util.Identifier; @@ -11,11 +10,6 @@ public class InwardSpell extends Spell { super(id, level); } - @Override - public void execute(Entity target, Entity source, Entity attacker) { - // NOOP - } - @Override public int getXPCost() { return 16; diff --git a/src/main/java/com/thebrokenrail/sorcerycraft/spell/SteadfastSpell.java b/src/main/java/com/thebrokenrail/sorcerycraft/spell/SteadfastSpell.java index 94321bc..c63e0d2 100644 --- a/src/main/java/com/thebrokenrail/sorcerycraft/spell/SteadfastSpell.java +++ b/src/main/java/com/thebrokenrail/sorcerycraft/spell/SteadfastSpell.java @@ -1,7 +1,6 @@ package com.thebrokenrail.sorcerycraft.spell; import com.thebrokenrail.sorcerycraft.spell.registry.Spell; -import net.minecraft.entity.Entity; import net.minecraft.item.ItemStack; import net.minecraft.item.Items; import net.minecraft.util.Identifier; @@ -11,11 +10,6 @@ public class SteadfastSpell extends Spell { super(id, level); } - @Override - public void execute(Entity target, Entity source, Entity attacker) { - // NOOP - } - @Override public int getXPCost() { return 18; diff --git a/src/main/java/com/thebrokenrail/sorcerycraft/spell/registry/Spell.java b/src/main/java/com/thebrokenrail/sorcerycraft/spell/registry/Spell.java index bcbe6fd..6886276 100644 --- a/src/main/java/com/thebrokenrail/sorcerycraft/spell/registry/Spell.java +++ b/src/main/java/com/thebrokenrail/sorcerycraft/spell/registry/Spell.java @@ -3,6 +3,8 @@ package com.thebrokenrail.sorcerycraft.spell.registry; import net.minecraft.entity.Entity; import net.minecraft.item.ItemStack; import net.minecraft.util.Identifier; +import net.minecraft.util.hit.BlockHitResult; +import net.minecraft.world.World; public abstract class Spell { private final Identifier id; @@ -21,7 +23,13 @@ public abstract class Spell { return level; } - public abstract void execute(Entity target, Entity source, Entity attacker); + public void execute(Entity target, Entity source, Entity attacker) { + // NOOP + } + + public void execute(World world , BlockHitResult hitResult) { + // NOOP + } public abstract int getXPCost(); diff --git a/src/main/java/com/thebrokenrail/sorcerycraft/spell/registry/Spells.java b/src/main/java/com/thebrokenrail/sorcerycraft/spell/registry/Spells.java index 631c35f..db2a047 100644 --- a/src/main/java/com/thebrokenrail/sorcerycraft/spell/registry/Spells.java +++ b/src/main/java/com/thebrokenrail/sorcerycraft/spell/registry/Spells.java @@ -1,6 +1,7 @@ package com.thebrokenrail.sorcerycraft.spell.registry; import com.thebrokenrail.sorcerycraft.SorceryCraft; +import com.thebrokenrail.sorcerycraft.spell.CoolingSpell; import com.thebrokenrail.sorcerycraft.spell.DamageSpell; import com.thebrokenrail.sorcerycraft.spell.DissolveSpell; import com.thebrokenrail.sorcerycraft.spell.FlameSpell; @@ -9,7 +10,6 @@ import com.thebrokenrail.sorcerycraft.spell.InwardSpell; import com.thebrokenrail.sorcerycraft.spell.LevitateSpell; import com.thebrokenrail.sorcerycraft.spell.SteadfastSpell; import com.thebrokenrail.sorcerycraft.spell.TeleportSpell; -import com.thebrokenrail.sorcerycraft.spell.registry.SpellRegistry; import net.minecraft.util.Identifier; @SuppressWarnings("unused") @@ -22,6 +22,7 @@ public class Spells { public static final Identifier LEVITATE_SPELL; public static final Identifier TELEPORT_SPELL; public static final Identifier INWARD_SPELL; + public static final Identifier COOLING_SPELL; static { HEAL_SPELL = SpellRegistry.registerSpell(new Identifier(SorceryCraft.NAMESPACE, "heal_spell"), HealSpell.class); @@ -32,5 +33,6 @@ public class Spells { LEVITATE_SPELL = SpellRegistry.registerSpell(new Identifier(SorceryCraft.NAMESPACE, "levitate_spell"), LevitateSpell.class); TELEPORT_SPELL = SpellRegistry.registerSpell(new Identifier(SorceryCraft.NAMESPACE, "teleport_spell"), TeleportSpell.class); INWARD_SPELL = SpellRegistry.registerSpell(new Identifier(SorceryCraft.NAMESPACE, "inward_spell"), InwardSpell.class); + COOLING_SPELL = SpellRegistry.registerSpell(new Identifier(SorceryCraft.NAMESPACE, "cooling_spell"), CoolingSpell.class); } } diff --git a/src/main/java/com/thebrokenrail/sorcerycraft/spell/util/SpellTag.java b/src/main/java/com/thebrokenrail/sorcerycraft/spell/util/SpellTag.java index fc2e650..582ccd5 100644 --- a/src/main/java/com/thebrokenrail/sorcerycraft/spell/util/SpellTag.java +++ b/src/main/java/com/thebrokenrail/sorcerycraft/spell/util/SpellTag.java @@ -71,13 +71,9 @@ public class SpellTag { for (int i = 0; i < spells.size(); i++) { CompoundTag spell = spells.getCompound(i); - String idStr = spell.getString("id"); - Identifier id = new Identifier(idStr); - if (!idStr.equals(id.toString())) { - id = new Identifier(SorceryCraft.NAMESPACE, idStr); - } - + Identifier id = new Identifier(spell.getString("id")); int level = spell.getInt("level"); + if (map.get(id) == null || map.get(id) < level) { map.put(id, level); } @@ -104,7 +100,7 @@ public class SpellTag { boolean changed = false; for (Map.Entry entry : itemSpells.entrySet()) { - Spell spell = SpellRegistry.getSpell(entry.getKey(), entry.getValue()); + Spell spell = SpellRegistry.getSpell(entry); if (spell != null) { if (spell.getLevel() >= spell.getMaxLevel()) { spell = SpellRegistry.getSpell(entry.getKey(), spell.getMaxLevel() - 1); diff --git a/src/main/resources/assets/sorcerycraft/lang/en_us.json b/src/main/resources/assets/sorcerycraft/lang/en_us.json index e225255..7246e7a 100644 --- a/src/main/resources/assets/sorcerycraft/lang/en_us.json +++ b/src/main/resources/assets/sorcerycraft/lang/en_us.json @@ -19,5 +19,6 @@ "spell.sorcerycraft.flame_spell": "Flame", "spell.sorcerycraft.levitate_spell": "Levitate", "spell.sorcerycraft.teleport_spell": "Teleport", - "spell.sorcerycraft.inward_spell": "Inward" + "spell.sorcerycraft.inward_spell": "Inward", + "spell.sorcerycraft.cooling_spell": "Cooling" } \ No newline at end of file