From dd228acf79c097c33a8e03d6658f007972075306 Mon Sep 17 00:00:00 2001 From: TheBrokenRail Date: Tue, 3 Mar 2020 20:22:40 -0500 Subject: [PATCH] 1.0.5 Clean up code --- CHANGELOG.md | 3 ++ README.md | 13 ++++++-- build.gradle | 1 - gradle.properties | 2 +- .../sorcerycraft/SorceryCraft.java | 6 +++- .../block/CastingTableContainer.java | 9 +++--- .../sorcerycraft/entity/SpellEntity.java | 7 ++++- .../sorcerycraft/item/SpellItem.java | 31 +++++++------------ 8 files changed, 43 insertions(+), 29 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index f9e82b1..948a9d9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,8 @@ ### Changelog +**1.0.5** +* Clean up code + **1.0.4** * Migrate old worlds to new ID system diff --git a/README.md b/README.md index cda8c86..6f1d531 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ You can apply Spells to blank or existing Spells in the Casting Table. Doing so -#### Casting table +#### Casting Table @@ -58,4 +58,13 @@ You can apply Spells to blank or existing Spells in the Casting Table. Doing so | Levitate | 2 | Gives target the Levitation effect. | | 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. | \ No newline at end of file +| Inward | 1 | Causes the Spell to target the player. If the Spell fails instead of rebounding, it will just do nothing. | + +## ```/spell``` Command +This command requires OP permissions. + +#### ```/spell clear ``` +This command clears all known spells from the given player. + +#### ```/spell list ``` +This lists all the spells the given player knows. \ No newline at end of file diff --git a/build.gradle b/build.gradle index 01d3753..5ccd6dc 100644 --- a/build.gradle +++ b/build.gradle @@ -7,7 +7,6 @@ compileJava { targetCompatibility = JavaVersion.VERSION_1_8 } -archivesBaseName = project.archives_base_name version = project.mod_version as Object group = project.maven_group as Object diff --git a/gradle.properties b/gradle.properties index 1d36ae6..e754adf 100644 --- a/gradle.properties +++ b/gradle.properties @@ -8,7 +8,7 @@ org.gradle.jvmargs = -Xmx1G loader_version = 0.7.8+build.184 # Mod Properties - mod_version = 1.0.4 + mod_version = 1.0.5 maven_group = com.thebrokenrail archives_base_name = sorcerycraft diff --git a/src/main/java/com/thebrokenrail/sorcerycraft/SorceryCraft.java b/src/main/java/com/thebrokenrail/sorcerycraft/SorceryCraft.java index e7b18f0..de279b9 100644 --- a/src/main/java/com/thebrokenrail/sorcerycraft/SorceryCraft.java +++ b/src/main/java/com/thebrokenrail/sorcerycraft/SorceryCraft.java @@ -139,8 +139,12 @@ public class SorceryCraft implements ModInitializer, ClientModInitializer { private static final SoundEvent SPELL_SOUND_EFFECT = SoundEvents.BLOCK_ENCHANTMENT_TABLE_USE; + public static void playSpellSound(World world, BlockPos pos) { + world.playSound(null, pos, SPELL_SOUND_EFFECT, SoundCategory.BLOCKS, 1.0f, 1.0f); + } + public static void playSpellSound(BlockPointer block) { - block.getWorld().playSound(null, block.getBlockPos(), SPELL_SOUND_EFFECT, SoundCategory.BLOCKS, 1.0f, 1.0f); + playSpellSound(block.getWorld(), block.getBlockPos()); } public static void playSpellSound(PlayerEntity player) { diff --git a/src/main/java/com/thebrokenrail/sorcerycraft/block/CastingTableContainer.java b/src/main/java/com/thebrokenrail/sorcerycraft/block/CastingTableContainer.java index 67de7b7..f62ebf5 100644 --- a/src/main/java/com/thebrokenrail/sorcerycraft/block/CastingTableContainer.java +++ b/src/main/java/com/thebrokenrail/sorcerycraft/block/CastingTableContainer.java @@ -16,10 +16,13 @@ import net.minecraft.inventory.CraftingResultInventory; import net.minecraft.inventory.Inventory; import net.minecraft.item.ItemStack; import net.minecraft.util.Identifier; +import net.minecraft.util.math.BlockPos; +import net.minecraft.world.World; import java.util.ArrayList; import java.util.List; import java.util.Map; +import java.util.function.BiConsumer; public class CastingTableContainer extends Container { private final Inventory inventory; @@ -94,7 +97,7 @@ public class CastingTableContainer extends Container { player.addExperienceLevels(-spells[index].getXPCost()); } - SorceryCraft.playSpellSound(player); + context.run((BiConsumer) SorceryCraft::playSpellSound); CastingTableContainer.this.inventory.setInvStack(0, ItemStack.EMPTY); CastingTableContainer.this.inventory.takeInvStack(1, spells[index].getItemCost().getCount()); @@ -133,9 +136,7 @@ public class CastingTableContainer extends Container { @Override public void close(PlayerEntity player) { super.close(player); - context.run((world, blockPos) -> { - dropInventory(player, world, inventory); - }); + context.run((BiConsumer) (world, blockPos) -> dropInventory(player, world, inventory)); } @Override diff --git a/src/main/java/com/thebrokenrail/sorcerycraft/entity/SpellEntity.java b/src/main/java/com/thebrokenrail/sorcerycraft/entity/SpellEntity.java index 470be28..312dd73 100644 --- a/src/main/java/com/thebrokenrail/sorcerycraft/entity/SpellEntity.java +++ b/src/main/java/com/thebrokenrail/sorcerycraft/entity/SpellEntity.java @@ -10,11 +10,13 @@ import net.fabricmc.api.Environment; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityType; import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.thrown.ThrownItemEntity; 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.sound.SoundCategory; import net.minecraft.sound.SoundEvents; import net.minecraft.util.Identifier; import net.minecraft.util.hit.EntityHitResult; @@ -58,7 +60,10 @@ public class SpellEntity extends ThrownItemEntity { if (success) { spell.execute(entity, this, getOwner()); } else if (getOwner() != null) { - getOwner().playSound(SoundEvents.ENCHANT_THORNS_HIT, 1.0f, 1.0f); + if (getOwner() instanceof PlayerEntity) { + PlayerEntity player = (PlayerEntity) getOwner(); + player.playSound(SoundEvents.ENCHANT_THORNS_HIT, SoundCategory.PLAYERS, 1.0f, 1.0f); + } spell.execute(getOwner(), this, getOwner()); } } diff --git a/src/main/java/com/thebrokenrail/sorcerycraft/item/SpellItem.java b/src/main/java/com/thebrokenrail/sorcerycraft/item/SpellItem.java index d23ff68..6c9a43c 100644 --- a/src/main/java/com/thebrokenrail/sorcerycraft/item/SpellItem.java +++ b/src/main/java/com/thebrokenrail/sorcerycraft/item/SpellItem.java @@ -37,26 +37,20 @@ public class SpellItem extends Item { public TypedActionResult use(World world, PlayerEntity playerEntity, Hand hand) { ItemStack itemStack = playerEntity.getStackInHand(hand); - Map spells = SpellTag.getSpells(itemStack); + SorceryCraft.playSpellSound(playerEntity); - if (spells.size() > 0) { - SorceryCraft.playSpellSound(playerEntity); - - if (!world.isClient()) { - SpellEntity entity = new SpellEntity(world, playerEntity); - entity.setItem(itemStack); - entity.setProperties(playerEntity, playerEntity.pitch, playerEntity.yaw, 0.0f, 1.5f, 1.0f); - world.spawnEntity(entity); - } - - if (!playerEntity.isCreative()) { - itemStack.decrement(1); - } - - return new TypedActionResult<>(ActionResult.SUCCESS, itemStack); - } else { - return new TypedActionResult<>(ActionResult.FAIL, itemStack); + if (!world.isClient()) { + SpellEntity entity = new SpellEntity(world, playerEntity); + entity.setItem(itemStack); + entity.setProperties(playerEntity, playerEntity.pitch, playerEntity.yaw, 0.0f, 1.5f, 1.0f); + world.spawnEntity(entity); } + + if (!playerEntity.isCreative()) { + itemStack.decrement(1); + } + + return new TypedActionResult<>(ActionResult.SUCCESS, itemStack); } @Override @@ -124,7 +118,6 @@ public class SpellItem extends Item { } if (changed) { - //LearnedNewSpellS2CPacket.send((ServerPlayerEntity) player); SorceryCraft.playSpellSound(player); spellPlayer.setSpells(playerSpells); }
Lapis Lazuli