Add Teleport Spell
This commit is contained in:
parent
b377d8b7f0
commit
32f7371291
@ -28,7 +28,10 @@ import net.minecraft.client.MinecraftClient;
|
|||||||
import net.minecraft.entity.EntityCategory;
|
import net.minecraft.entity.EntityCategory;
|
||||||
import net.minecraft.entity.EntityDimensions;
|
import net.minecraft.entity.EntityDimensions;
|
||||||
import net.minecraft.entity.EntityType;
|
import net.minecraft.entity.EntityType;
|
||||||
import net.minecraft.item.*;
|
import net.minecraft.item.BlockItem;
|
||||||
|
import net.minecraft.item.Item;
|
||||||
|
import net.minecraft.item.ItemGroup;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.loot.BinomialLootTableRange;
|
import net.minecraft.loot.BinomialLootTableRange;
|
||||||
import net.minecraft.loot.LootTables;
|
import net.minecraft.loot.LootTables;
|
||||||
import net.minecraft.loot.entry.ItemEntry;
|
import net.minecraft.loot.entry.ItemEntry;
|
||||||
|
@ -5,7 +5,10 @@ import com.thebrokenrail.sorcerycraft.spell.Spell;
|
|||||||
import com.thebrokenrail.sorcerycraft.spell.SpellPlayerEntity;
|
import com.thebrokenrail.sorcerycraft.spell.SpellPlayerEntity;
|
||||||
import com.thebrokenrail.sorcerycraft.spell.SpellRegistry;
|
import com.thebrokenrail.sorcerycraft.spell.SpellRegistry;
|
||||||
import com.thebrokenrail.sorcerycraft.spell.SpellTag;
|
import com.thebrokenrail.sorcerycraft.spell.SpellTag;
|
||||||
import net.minecraft.container.*;
|
import net.minecraft.container.BlockContext;
|
||||||
|
import net.minecraft.container.Container;
|
||||||
|
import net.minecraft.container.ContainerType;
|
||||||
|
import net.minecraft.container.Slot;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
import net.minecraft.entity.player.PlayerInventory;
|
import net.minecraft.entity.player.PlayerInventory;
|
||||||
import net.minecraft.inventory.BasicInventory;
|
import net.minecraft.inventory.BasicInventory;
|
||||||
@ -162,7 +165,7 @@ public class CastingTableContainer extends Container {
|
|||||||
if (!stack.isEmpty()) {
|
if (!stack.isEmpty()) {
|
||||||
for (int i = 3; i < 39; ++i) {
|
for (int i = 3; i < 39; ++i) {
|
||||||
ItemStack itemStack = slots.get(i).getStack();
|
ItemStack itemStack = slots.get(i).getStack();
|
||||||
if (!itemStack.isEmpty() && stack.getItem() == itemStack.getItem()) {
|
if (!itemStack.isEmpty() && itemCompatible(stack, itemStack)) {
|
||||||
ItemStack invSlot = inventory.getInvStack(slot);
|
ItemStack invSlot = inventory.getInvStack(slot);
|
||||||
int count = invSlot.isEmpty() ? 0 : invSlot.getCount();
|
int count = invSlot.isEmpty() ? 0 : invSlot.getCount();
|
||||||
int requiredCount = Math.min((onlyOne ? 1 : stack.getMaxCount()) - count, itemStack.getCount());
|
int requiredCount = Math.min((onlyOne ? 1 : stack.getMaxCount()) - count, itemStack.getCount());
|
||||||
@ -179,6 +182,10 @@ public class CastingTableContainer extends Container {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private boolean itemCompatible(ItemStack itemStack, ItemStack otherItemStack) {
|
||||||
|
return itemStack.getItem() == otherItemStack.getItem();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean canUse(PlayerEntity player) {
|
public boolean canUse(PlayerEntity player) {
|
||||||
return true;
|
return true;
|
||||||
|
@ -6,7 +6,9 @@ import com.thebrokenrail.sorcerycraft.spell.SpellRegistry;
|
|||||||
import com.thebrokenrail.sorcerycraft.spell.SpellTag;
|
import com.thebrokenrail.sorcerycraft.spell.SpellTag;
|
||||||
import net.fabricmc.api.EnvType;
|
import net.fabricmc.api.EnvType;
|
||||||
import net.fabricmc.api.Environment;
|
import net.fabricmc.api.Environment;
|
||||||
import net.minecraft.entity.*;
|
import net.minecraft.entity.Entity;
|
||||||
|
import net.minecraft.entity.EntityType;
|
||||||
|
import net.minecraft.entity.LivingEntity;
|
||||||
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;
|
||||||
|
@ -3,7 +3,10 @@ package com.thebrokenrail.sorcerycraft.item;
|
|||||||
import com.thebrokenrail.sorcerycraft.SorceryCraft;
|
import com.thebrokenrail.sorcerycraft.SorceryCraft;
|
||||||
import com.thebrokenrail.sorcerycraft.entity.SpellEntity;
|
import com.thebrokenrail.sorcerycraft.entity.SpellEntity;
|
||||||
import com.thebrokenrail.sorcerycraft.packet.LearnedNewSpellS2CPacket;
|
import com.thebrokenrail.sorcerycraft.packet.LearnedNewSpellS2CPacket;
|
||||||
import com.thebrokenrail.sorcerycraft.spell.*;
|
import com.thebrokenrail.sorcerycraft.spell.Spell;
|
||||||
|
import com.thebrokenrail.sorcerycraft.spell.SpellPlayerEntity;
|
||||||
|
import com.thebrokenrail.sorcerycraft.spell.SpellRegistry;
|
||||||
|
import com.thebrokenrail.sorcerycraft.spell.SpellTag;
|
||||||
import net.minecraft.client.item.TooltipContext;
|
import net.minecraft.client.item.TooltipContext;
|
||||||
import net.minecraft.entity.Entity;
|
import net.minecraft.entity.Entity;
|
||||||
import net.minecraft.entity.player.PlayerEntity;
|
import net.minecraft.entity.player.PlayerEntity;
|
||||||
@ -15,7 +18,12 @@ import net.minecraft.sound.SoundEvents;
|
|||||||
import net.minecraft.text.LiteralText;
|
import net.minecraft.text.LiteralText;
|
||||||
import net.minecraft.text.Text;
|
import net.minecraft.text.Text;
|
||||||
import net.minecraft.text.TranslatableText;
|
import net.minecraft.text.TranslatableText;
|
||||||
import net.minecraft.util.*;
|
import net.minecraft.util.ActionResult;
|
||||||
|
import net.minecraft.util.DefaultedList;
|
||||||
|
import net.minecraft.util.Formatting;
|
||||||
|
import net.minecraft.util.Hand;
|
||||||
|
import net.minecraft.util.Rarity;
|
||||||
|
import net.minecraft.util.TypedActionResult;
|
||||||
import net.minecraft.world.World;
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
|
@ -16,7 +16,8 @@ import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
|||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
@Mixin(ClientPlayNetworkHandler.class)
|
@Mixin(ClientPlayNetworkHandler.class)
|
||||||
public class MixinClientPlayNetworkHandler {
|
public class MixinClientPlayNetworkHandler {
|
||||||
@Shadow private ClientWorld world;
|
@Shadow
|
||||||
|
private ClientWorld world;
|
||||||
|
|
||||||
@Inject(method = "onEntitySpawn", at = @At(value = "TAIL"))
|
@Inject(method = "onEntitySpawn", at = @At(value = "TAIL"))
|
||||||
public void onEntitySpawn(EntitySpawnS2CPacket packet, CallbackInfo callbackInfo) {
|
public void onEntitySpawn(EntitySpawnS2CPacket packet, CallbackInfo callbackInfo) {
|
||||||
|
@ -9,12 +9,13 @@ import org.spongepowered.asm.mixin.injection.At;
|
|||||||
import org.spongepowered.asm.mixin.injection.Inject;
|
import org.spongepowered.asm.mixin.injection.Inject;
|
||||||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
@SuppressWarnings("unused")
|
@SuppressWarnings("unused")
|
||||||
@Mixin(PlayerEntity.class)
|
@Mixin(PlayerEntity.class)
|
||||||
public class MixinPlayerEntity implements SpellPlayerEntity {
|
public class MixinPlayerEntity implements SpellPlayerEntity {
|
||||||
private Map<String, Integer> spells;
|
private Map<String, Integer> spells = new HashMap<>();
|
||||||
|
|
||||||
@Inject(at = @At("HEAD"), method = "readCustomDataFromTag")
|
@Inject(at = @At("HEAD"), method = "readCustomDataFromTag")
|
||||||
public void readCustomDataFromTag(CompoundTag tag, CallbackInfo info) {
|
public void readCustomDataFromTag(CompoundTag tag, CallbackInfo info) {
|
||||||
|
@ -1,14 +1,14 @@
|
|||||||
package com.thebrokenrail.sorcerycraft.spell;
|
package com.thebrokenrail.sorcerycraft.spell;
|
||||||
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import net.minecraft.item.ItemStack;
|
import net.minecraft.item.ItemStack;
|
||||||
import net.minecraft.loot.condition.LootCondition;
|
import net.minecraft.loot.condition.LootCondition;
|
||||||
import net.minecraft.loot.context.LootContext;
|
import net.minecraft.loot.context.LootContext;
|
||||||
import net.minecraft.loot.function.ConditionalLootFunction;
|
import net.minecraft.loot.function.ConditionalLootFunction;
|
||||||
import net.minecraft.loot.function.LootFunction;
|
import net.minecraft.loot.function.LootFunction;
|
||||||
|
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public class RandomSpellLootTableFunction extends ConditionalLootFunction {
|
public class RandomSpellLootTableFunction extends ConditionalLootFunction {
|
||||||
private RandomSpellLootTableFunction(LootCondition[] conditions) {
|
private RandomSpellLootTableFunction(LootCondition[] conditions) {
|
||||||
super(conditions);
|
super(conditions);
|
||||||
|
@ -57,5 +57,6 @@ public class SpellRegistry {
|
|||||||
SpellRegistry.registerSpell("steadfast_spell", SteadfastSpell.class);
|
SpellRegistry.registerSpell("steadfast_spell", SteadfastSpell.class);
|
||||||
SpellRegistry.registerSpell("flame_spell", FlameSpell.class);
|
SpellRegistry.registerSpell("flame_spell", FlameSpell.class);
|
||||||
SpellRegistry.registerSpell("levitate_spell", LevitateSpell.class);
|
SpellRegistry.registerSpell("levitate_spell", LevitateSpell.class);
|
||||||
|
SpellRegistry.registerSpell("teleport_spell", TeleportSpell.class);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,81 @@
|
|||||||
|
package com.thebrokenrail.sorcerycraft.spell;
|
||||||
|
|
||||||
|
import net.minecraft.entity.Entity;
|
||||||
|
import net.minecraft.entity.LivingEntity;
|
||||||
|
import net.minecraft.entity.effect.StatusEffects;
|
||||||
|
import net.minecraft.item.ItemStack;
|
||||||
|
import net.minecraft.item.Items;
|
||||||
|
import net.minecraft.sound.SoundCategory;
|
||||||
|
import net.minecraft.sound.SoundEvents;
|
||||||
|
import net.minecraft.util.math.MathHelper;
|
||||||
|
import net.minecraft.world.World;
|
||||||
|
|
||||||
|
public class TeleportSpell extends Spell {
|
||||||
|
public TeleportSpell(String id, int level) {
|
||||||
|
super(id, level);
|
||||||
|
}
|
||||||
|
|
||||||
|
private int getMaxTeleport(World world) {
|
||||||
|
return world.getDimension().isNether() ? 128 : 256;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public void execute(Entity target, Entity source, Entity attacker) {
|
||||||
|
World world = target.getEntityWorld();
|
||||||
|
int range = 16 + (8 * getLevel());
|
||||||
|
if (target instanceof LivingEntity) {
|
||||||
|
LivingEntity user = (LivingEntity) target;
|
||||||
|
if (!world.isClient()) {
|
||||||
|
double d = user.getX();
|
||||||
|
double e = user.getY();
|
||||||
|
double f = user.getZ();
|
||||||
|
|
||||||
|
for (int i = 0; i < range; ++i) {
|
||||||
|
double x = user.getX() + (user.getRandom().nextDouble() - 0.5D) * range;
|
||||||
|
double y = MathHelper.clamp(user.getY() + (double) (user.getRandom().nextInt(range) - (range / 2)), 0d, getMaxTeleport(world) - 1);
|
||||||
|
double z = user.getZ() + (user.getRandom().nextDouble() - 0.5D) * range;
|
||||||
|
if (user.hasVehicle()) {
|
||||||
|
user.stopRiding();
|
||||||
|
}
|
||||||
|
|
||||||
|
if (user.teleport(x, y, z, true)) {
|
||||||
|
world.playSound(null, d, e, f, SoundEvents.ITEM_CHORUS_FRUIT_TELEPORT, SoundCategory.PLAYERS, 1.0F, 1.0F);
|
||||||
|
user.playSound(SoundEvents.ITEM_CHORUS_FRUIT_TELEPORT, 1.0F, 1.0F);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getXPCost() {
|
||||||
|
switch (getLevel()) {
|
||||||
|
case 0: {
|
||||||
|
return 12;
|
||||||
|
}
|
||||||
|
case 1: {
|
||||||
|
return 18;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public ItemStack getItemCost() {
|
||||||
|
switch (getLevel()) {
|
||||||
|
case 0: {
|
||||||
|
return new ItemStack(Items.ENDER_PEARL);
|
||||||
|
}
|
||||||
|
case 1: {
|
||||||
|
return new ItemStack(Items.CHORUS_FRUIT);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return ItemStack.EMPTY;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int getMaxLevel() {
|
||||||
|
return 2;
|
||||||
|
}
|
||||||
|
}
|
@ -14,5 +14,6 @@
|
|||||||
"spell.sorcerycraft.dissolve_spell": "Dissolve",
|
"spell.sorcerycraft.dissolve_spell": "Dissolve",
|
||||||
"spell.sorcerycraft.steadfast_spell": "Steadfast",
|
"spell.sorcerycraft.steadfast_spell": "Steadfast",
|
||||||
"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"
|
||||||
}
|
}
|
Reference in New Issue
Block a user