diff --git a/src/main/java/fathertoast/specialmobs/client/ClientRegister.java b/src/main/java/fathertoast/specialmobs/client/ClientRegister.java index ee13ce0..2f4ae21 100644 --- a/src/main/java/fathertoast/specialmobs/client/ClientRegister.java +++ b/src/main/java/fathertoast/specialmobs/client/ClientRegister.java @@ -10,6 +10,7 @@ import fathertoast.specialmobs.common.entity.witherskeleton.NinjaWitherSkeletonE import mcp.MethodsReturnNonnullByDefault; import net.minecraft.client.Minecraft; import net.minecraft.client.renderer.ItemRenderer; +import net.minecraft.client.renderer.RenderTypeLookup; import net.minecraft.client.renderer.entity.SpriteRenderer; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityType; diff --git a/src/main/java/fathertoast/specialmobs/common/core/register/SMItems.java b/src/main/java/fathertoast/specialmobs/common/core/register/SMItems.java index 089ccf4..476b769 100644 --- a/src/main/java/fathertoast/specialmobs/common/core/register/SMItems.java +++ b/src/main/java/fathertoast/specialmobs/common/core/register/SMItems.java @@ -1,6 +1,7 @@ package fathertoast.specialmobs.common.core.register; import fathertoast.specialmobs.common.core.SpecialMobs; +import fathertoast.specialmobs.common.item.IncorporealFireChargeItem; import fathertoast.specialmobs.common.item.SyringeItem; import net.minecraft.entity.Entity; import net.minecraft.entity.EntityType; @@ -22,6 +23,7 @@ public class SMItems { public static final RegistryObject SYRINGE = registerSimpleItem("syringe", SyringeItem::new); + public static final RegistryObject INCORPOREAL_FIREBALL = registerSimpleItem("incorporeal_fire_charge", IncorporealFireChargeItem::new); /** Registers an entity type's spawn egg item to the deferred register. */ diff --git a/src/main/java/fathertoast/specialmobs/common/entity/ghast/CorporealShiftGhastEntity.java b/src/main/java/fathertoast/specialmobs/common/entity/ghast/CorporealShiftGhastEntity.java index 56807f4..82fd165 100644 --- a/src/main/java/fathertoast/specialmobs/common/entity/ghast/CorporealShiftGhastEntity.java +++ b/src/main/java/fathertoast/specialmobs/common/entity/ghast/CorporealShiftGhastEntity.java @@ -3,6 +3,7 @@ package fathertoast.specialmobs.common.entity.ghast; import fathertoast.specialmobs.common.bestiary.BestiaryInfo; import fathertoast.specialmobs.common.bestiary.MobFamily; import fathertoast.specialmobs.common.bestiary.SpecialMob; +import fathertoast.specialmobs.common.core.register.SMItems; import fathertoast.specialmobs.common.entity.SpecialMobData; import fathertoast.specialmobs.common.entity.projectile.CorporealShiftFireballEntity; import fathertoast.specialmobs.common.util.AttributeHelper; @@ -60,7 +61,7 @@ public class CorporealShiftGhastEntity extends _SpecialGhastEntity { public static void buildLootTable( LootTableBuilder loot ) { addBaseLoot( loot ); // TODO - Uh uhm uhhhhh hmmm.. - loot.addSemicommonDrop( "semicommon", Items.POISONOUS_POTATO ); + loot.addSemicommonDrop( "semicommon", SMItems.INCORPOREAL_FIREBALL.get() ); } @SpecialMob.Factory diff --git a/src/main/java/fathertoast/specialmobs/common/entity/projectile/CorporealShiftFireballEntity.java b/src/main/java/fathertoast/specialmobs/common/entity/projectile/CorporealShiftFireballEntity.java index dfc0caf..84e4da2 100644 --- a/src/main/java/fathertoast/specialmobs/common/entity/projectile/CorporealShiftFireballEntity.java +++ b/src/main/java/fathertoast/specialmobs/common/entity/projectile/CorporealShiftFireballEntity.java @@ -3,6 +3,7 @@ package fathertoast.specialmobs.common.entity.projectile; import fathertoast.specialmobs.common.bestiary.SpecialMob; import fathertoast.specialmobs.common.core.SpecialMobs; import fathertoast.specialmobs.common.core.register.SMEntities; +import fathertoast.specialmobs.common.core.register.SMItems; import fathertoast.specialmobs.common.entity.ghast.CorporealShiftGhastEntity; import fathertoast.specialmobs.common.util.References; import net.minecraft.entity.Entity; @@ -50,7 +51,14 @@ public class CorporealShiftFireballEntity extends AbstractFireballEntity { super(SMEntities.CORPOREAL_FIREBALL.get(), ghast, x, y, z, world); setCorporeal(ghast.isCorporeal()); target = ghast.getTarget(); - setItem(isCorporeal() ? new ItemStack(Items.FIRE_CHARGE) : new ItemStack(Items.ENDER_PEARL)); + setItem(isCorporeal() ? new ItemStack(Items.FIRE_CHARGE) : new ItemStack(SMItems.INCORPOREAL_FIREBALL.get())); + } + + public CorporealShiftFireballEntity(World world, PlayerEntity owner, LivingEntity target, double x, double y, double z) { + super(SMEntities.CORPOREAL_FIREBALL.get(), owner, x, y, z, world); + setCorporeal(false); + this.target = target; + setItem(new ItemStack(SMItems.INCORPOREAL_FIREBALL.get())); } @SpecialMob.LanguageProvider @@ -97,6 +105,7 @@ public class CorporealShiftFireballEntity extends AbstractFireballEntity { @Override protected boolean shouldBurn() { + // Hee hee hee haw return isCorporeal(); } @@ -104,6 +113,8 @@ public class CorporealShiftFireballEntity extends AbstractFireballEntity { protected void onHit(RayTraceResult traceResult) { super.onHit(traceResult); + // Only go boom if the fireball is corporeal. + // If not, pass through blocks to be a menace. if (!level.isClientSide && isCorporeal()) { shouldExplode = true; } @@ -119,6 +130,8 @@ public class CorporealShiftFireballEntity extends AbstractFireballEntity { if (!isCorporeal()) { // TODO - Figure out why this is cringe + // TODO part 2. - What the fuck + // TODO part 3. - HELP SpecialMobs.LOG.info("X={}, XO={}", target.getX(), target.xo); SpecialMobs.LOG.info("Z={}, ZO={}", target.getZ(), target.zo); diff --git a/src/main/java/fathertoast/specialmobs/common/item/IncorporealFireChargeItem.java b/src/main/java/fathertoast/specialmobs/common/item/IncorporealFireChargeItem.java new file mode 100644 index 0000000..68a891a --- /dev/null +++ b/src/main/java/fathertoast/specialmobs/common/item/IncorporealFireChargeItem.java @@ -0,0 +1,44 @@ +package fathertoast.specialmobs.common.item; + +import fathertoast.specialmobs.common.bestiary.SpecialMob; +import fathertoast.specialmobs.common.network.NetworkHelper; +import fathertoast.specialmobs.common.util.EntityUtil; +import fathertoast.specialmobs.common.util.References; +import net.minecraft.entity.Entity; +import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.item.Item; +import net.minecraft.item.ItemGroup; +import net.minecraft.item.ItemStack; +import net.minecraft.item.Rarity; +import net.minecraft.util.ActionResult; +import net.minecraft.util.Hand; +import net.minecraft.util.SoundCategory; +import net.minecraft.util.SoundEvents; +import net.minecraft.world.World; + +public class IncorporealFireChargeItem extends Item { + + public IncorporealFireChargeItem() { + super(new Item.Properties().stacksTo(1).tab(ItemGroup.TAB_MISC).rarity(Rarity.UNCOMMON)); + } + + @SpecialMob.LanguageProvider + public static String[] getTranslations( String langKey ) { + return References.translations( langKey, "Incorporeal Fire Charge", + "", "", "", "", "", "" );//TODO + } + + @Override + public ActionResult use(World world, PlayerEntity player, Hand hand) { + if (world.isClientSide) { + Entity entity = EntityUtil.getClientMouseOver(player); + + if (entity instanceof LivingEntity) { + NetworkHelper.spawnIncorporealFireball(player, (LivingEntity) entity); + } + world.playSound(null, player.blockPosition(), SoundEvents.FIRECHARGE_USE, SoundCategory.BLOCKS, 1.0F, (random.nextFloat() - random.nextFloat()) * 0.2F + 1.0F); + } + return ActionResult.sidedSuccess(player.getItemInHand(hand), world.isClientSide); + } +} diff --git a/src/main/java/fathertoast/specialmobs/common/network/NetworkHelper.java b/src/main/java/fathertoast/specialmobs/common/network/NetworkHelper.java index f292cbe..9c3dfcd 100644 --- a/src/main/java/fathertoast/specialmobs/common/network/NetworkHelper.java +++ b/src/main/java/fathertoast/specialmobs/common/network/NetworkHelper.java @@ -1,5 +1,14 @@ package fathertoast.specialmobs.common.network; +import fathertoast.specialmobs.common.network.message.C2SSpawnIncorporealFireball; +import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.player.PlayerEntity; + +import javax.annotation.Nonnull; + public class NetworkHelper { + public static void spawnIncorporealFireball(@Nonnull PlayerEntity player, @Nonnull LivingEntity livingEntity) { + PacketHandler.CHANNEL.sendToServer(new C2SSpawnIncorporealFireball(player.getUUID(), livingEntity.getId())); + } } diff --git a/src/main/java/fathertoast/specialmobs/common/network/PacketHandler.java b/src/main/java/fathertoast/specialmobs/common/network/PacketHandler.java index f7c6df0..3f46ffd 100644 --- a/src/main/java/fathertoast/specialmobs/common/network/PacketHandler.java +++ b/src/main/java/fathertoast/specialmobs/common/network/PacketHandler.java @@ -1,6 +1,7 @@ package fathertoast.specialmobs.common.network; import fathertoast.specialmobs.common.core.SpecialMobs; +import fathertoast.specialmobs.common.network.message.C2SSpawnIncorporealFireball; import net.minecraft.entity.player.ServerPlayerEntity; import net.minecraft.network.PacketBuffer; import net.minecraft.util.ResourceLocation; @@ -33,11 +34,11 @@ public class PacketHandler { } public final void registerMessages() { - + registerMessage(C2SSpawnIncorporealFireball.class, C2SSpawnIncorporealFireball::encode, C2SSpawnIncorporealFireball::decode, C2SSpawnIncorporealFireball::handle); } - public void registerMessage(Class messageType, BiConsumer encoder, Function decoder, BiConsumer> messageConsumer) { - CHANNEL.registerMessage(this.messageIndex++, messageType, encoder, decoder, messageConsumer, Optional.empty()); + public void registerMessage(Class messageType, BiConsumer encoder, Function decoder, BiConsumer> handler) { + CHANNEL.registerMessage(this.messageIndex++, messageType, encoder, decoder, handler, Optional.empty()); } /** diff --git a/src/main/java/fathertoast/specialmobs/common/network/message/C2SSpawnIncorporealFireball.java b/src/main/java/fathertoast/specialmobs/common/network/message/C2SSpawnIncorporealFireball.java new file mode 100644 index 0000000..c4046a3 --- /dev/null +++ b/src/main/java/fathertoast/specialmobs/common/network/message/C2SSpawnIncorporealFireball.java @@ -0,0 +1,37 @@ +package fathertoast.specialmobs.common.network.message; + +import fathertoast.specialmobs.common.network.work.ServerWork; +import net.minecraft.network.PacketBuffer; +import net.minecraftforge.fml.network.NetworkEvent; + +import java.util.UUID; +import java.util.function.Supplier; + +public class C2SSpawnIncorporealFireball { + + public final UUID playerUUID; + public final int targetEntityID; + + public C2SSpawnIncorporealFireball(UUID playerUUID, int targetEntityId) { + this.playerUUID = playerUUID; + this.targetEntityID = targetEntityId; + } + + public static void handle(C2SSpawnIncorporealFireball message, Supplier contextSupplier) { + NetworkEvent.Context context = contextSupplier.get(); + + if (context.getDirection().getReceptionSide().isServer()) { + context.enqueueWork(() -> ServerWork.handleSpawnIncorporealFireball(message)); + } + context.setPacketHandled(true); + } + + public static C2SSpawnIncorporealFireball decode(PacketBuffer buffer) { + return new C2SSpawnIncorporealFireball(buffer.readUUID(), buffer.readInt()); + } + + public static void encode(C2SSpawnIncorporealFireball message, PacketBuffer buffer) { + buffer.writeUUID(message.playerUUID); + buffer.writeInt(message.targetEntityID); + } +} diff --git a/src/main/java/fathertoast/specialmobs/common/network/work/ServerWork.java b/src/main/java/fathertoast/specialmobs/common/network/work/ServerWork.java new file mode 100644 index 0000000..b15773f --- /dev/null +++ b/src/main/java/fathertoast/specialmobs/common/network/work/ServerWork.java @@ -0,0 +1,36 @@ +package fathertoast.specialmobs.common.network.work; + +import fathertoast.specialmobs.common.entity.projectile.CorporealShiftFireballEntity; +import fathertoast.specialmobs.common.network.message.C2SSpawnIncorporealFireball; +import net.minecraft.entity.Entity; +import net.minecraft.entity.LivingEntity; +import net.minecraft.entity.player.ServerPlayerEntity; +import net.minecraft.server.MinecraftServer; +import net.minecraft.world.server.ServerWorld; +import net.minecraftforge.fml.LogicalSide; +import net.minecraftforge.fml.LogicalSidedProvider; + +public class ServerWork { + + public static void handleSpawnIncorporealFireball(C2SSpawnIncorporealFireball message) { + MinecraftServer server = LogicalSidedProvider.INSTANCE.get(LogicalSide.SERVER); + + if (server == null) + return; + + ServerPlayerEntity player = server.getPlayerList().getPlayer(message.playerUUID); + + if (player == null) + return; + + ServerWorld world = (ServerWorld) player.level; + Entity entity = world.getEntity(message.targetEntityID); + + if (!(entity instanceof LivingEntity)) + return; + + LivingEntity livingEntity = (LivingEntity) entity; + CorporealShiftFireballEntity fireballEntity = new CorporealShiftFireballEntity(world, player, livingEntity, player.getX(), player.getEyeY(), player.getZ()); + world.addFreshEntity(fireballEntity); + } + } diff --git a/src/main/java/fathertoast/specialmobs/common/util/EntityUtil.java b/src/main/java/fathertoast/specialmobs/common/util/EntityUtil.java new file mode 100644 index 0000000..3806788 --- /dev/null +++ b/src/main/java/fathertoast/specialmobs/common/util/EntityUtil.java @@ -0,0 +1,27 @@ +package fathertoast.specialmobs.common.util; + +import fathertoast.specialmobs.common.core.SpecialMobs; +import net.minecraft.client.Minecraft; +import net.minecraft.entity.Entity; +import net.minecraft.entity.player.PlayerEntity; +import net.minecraft.util.math.EntityRayTraceResult; +import net.minecraft.util.math.RayTraceResult; + +import javax.annotation.Nullable; + +public class EntityUtil { + + @Nullable + public static Entity getClientMouseOver(PlayerEntity player) { + if (!player.level.isClientSide) { + SpecialMobs.LOG.error("Tried to fetch player \"mouse-over\" entity from server side. This can't be right?"); + return null; + } + RayTraceResult result = Minecraft.getInstance().hitResult; + + if (result instanceof EntityRayTraceResult) { + return ((EntityRayTraceResult)result).getEntity(); + } + return null; + } +} diff --git a/src/main/resources/assets/specialmobs/textures/item/incorporeal_fire_charge.png b/src/main/resources/assets/specialmobs/textures/item/incorporeal_fire_charge.png new file mode 100644 index 0000000..3691f58 Binary files /dev/null and b/src/main/resources/assets/specialmobs/textures/item/incorporeal_fire_charge.png differ