Fix Crash
SorceryCraft/pipeline/head This commit looks good Details

Add Teleport Spell
This commit is contained in:
TheBrokenRail 2020-03-02 17:11:37 -05:00
parent b377d8b7f0
commit 32f7371291
11 changed files with 122 additions and 17 deletions

View File

@ -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;
@ -47,7 +50,7 @@ public class SorceryCraft implements ModInitializer, ClientModInitializer {
public static BlockItem CASTING_TABLE_BLOCK_ITEM; public static BlockItem CASTING_TABLE_BLOCK_ITEM;
public static ItemGroup ITEM_GROUP; public static ItemGroup ITEM_GROUP;
public static EntityType<SpellEntity> SPELL_ENTITY; public static EntityType<SpellEntity> SPELL_ENTITY;
public static final Identifier[] LOOT_TABLES = new Identifier[] { public static final Identifier[] LOOT_TABLES = new Identifier[]{
LootTables.SIMPLE_DUNGEON_CHEST, LootTables.SIMPLE_DUNGEON_CHEST,
LootTables.END_CITY_TREASURE_CHEST, LootTables.END_CITY_TREASURE_CHEST,
LootTables.NETHER_BRIDGE_CHEST, LootTables.NETHER_BRIDGE_CHEST,

View File

@ -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;
@ -101,7 +104,7 @@ public class CastingTableContainer extends Container {
int k; int k;
for (k = 0; k < 3; ++k) { for (k = 0; k < 3; ++k) {
for(int j = 0; j < 9; ++j) { for (int j = 0; j < 9; ++j) {
addSlot(new Slot(playerInventory, j + k * 9 + 9, 108 + j * 18, 84 + k * 18)); addSlot(new Slot(playerInventory, j + k * 9 + 9, 108 + j * 18, 84 + k * 18));
} }
} }
@ -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;

View File

@ -155,7 +155,7 @@ public class CastingTableScreen extends ContainerScreen<CastingTableContainer> {
int k = j + 139; int k = j + 139;
int l = i - 7; int l = i - 7;
float f = ((float) mouseY - (float) j - 13.5F) / ((float) (k - j) - 27.0F); float f = ((float) mouseY - (float) j - 13.5F) / ((float) (k - j) - 27.0F);
f = f * (float)l + 0.5F; f = f * (float) l + 0.5F;
indexStartOffset = MathHelper.clamp((int) f, 0, l); indexStartOffset = MathHelper.clamp((int) f, 0, l);
return true; return true;
} else { } else {
@ -168,7 +168,7 @@ public class CastingTableScreen extends ContainerScreen<CastingTableContainer> {
scrolling = false; scrolling = false;
int i = (width - containerWidth) / 2; int i = (width - containerWidth) / 2;
int j = (height - containerHeight) / 2; int j = (height - containerHeight) / 2;
if (this.canScroll(container.getRecipes().length) && mouseX > (double)(i + 94) && mouseX < (double) (i + 94 + 6) && mouseY > (double) (j + 18) && mouseY <= (double) (j + 18 + 139 + 1)) { if (this.canScroll(container.getRecipes().length) && mouseX > (double) (i + 94) && mouseX < (double) (i + 94 + 6) && mouseY > (double) (j + 18) && mouseY <= (double) (j + 18 + 139 + 1)) {
scrolling = true; scrolling = true;
} }

View File

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

View File

@ -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;
@ -28,7 +36,7 @@ public class SpellItem extends Item {
} }
@Override @Override
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<String, Integer> spells = SpellTag.getSpells(itemStack); Map<String, Integer> spells = SpellTag.getSpells(itemStack);

View File

@ -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) {

View File

@ -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) {

View File

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

View File

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

View File

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

View File

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