1.0.11
All checks were successful
SorceryCraft/pipeline/head This commit looks good

Allow Spells to Affect Blocks
Add Cooling Spell
This commit is contained in:
TheBrokenRail 2020-03-07 15:12:46 -05:00
parent b88132eb29
commit 07d1d44f52
14 changed files with 104 additions and 47 deletions

View File

@ -1,5 +1,9 @@
### Changelog ### Changelog
**1.0.11**
* Allow Spells to Affect Blocks
* Add Cooling Spell
**1.0.10** **1.0.10**
* Add Issues Link * Add Issues Link

View File

@ -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. | | Steadfast | 1 | Prevents Spell from rebounding. |
| Teleport | 2 | Teleports target to random location. | | 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. | | 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 ## ```/spell``` Command
This command requires OP permissions. This command requires OP permissions.

View File

@ -10,7 +10,7 @@ org.gradle.jvmargs = -Xmx1G
loader_version = 0.7.8+build.186 loader_version = 0.7.8+build.186
# Mod Properties # Mod Properties
mod_version = 1.0.10 mod_version = 1.0.11
maven_group = com.thebrokenrail maven_group = com.thebrokenrail
archives_base_name = sorcerycraft archives_base_name = sorcerycraft

View File

@ -1,21 +1,21 @@
package com.thebrokenrail.sorcerycraft.client.entity; package com.thebrokenrail.sorcerycraft.client.entity;
import com.thebrokenrail.sorcerycraft.entity.SpellEntity;
import net.fabricmc.api.EnvType; import net.fabricmc.api.EnvType;
import net.fabricmc.api.Environment; import net.fabricmc.api.Environment;
import net.minecraft.client.render.entity.EntityRenderDispatcher; import net.minecraft.client.render.entity.EntityRenderDispatcher;
import net.minecraft.client.render.entity.EntityRenderer; import net.minecraft.client.render.entity.EntityRenderer;
import net.minecraft.container.PlayerContainer; import net.minecraft.container.PlayerContainer;
import net.minecraft.entity.AreaEffectCloudEntity;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
@Environment(EnvType.CLIENT) @Environment(EnvType.CLIENT)
public class SpellEntityRenderer extends EntityRenderer<AreaEffectCloudEntity> { public class SpellEntityRenderer extends EntityRenderer<SpellEntity> {
public SpellEntityRenderer(EntityRenderDispatcher entityRenderDispatcher) { public SpellEntityRenderer(EntityRenderDispatcher entityRenderDispatcher) {
super(entityRenderDispatcher); super(entityRenderDispatcher);
} }
@Override @Override
public Identifier getTexture(AreaEffectCloudEntity areaEffectCloudEntity) { public Identifier getTexture(SpellEntity spellEntity) {
return PlayerContainer.BLOCK_ATLAS_TEXTURE; return PlayerContainer.BLOCK_ATLAS_TEXTURE;
} }
} }

View File

@ -5,8 +5,6 @@ import com.thebrokenrail.sorcerycraft.spell.registry.Spell;
import com.thebrokenrail.sorcerycraft.spell.registry.SpellRegistry; import com.thebrokenrail.sorcerycraft.spell.registry.SpellRegistry;
import com.thebrokenrail.sorcerycraft.spell.util.SpellTag; import com.thebrokenrail.sorcerycraft.spell.util.SpellTag;
import com.thebrokenrail.sorcerycraft.spell.registry.Spells; 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.Entity;
import net.minecraft.entity.EntityType; import net.minecraft.entity.EntityType;
import net.minecraft.entity.LivingEntity; import net.minecraft.entity.LivingEntity;
@ -16,12 +14,12 @@ import net.minecraft.item.Item;
import net.minecraft.network.Packet; import net.minecraft.network.Packet;
import net.minecraft.network.packet.s2c.play.EntitySpawnS2CPacket; import net.minecraft.network.packet.s2c.play.EntitySpawnS2CPacket;
import net.minecraft.particle.ParticleTypes; import net.minecraft.particle.ParticleTypes;
import net.minecraft.server.command.ParticleCommand;
import net.minecraft.server.network.ServerPlayerEntity; import net.minecraft.server.network.ServerPlayerEntity;
import net.minecraft.server.world.ServerWorld; import net.minecraft.server.world.ServerWorld;
import net.minecraft.sound.SoundCategory; import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvents; import net.minecraft.sound.SoundEvents;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.hit.EntityHitResult; import net.minecraft.util.hit.EntityHitResult;
import net.minecraft.util.hit.HitResult; import net.minecraft.util.hit.HitResult;
import net.minecraft.world.World; import net.minecraft.world.World;
@ -39,8 +37,6 @@ public class SpellEntity extends ThrownItemEntity {
super(SorceryCraft.SPELL_ENTITY, owner, world); super(SorceryCraft.SPELL_ENTITY, owner, world);
} }
private boolean firstTick = true;
public SpellEntity(World world, double x, double y, double z) { public SpellEntity(World world, double x, double y, double z) {
super(SorceryCraft.SPELL_ENTITY, x, y, z, world); super(SorceryCraft.SPELL_ENTITY, x, y, z, world);
} }
@ -51,19 +47,21 @@ public class SpellEntity extends ThrownItemEntity {
@Override @Override
protected void onCollision(HitResult hitResult) { protected void onCollision(HitResult hitResult) {
if (!getEntityWorld().isClient()) {
Map<Identifier, Integer> spells = SpellTag.getSpells(getItem()); Map<Identifier, Integer> spells = SpellTag.getSpells(getItem());
if (!spells.containsKey(Spells.INWARD_SPELL)) { 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();
boolean success = didSpellSucceed(spells); boolean success = didSpellSucceed(spells);
for (Map.Entry<Identifier, Integer> entry : spells.entrySet()) { for (Map.Entry<Identifier, Integer> entry : spells.entrySet()) {
Spell spell = SpellRegistry.getSpell(entry.getKey(), entry.getValue()); Spell spell = SpellRegistry.getSpell(entry);
if (spell != null) { if (spell != null) {
if (success) { if (success) {
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()); spell.execute(entity, this, getOwner());
}
} else if (getOwner() != null) { } else if (getOwner() != null) {
if (getOwner() instanceof PlayerEntity) { if (getOwner() instanceof PlayerEntity) {
PlayerEntity player = (PlayerEntity) getOwner(); PlayerEntity player = (PlayerEntity) getOwner();
@ -73,7 +71,6 @@ public class SpellEntity extends ThrownItemEntity {
} }
} }
} }
remove(); remove();
} }
} }
@ -82,14 +79,13 @@ public class SpellEntity extends ThrownItemEntity {
@Override @Override
public void tick() { public void tick() {
super.tick(); super.tick();
if (firstTick) { if (!getEntityWorld().isClient()) {
firstTick = false;
Map<Identifier, Integer> spells = SpellTag.getSpells(getItem()); Map<Identifier, Integer> spells = SpellTag.getSpells(getItem());
if (spells.containsKey(Spells.INWARD_SPELL)) { if (spells.containsKey(Spells.INWARD_SPELL)) {
if (getOwner() != null) { if (getOwner() != null) {
boolean success = didSpellSucceed(spells); boolean success = didSpellSucceed(spells);
for (Map.Entry<Identifier, Integer> entry : spells.entrySet()) { for (Map.Entry<Identifier, Integer> entry : spells.entrySet()) {
Spell spell = SpellRegistry.getSpell(entry.getKey(), entry.getValue()); Spell spell = SpellRegistry.getSpell(entry);
if (spell != null) { if (spell != null) {
if (success) { if (success) {
spell.execute(getOwner(), this, getOwner()); spell.execute(getOwner(), this, getOwner());
@ -103,8 +99,7 @@ public class SpellEntity extends ThrownItemEntity {
remove(); remove();
return; return;
} }
}
if (!getEntityWorld().isClient()) {
List<ServerPlayerEntity> viewers = Objects.requireNonNull(getServer()).getPlayerManager().getPlayerList(); List<ServerPlayerEntity> viewers = Objects.requireNonNull(getServer()).getPlayerManager().getPlayerList();
for (ServerPlayerEntity viewer : viewers) { for (ServerPlayerEntity viewer : viewers) {
((ServerWorld) getEntityWorld()).spawnParticles(viewer, ParticleTypes.WITCH, true, getX(), getY(), getZ(), 8, 0.01d, 0.01d, 0.01d, 0.5d); ((ServerWorld) getEntityWorld()).spawnParticles(viewer, ParticleTypes.WITCH, true, getX(), getY(), getZ(), 8, 0.01d, 0.01d, 0.01d, 0.5d);

View File

@ -52,7 +52,7 @@ public class SpellItem extends Item {
@Override @Override
public boolean hasEnchantmentGlint(ItemStack stack) { public boolean hasEnchantmentGlint(ItemStack stack) {
Map<Identifier, Integer> spells = SpellTag.getSpells(stack); Map<Identifier, Integer> spells = SpellTag.getSpells(stack);
return spells.size() > 0; return spells.size() > 0 || super.hasEnchantmentGlint(stack);
} }
@Override @Override

View File

@ -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;
}
}

View File

@ -1,10 +1,14 @@
package com.thebrokenrail.sorcerycraft.spell; package com.thebrokenrail.sorcerycraft.spell;
import com.thebrokenrail.sorcerycraft.spell.registry.Spell; import com.thebrokenrail.sorcerycraft.spell.registry.Spell;
import net.minecraft.block.AbstractFireBlock;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.item.Items; import net.minecraft.item.Items;
import net.minecraft.util.Identifier; 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 class FlameSpell extends Spell {
public FlameSpell(Identifier id, int level) { public FlameSpell(Identifier id, int level) {
@ -16,6 +20,14 @@ public class FlameSpell extends Spell {
target.setFireTicks(400 + (getLevel() * 200)); 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 @Override
public int getXPCost() { public int getXPCost() {
switch (getLevel()) { switch (getLevel()) {

View File

@ -1,7 +1,6 @@
package com.thebrokenrail.sorcerycraft.spell; package com.thebrokenrail.sorcerycraft.spell;
import com.thebrokenrail.sorcerycraft.spell.registry.Spell; import com.thebrokenrail.sorcerycraft.spell.registry.Spell;
import net.minecraft.entity.Entity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.item.Items; import net.minecraft.item.Items;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
@ -11,11 +10,6 @@ public class InwardSpell extends Spell {
super(id, level); super(id, level);
} }
@Override
public void execute(Entity target, Entity source, Entity attacker) {
// NOOP
}
@Override @Override
public int getXPCost() { public int getXPCost() {
return 16; return 16;

View File

@ -1,7 +1,6 @@
package com.thebrokenrail.sorcerycraft.spell; package com.thebrokenrail.sorcerycraft.spell;
import com.thebrokenrail.sorcerycraft.spell.registry.Spell; import com.thebrokenrail.sorcerycraft.spell.registry.Spell;
import net.minecraft.entity.Entity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.item.Items; import net.minecraft.item.Items;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
@ -11,11 +10,6 @@ public class SteadfastSpell extends Spell {
super(id, level); super(id, level);
} }
@Override
public void execute(Entity target, Entity source, Entity attacker) {
// NOOP
}
@Override @Override
public int getXPCost() { public int getXPCost() {
return 18; return 18;

View File

@ -3,6 +3,8 @@ package com.thebrokenrail.sorcerycraft.spell.registry;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.world.World;
public abstract class Spell { public abstract class Spell {
private final Identifier id; private final Identifier id;
@ -21,7 +23,13 @@ public abstract class Spell {
return level; 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(); public abstract int getXPCost();

View File

@ -1,6 +1,7 @@
package com.thebrokenrail.sorcerycraft.spell.registry; package com.thebrokenrail.sorcerycraft.spell.registry;
import com.thebrokenrail.sorcerycraft.SorceryCraft; import com.thebrokenrail.sorcerycraft.SorceryCraft;
import com.thebrokenrail.sorcerycraft.spell.CoolingSpell;
import com.thebrokenrail.sorcerycraft.spell.DamageSpell; import com.thebrokenrail.sorcerycraft.spell.DamageSpell;
import com.thebrokenrail.sorcerycraft.spell.DissolveSpell; import com.thebrokenrail.sorcerycraft.spell.DissolveSpell;
import com.thebrokenrail.sorcerycraft.spell.FlameSpell; 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.LevitateSpell;
import com.thebrokenrail.sorcerycraft.spell.SteadfastSpell; import com.thebrokenrail.sorcerycraft.spell.SteadfastSpell;
import com.thebrokenrail.sorcerycraft.spell.TeleportSpell; import com.thebrokenrail.sorcerycraft.spell.TeleportSpell;
import com.thebrokenrail.sorcerycraft.spell.registry.SpellRegistry;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
@SuppressWarnings("unused") @SuppressWarnings("unused")
@ -22,6 +22,7 @@ public class Spells {
public static final Identifier LEVITATE_SPELL; public static final Identifier LEVITATE_SPELL;
public static final Identifier TELEPORT_SPELL; public static final Identifier TELEPORT_SPELL;
public static final Identifier INWARD_SPELL; public static final Identifier INWARD_SPELL;
public static final Identifier COOLING_SPELL;
static { static {
HEAL_SPELL = SpellRegistry.registerSpell(new Identifier(SorceryCraft.NAMESPACE, "heal_spell"), HealSpell.class); 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); LEVITATE_SPELL = SpellRegistry.registerSpell(new Identifier(SorceryCraft.NAMESPACE, "levitate_spell"), LevitateSpell.class);
TELEPORT_SPELL = SpellRegistry.registerSpell(new Identifier(SorceryCraft.NAMESPACE, "teleport_spell"), TeleportSpell.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); INWARD_SPELL = SpellRegistry.registerSpell(new Identifier(SorceryCraft.NAMESPACE, "inward_spell"), InwardSpell.class);
COOLING_SPELL = SpellRegistry.registerSpell(new Identifier(SorceryCraft.NAMESPACE, "cooling_spell"), CoolingSpell.class);
} }
} }

View File

@ -71,13 +71,9 @@ public class SpellTag {
for (int i = 0; i < spells.size(); i++) { for (int i = 0; i < spells.size(); i++) {
CompoundTag spell = spells.getCompound(i); CompoundTag spell = spells.getCompound(i);
String idStr = spell.getString("id"); Identifier id = new Identifier(spell.getString("id"));
Identifier id = new Identifier(idStr);
if (!idStr.equals(id.toString())) {
id = new Identifier(SorceryCraft.NAMESPACE, idStr);
}
int level = spell.getInt("level"); int level = spell.getInt("level");
if (map.get(id) == null || map.get(id) < level) { if (map.get(id) == null || map.get(id) < level) {
map.put(id, level); map.put(id, level);
} }
@ -104,7 +100,7 @@ public class SpellTag {
boolean changed = false; boolean changed = false;
for (Map.Entry<Identifier, Integer> entry : itemSpells.entrySet()) { for (Map.Entry<Identifier, Integer> entry : itemSpells.entrySet()) {
Spell spell = SpellRegistry.getSpell(entry.getKey(), entry.getValue()); Spell spell = SpellRegistry.getSpell(entry);
if (spell != null) { if (spell != null) {
if (spell.getLevel() >= spell.getMaxLevel()) { if (spell.getLevel() >= spell.getMaxLevel()) {
spell = SpellRegistry.getSpell(entry.getKey(), spell.getMaxLevel() - 1); spell = SpellRegistry.getSpell(entry.getKey(), spell.getMaxLevel() - 1);

View File

@ -19,5 +19,6 @@
"spell.sorcerycraft.flame_spell": "Flame", "spell.sorcerycraft.flame_spell": "Flame",
"spell.sorcerycraft.levitate_spell": "Levitate", "spell.sorcerycraft.levitate_spell": "Levitate",
"spell.sorcerycraft.teleport_spell": "Teleport", "spell.sorcerycraft.teleport_spell": "Teleport",
"spell.sorcerycraft.inward_spell": "Inward" "spell.sorcerycraft.inward_spell": "Inward",
"spell.sorcerycraft.cooling_spell": "Cooling"
} }