Fixed projectiles and other entities not spawning, fixed the staff

This commit is contained in:
Sollace 2020-05-03 22:42:16 +02:00
parent 9c4568e707
commit 9e6da2f64a
6 changed files with 70 additions and 12 deletions

View file

@ -7,7 +7,9 @@ import com.minelittlepony.unicopia.magic.Caster;
import com.minelittlepony.unicopia.magic.MagicEffect;
import com.minelittlepony.unicopia.magic.TossedMagicEffect;
import com.minelittlepony.unicopia.magic.spell.SpellRegistry;
import com.minelittlepony.unicopia.network.Channel;
import com.minelittlepony.unicopia.network.EffectSync;
import com.minelittlepony.unicopia.network.MsgSpawnProjectile;
import com.minelittlepony.unicopia.util.projectile.AdvancedProjectile;
import com.minelittlepony.unicopia.util.projectile.Tossable;
import com.minelittlepony.unicopia.util.projectile.TossableItem;
@ -24,6 +26,7 @@ import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.Items;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.network.Packet;
import net.minecraft.particle.ItemStackParticleEffect;
import net.minecraft.particle.ParticleEffect;
import net.minecraft.particle.ParticleTypes;
@ -205,7 +208,7 @@ public class ProjectileEntity extends ThrownItemEntity implements IMagicals, Adv
@Override
public void launch(Entity entityThrower, float pitch, float yaw, float wobble, float velocity, float inaccuracy) {
setVelocity(pitch, yaw, wobble, velocity, inaccuracy);
setProperties(entityThrower, pitch, yaw, wobble, velocity, inaccuracy);
}
private ParticleEffect getParticleParameters() {
@ -289,4 +292,9 @@ public class ProjectileEntity extends ThrownItemEntity implements IMagicals, Adv
remove();
}
}
@Override
public Packet<?> createSpawnPacket() {
return Channel.SPAWN_PROJECTILE.toPacket(new MsgSpawnProjectile(this));
}
}

View file

@ -16,7 +16,6 @@ import com.minelittlepony.unicopia.util.projectile.TossableItem;
import net.minecraft.block.BlockState;
import net.minecraft.client.item.TooltipContext;
import net.minecraft.entity.Entity;
import net.minecraft.entity.EquipmentSlot;
import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.damage.DamageSource;
@ -26,7 +25,6 @@ import net.minecraft.particle.ParticleTypes;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvents;
import net.minecraft.text.Text;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.TypedActionResult;
import net.minecraft.util.math.BlockPos;
@ -54,9 +52,8 @@ public class EnchantedStaffItem extends StaffItem implements Affine, TossableIte
if (EquinePredicates.PLAYER_UNICORN.test(player) && hand == Hand.MAIN_HAND) {
ItemStack itemstack = player.getStackInHand(hand);
player.swingHand(hand);
return new TypedActionResult<>(ActionResult.SUCCESS, itemstack);
player.setCurrentHand(hand);
return TypedActionResult.consume(itemstack);
}
return super.use(world, player, hand);
@ -91,15 +88,15 @@ public class EnchantedStaffItem extends StaffItem implements Affine, TossableIte
return false;
}
public void onUpdate(ItemStack stack, World world, Entity entity, int itemSlot, boolean isSelected) {
@Override
public void usageTick(World world, LivingEntity entity, ItemStack stack, int ticksRemaining) {
if (entity instanceof LivingEntity) {
LivingEntity living = (LivingEntity)entity;
LivingEntity living = entity;
if (living.getActiveItem().getItem() == this) {
Vec3d eyes = entity.getCameraPosVec(1);
float i = getMaxUseTime(stack) - living.getItemUseTimeLeft();
float i = getMaxUseTime(stack) - ticksRemaining;
world.addParticle(i > 150 ? ParticleTypes.LARGE_SMOKE : ParticleTypes.CLOUD, eyes.x, eyes.y, eyes.z,
(world.random.nextGaussian() - 0.5) / 10,

View file

@ -1,6 +1,7 @@
package com.minelittlepony.unicopia.magic;
import com.minelittlepony.unicopia.entity.SpellcastEntity;
import com.minelittlepony.unicopia.entity.UEntities;
import com.minelittlepony.unicopia.magic.spell.SpellRegistry;
import net.minecraft.item.ItemStack;
@ -46,7 +47,7 @@ public interface Castable extends MagicalItem, Dispensable {
* Called to cast a spell. The result is an entity spawned with the spell attached.
*/
default SpellcastEntity castContainedSpell(World world, BlockPos pos, ItemStack stack, MagicEffect effect) {
SpellcastEntity spell = new SpellcastEntity(null, world);
SpellcastEntity spell = new SpellcastEntity(UEntities.MAGIC_SPELL, world);
spell.setAffinity(getAffinity(stack));
spell.updatePositionAndAngles(pos.getX() + 0.5, pos.getY() + 0.5, pos.getZ() + 0.5, 0, 0);

View file

@ -3,6 +3,7 @@ package com.minelittlepony.unicopia.magic;
import javax.annotation.Nullable;
import com.minelittlepony.unicopia.entity.ProjectileEntity;
import com.minelittlepony.unicopia.entity.UEntities;
import com.minelittlepony.unicopia.item.UItems;
import com.minelittlepony.unicopia.magic.spell.SpellRegistry;
import com.minelittlepony.unicopia.util.projectile.AdvancedProjectile;
@ -49,7 +50,7 @@ public interface TossedMagicEffect extends MagicEffect, Tossable<Caster<?>> {
world.playSound(null, entity.getX(), entity.getY(), entity.getZ(), getThrowSound(caster), SoundCategory.NEUTRAL, 0.7F, 0.4F / (world.random.nextFloat() * 0.4F + 0.8F));
if (caster.isLocal()) {
AdvancedProjectile projectile = new ProjectileEntity(null, world, caster.getOwner());
AdvancedProjectile projectile = new ProjectileEntity(UEntities.THROWN_ITEM, world, caster.getOwner());
projectile.setItem(getCastAppearance(caster));
projectile.setThrowDamage(getThrowDamage(caster));

View file

@ -20,6 +20,7 @@ public interface Channel {
SPacketType<MsgPlayerCapabilities> BROADCAST_CAPABILITIES = broadcast(PLAYER_CAPABILITIES, MsgPlayerCapabilities::new);
CPacketType<MsgSpawnRainbow> SPAWN_RAINBOW = serverToClient(new Identifier("unicopia", "rainbow_entity"), MsgSpawnRainbow::new);
CPacketType<MsgSpawnProjectile> SPAWN_PROJECTILE = serverToClient(new Identifier("unicopia", "projectile_entity"), MsgSpawnProjectile::new);
static void bootstrap() { }

View file

@ -0,0 +1,50 @@
package com.minelittlepony.unicopia.network;
import java.io.IOException;
import net.fabricmc.fabric.api.network.PacketContext;
import net.minecraft.client.network.packet.EntitySpawnS2CPacket;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.entity.Entity;
import net.minecraft.util.PacketByteBuf;
import net.minecraft.world.World;
public class MsgSpawnProjectile extends EntitySpawnS2CPacket implements Channel.Packet {
MsgSpawnProjectile(PacketByteBuf buffer) {
try {
read(buffer);
} catch (IOException e) { }
}
public MsgSpawnProjectile(Entity e) {
super(e);
}
@Override
public void toBuffer(PacketByteBuf buffer) {
try {
write(buffer);
} catch (IOException e) {
}
}
@Override
public void handle(PacketContext context) {
World world = context.getPlayer().world;
Entity entity = getEntityTypeId().create(world);
entity.updateTrackedPosition(getX(), getY(), getZ());
entity.pitch = getPitch() * 360 / 256.0F;
entity.yaw = getYaw() * 360 / 256.0F;
entity.setEntityId(getId());
entity.setUuid(getUuid());
((ClientWorld)world).addEntity(getId(), entity);
}
}