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

Clean up code
This commit is contained in:
TheBrokenRail 2020-03-03 20:22:40 -05:00
parent e2cfd1d656
commit dd228acf79
8 changed files with 43 additions and 29 deletions

View File

@ -1,5 +1,8 @@
### Changelog ### Changelog
**1.0.5**
* Clean up code
**1.0.4** **1.0.4**
* Migrate old worlds to new ID system * Migrate old worlds to new ID system

View File

@ -29,7 +29,7 @@ You can apply Spells to blank or existing Spells in the Casting Table. Doing so
</tr> </tr>
</table> </table>
#### Casting table #### Casting Table
<table> <table>
<tr> <tr>
<td>Lapis Lazuli</td> <td>Lapis Lazuli</td>
@ -59,3 +59,12 @@ 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. |
## ```/spell``` Command
This command requires OP permissions.
#### ```/spell clear <player>```
This command clears all known spells from the given player.
#### ```/spell list <player>```
This lists all the spells the given player knows.

View File

@ -7,7 +7,6 @@ compileJava {
targetCompatibility = JavaVersion.VERSION_1_8 targetCompatibility = JavaVersion.VERSION_1_8
} }
archivesBaseName = project.archives_base_name
version = project.mod_version as Object version = project.mod_version as Object
group = project.maven_group as Object group = project.maven_group as Object

View File

@ -8,7 +8,7 @@ org.gradle.jvmargs = -Xmx1G
loader_version = 0.7.8+build.184 loader_version = 0.7.8+build.184
# Mod Properties # Mod Properties
mod_version = 1.0.4 mod_version = 1.0.5
maven_group = com.thebrokenrail maven_group = com.thebrokenrail
archives_base_name = sorcerycraft archives_base_name = sorcerycraft

View File

@ -139,8 +139,12 @@ public class SorceryCraft implements ModInitializer, ClientModInitializer {
private static final SoundEvent SPELL_SOUND_EFFECT = SoundEvents.BLOCK_ENCHANTMENT_TABLE_USE; 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) { 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) { public static void playSpellSound(PlayerEntity player) {

View File

@ -16,10 +16,13 @@ import net.minecraft.inventory.CraftingResultInventory;
import net.minecraft.inventory.Inventory; import net.minecraft.inventory.Inventory;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.function.BiConsumer;
public class CastingTableContainer extends Container { public class CastingTableContainer extends Container {
private final Inventory inventory; private final Inventory inventory;
@ -94,7 +97,7 @@ public class CastingTableContainer extends Container {
player.addExperienceLevels(-spells[index].getXPCost()); player.addExperienceLevels(-spells[index].getXPCost());
} }
SorceryCraft.playSpellSound(player); context.run((BiConsumer<World, BlockPos>) SorceryCraft::playSpellSound);
CastingTableContainer.this.inventory.setInvStack(0, ItemStack.EMPTY); CastingTableContainer.this.inventory.setInvStack(0, ItemStack.EMPTY);
CastingTableContainer.this.inventory.takeInvStack(1, spells[index].getItemCost().getCount()); CastingTableContainer.this.inventory.takeInvStack(1, spells[index].getItemCost().getCount());
@ -133,9 +136,7 @@ public class CastingTableContainer extends Container {
@Override @Override
public void close(PlayerEntity player) { public void close(PlayerEntity player) {
super.close(player); super.close(player);
context.run((world, blockPos) -> { context.run((BiConsumer<World, BlockPos>) (world, blockPos) -> dropInventory(player, world, inventory));
dropInventory(player, world, inventory);
});
} }
@Override @Override

View File

@ -10,11 +10,13 @@ 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;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.thrown.ThrownItemEntity; import net.minecraft.entity.thrown.ThrownItemEntity;
import net.minecraft.item.Item; 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.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.EntityHitResult; import net.minecraft.util.hit.EntityHitResult;
@ -58,7 +60,10 @@ public class SpellEntity extends ThrownItemEntity {
if (success) { if (success) {
spell.execute(entity, this, getOwner()); spell.execute(entity, this, getOwner());
} else if (getOwner() != null) { } 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()); spell.execute(getOwner(), this, getOwner());
} }
} }

View File

@ -37,26 +37,20 @@ public class SpellItem extends Item {
public TypedActionResult<ItemStack> use(World world, PlayerEntity playerEntity, Hand hand) { public TypedActionResult<ItemStack> use(World world, PlayerEntity playerEntity, Hand hand) {
ItemStack itemStack = playerEntity.getStackInHand(hand); ItemStack itemStack = playerEntity.getStackInHand(hand);
Map<Identifier, Integer> spells = SpellTag.getSpells(itemStack); SorceryCraft.playSpellSound(playerEntity);
if (spells.size() > 0) { if (!world.isClient()) {
SorceryCraft.playSpellSound(playerEntity); SpellEntity entity = new SpellEntity(world, playerEntity);
entity.setItem(itemStack);
if (!world.isClient()) { entity.setProperties(playerEntity, playerEntity.pitch, playerEntity.yaw, 0.0f, 1.5f, 1.0f);
SpellEntity entity = new SpellEntity(world, playerEntity); world.spawnEntity(entity);
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 (!playerEntity.isCreative()) {
itemStack.decrement(1);
}
return new TypedActionResult<>(ActionResult.SUCCESS, itemStack);
} }
@Override @Override
@ -124,7 +118,6 @@ public class SpellItem extends Item {
} }
if (changed) { if (changed) {
//LearnedNewSpellS2CPacket.send((ServerPlayerEntity) player);
SorceryCraft.playSpellSound(player); SorceryCraft.playSpellSound(player);
spellPlayer.setSpells(playerSpells); spellPlayer.setSpells(playerSpells);
} }