diff --git a/common/src/main/kotlin/com/cobblemon/mod/common/api/tags/CobblemonItemTags.kt b/common/src/main/kotlin/com/cobblemon/mod/common/api/tags/CobblemonItemTags.kt index b0111a0891..d627a525cf 100644 --- a/common/src/main/kotlin/com/cobblemon/mod/common/api/tags/CobblemonItemTags.kt +++ b/common/src/main/kotlin/com/cobblemon/mod/common/api/tags/CobblemonItemTags.kt @@ -121,7 +121,10 @@ object CobblemonItemTags { @JvmField val POWER_LENS = create("held/power_lens") @JvmField val POWER_WEIGHT = create("held/power_weight") @JvmField val TERRAIN_SEEDS = create("held/terrain_seeds") - + //Wearable Held Item Tags + @JvmField val WEARABLE_EYE_ITEMS = create("wearable/eyes.json") + @JvmField val WEARABLE_HAT_ITEMS = create("wearable/hats.json") + @JvmField val HIDDEN_ITEMS = create("wearable/hidden.json") private fun create(path: String) = TagKey.create(Registries.ITEM, cobblemonResource(path)) diff --git a/common/src/main/kotlin/com/cobblemon/mod/common/client/gui/summary/Summary.kt b/common/src/main/kotlin/com/cobblemon/mod/common/client/gui/summary/Summary.kt index 90872847ab..facdb9c734 100644 --- a/common/src/main/kotlin/com/cobblemon/mod/common/client/gui/summary/Summary.kt +++ b/common/src/main/kotlin/com/cobblemon/mod/common/client/gui/summary/Summary.kt @@ -89,6 +89,8 @@ class Summary private constructor(party: Collection, private val edita private val typeSpacerDoubleResource = cobblemonResource("textures/gui/summary/type_spacer_double.png") private val sideSpacerResource = cobblemonResource("textures/gui/summary/summary_side_spacer.png") private val evolveButtonResource = cobblemonResource("textures/gui/summary/summary_evolve_button.png") + private val itemVisibleResource = cobblemonResource("textures/gui/summary/item_visible.png") + private val itemHiddenResource = cobblemonResource("textures/gui/summary/item_hidden.png") private val tabIconInfo = cobblemonResource("textures/gui/summary/summary_tab_icon_info.png") private val tabIconMoves = cobblemonResource("textures/gui/summary/summary_tab_icon_moves.png") private val tabIconStats = cobblemonResource("textures/gui/summary/summary_tab_icon_stats.png") @@ -168,6 +170,32 @@ class Summary private constructor(party: Collection, private val edita ) ) + //Item Visibility Button + val hideHeldItemBtn = SummaryButton( + buttonX = x + 22f, + buttonY = y + 101f, + buttonWidth = 13, + buttonHeight = 9, + clickAction = { + selectedPokemon.isItemHidden=!selectedPokemon.isItemHidden + }, + resource = itemVisibleResource, + renderRequirement = { !selectedPokemon.heldItem().isEmpty && !selectedPokemon.isItemHidden }, + clickRequirement = { !selectedPokemon.heldItem().isEmpty }, + ) + val showHeldItemBtn = SummaryButton( + buttonX = x + 22f, + buttonY = y + 101f, + buttonWidth = 13, + buttonHeight = 9, + clickAction = { }, + resource = itemHiddenResource, + renderRequirement = { !selectedPokemon.heldItem().isEmpty && selectedPokemon.isItemHidden }, + clickRequirement = { false }, + ) + addRenderableWidget(showHeldItemBtn) + addRenderableWidget(hideHeldItemBtn) + // Init Tabs summaryTabs.clear() summaryTabs.add( diff --git a/common/src/main/kotlin/com/cobblemon/mod/common/client/render/pokemon/PokemonRenderer.kt b/common/src/main/kotlin/com/cobblemon/mod/common/client/render/pokemon/PokemonRenderer.kt index a93b3e0f32..361e918480 100644 --- a/common/src/main/kotlin/com/cobblemon/mod/common/client/render/pokemon/PokemonRenderer.kt +++ b/common/src/main/kotlin/com/cobblemon/mod/common/client/render/pokemon/PokemonRenderer.kt @@ -10,7 +10,10 @@ package com.cobblemon.mod.common.client.render.pokemon import com.cobblemon.mod.common.Cobblemon import com.cobblemon.mod.common.api.pokedex.PokedexEntryProgress +import com.cobblemon.mod.common.api.tags.CobblemonItemTags.WEARABLE_EYE_ITEMS +import com.cobblemon.mod.common.api.tags.CobblemonItemTags.WEARABLE_HAT_ITEMS import com.cobblemon.mod.common.client.CobblemonClient +import com.cobblemon.mod.common.client.CobblemonClient.storage import com.cobblemon.mod.common.client.battle.ClientBallDisplay import com.cobblemon.mod.common.client.entity.NPCClientDelegate import com.cobblemon.mod.common.client.entity.PokemonClientDelegate @@ -18,6 +21,7 @@ import com.cobblemon.mod.common.client.entity.PokemonClientDelegate.Companion.BE import com.cobblemon.mod.common.client.entity.PokemonClientDelegate.Companion.BEAM_SHRINK_TIME import com.cobblemon.mod.common.client.keybind.boundKey import com.cobblemon.mod.common.client.keybind.keybinds.PartySendBinding +import com.cobblemon.mod.common.client.render.MatrixWrapper import com.cobblemon.mod.common.client.render.models.blockbench.PosableModel import com.cobblemon.mod.common.client.render.models.blockbench.PosableState import com.cobblemon.mod.common.client.render.models.blockbench.pokemon.PosablePokemonEntityModel @@ -34,13 +38,13 @@ import com.cobblemon.mod.common.entity.pokeball.EmptyPokeBallEntity import com.cobblemon.mod.common.entity.pokemon.PokemonEntity import com.cobblemon.mod.common.entity.pokemon.PokemonEntity.Companion.SPAWN_DIRECTION import com.cobblemon.mod.common.pokeball.PokeBall +import com.cobblemon.mod.common.pokemon.Pokemon import com.cobblemon.mod.common.util.* import com.cobblemon.mod.common.util.math.DoubleRange import com.cobblemon.mod.common.util.math.geometry.toRadians import com.cobblemon.mod.common.util.math.remap import com.mojang.blaze3d.vertex.PoseStack import com.mojang.math.Axis -import kotlin.math.* import net.minecraft.ChatFormatting import net.minecraft.client.Minecraft import net.minecraft.client.gui.Font.DisplayMode @@ -55,11 +59,14 @@ import net.minecraft.network.chat.Style import net.minecraft.resources.ResourceLocation import net.minecraft.util.Mth import net.minecraft.world.entity.Entity +import net.minecraft.world.item.ItemDisplayContext +import net.minecraft.world.item.ItemStack import net.minecraft.world.phys.Vec3 import org.joml.Math import org.joml.Quaternionf import org.joml.Vector3f import org.joml.Vector4f +import kotlin.math.* class PokemonRenderer( context: EntityRendererProvider.Context @@ -149,6 +156,102 @@ class PokemonRenderer( this.renderNameTag(entity, entity.effectiveName(), poseMatrix, buffer, packedLight, partialTicks) } // Minecraft.getInstance().bufferBuilders.entityVertexConsumers.draw() + + + + //Render Held Item + var shownItem = entity.shownItem + + shownItem = getRenderableItem(entity) + + if (!shownItem.isEmpty) { + var scale = 1.0f //scale value can be overridden by modifier + var transformationMode = ItemDisplayContext.GROUND // display mode can be overridden by modifier + val locators: Map = clientDelegate.locatorStates + + poseMatrix.pushPose() + + when { + (locators.containsKey("held_item_eyes") && shownItem.`is`(WEARABLE_EYE_ITEMS)) -> { + poseMatrix.mulPose(locators["held_item_eyes"]!!.matrix) + transformationMode = ItemDisplayContext.HEAD + //applyModifiers("held_item_eyes", locators) + poseMatrix.translate(0f, 0f, .28f * scale) + poseMatrix.scale(0.7f * scale, 0.7f * scale, 0.7f * scale) + } + (locators.containsKey("held_item_head") && shownItem.`is`(WEARABLE_HAT_ITEMS)) -> { + poseMatrix.mulPose(locators["held_item_head"]!!.matrix) + transformationMode = ItemDisplayContext.HEAD + //applyModifiers("held_item_head", locators) + poseMatrix.translate(0f, -0.26f * scale, 0f) + poseMatrix.scale(.68f * scale, .68f * scale, .68f * scale) + } + (locators.containsKey("held_item")) -> { + poseMatrix.mulPose(locators["held_item"]!!.matrix) + transformationMode = ItemDisplayContext.THIRD_PERSON_RIGHT_HAND + //applyModifiers("held_item", locators) + poseMatrix.scale(scale, scale, scale) + poseMatrix.mulPose((Axis.XP.rotationDegrees(-90f))) + poseMatrix.mulPose(Axis.YP.rotationDegrees(-90f)) + } + (locators.containsKey("held_item_fixed")) -> { + poseMatrix.mulPose(locators["held_item_fixed"]!!.matrix) + //applyModifiers("held_item_fixed", locators) + poseMatrix.scale(scale, scale, scale) + } + else -> { // Don't render any item + poseMatrix.popPose() + return + } + } + + heldItemRender.renderItem( + entity, + shownItem, + transformationMode, + false, + poseMatrix, + buffer, + packedLight + ) + poseMatrix.popPose() + } + } + + private val heldItemRender = ItemInHandRenderer(Minecraft.getInstance(), entityRenderDispatcher, Minecraft.getInstance().itemRenderer) + + /** + * @param [pokemonEntity] The pokemon to get the held item from. + * @return Returns the held item for this pokemon. + */ + private fun getRenderableItem(pokemonEntity: PokemonEntity): ItemStack { + //Hidden Check + if(pokemonEntity.pokemon.isItemHidden) return ItemStack.EMPTY + //Server Search + if(!pokemonEntity.shownItem.isEmpty) return pokemonEntity.shownItem + //Client Search + //TODO there must be a better way to do this bit, too many search loops + if (pokemonEntity.ownerUUID?.equals(Minecraft.getInstance().player?.uuid) == true) { + //See if the pokemon that is being rendered is part of client users party + for (p in storage.myParty) { + return comparePokemonEntity(p, pokemonEntity) ?: continue + } + //If not then check PCs **this is for pokemon roaming around from the pasture block** + for (pc in storage.pcStores.values) for (box in pc.boxes) for (p in box.slots) { + return comparePokemonEntity(p, pokemonEntity) ?: continue + } + } + //Default + return ItemStack.EMPTY + } + + //This is used to compare the uuid of the pokemon being rendered to the pokemon in your party/pc + private fun comparePokemonEntity(p: Pokemon?, pokemonEntity: PokemonEntity ) : ItemStack? { + if (p?.entity?.uuid?.equals(pokemonEntity.uuid) == true ) { + if (p.isItemHidden) return ItemStack.EMPTY + return p.heldItem() + } + return null } fun renderTransition( diff --git a/common/src/main/kotlin/com/cobblemon/mod/common/entity/pokemon/PokemonEntity.kt b/common/src/main/kotlin/com/cobblemon/mod/common/entity/pokemon/PokemonEntity.kt index d59b98c87e..f65916ab4c 100644 --- a/common/src/main/kotlin/com/cobblemon/mod/common/entity/pokemon/PokemonEntity.kt +++ b/common/src/main/kotlin/com/cobblemon/mod/common/entity/pokemon/PokemonEntity.kt @@ -174,6 +174,7 @@ open class PokemonEntity( @JvmStatic val FREEZE_FRAME = SynchedEntityData.defineId(PokemonEntity::class.java, EntityDataSerializers.FLOAT) @JvmStatic val CAUGHT_BALL = SynchedEntityData.defineId(PokemonEntity::class.java, EntityDataSerializers.STRING) @JvmStatic val EVOLUTION_STARTED = SynchedEntityData.defineId(PokemonEntity::class.java, EntityDataSerializers.BOOLEAN) + @JvmStatic var SHOWN_HELD_ITEM = SynchedEntityData.defineId(PokemonEntity::class.java, EntityDataSerializers.ITEM_STACK) const val BATTLE_LOCK = "battle" const val EVOLUTION_LOCK = "evolving" @@ -229,6 +230,10 @@ open class PokemonEntity( val friendship: Int get() = entityData.get(FRIENDSHIP) + var shownItem: ItemStack + get() = entityData.get(SHOWN_HELD_ITEM) + set(value) = entityData.set(SHOWN_HELD_ITEM, value) + var drops: DropTable? = null var tethering: PokemonPastureBlockEntity.Tethering? = null @@ -326,6 +331,7 @@ open class PokemonEntity( builder.define(FREEZE_FRAME, -1F) builder.define(CAUGHT_BALL, "") builder.define(EVOLUTION_STARTED, false) + builder.define(SHOWN_HELD_ITEM, ItemStack.EMPTY) } override fun onSyncedDataUpdated(data: EntityDataAccessor<*>) { diff --git a/common/src/main/kotlin/com/cobblemon/mod/common/pokemon/Pokemon.kt b/common/src/main/kotlin/com/cobblemon/mod/common/pokemon/Pokemon.kt index 172a4c3ebf..3ab15e01e7 100644 --- a/common/src/main/kotlin/com/cobblemon/mod/common/pokemon/Pokemon.kt +++ b/common/src/main/kotlin/com/cobblemon/mod/common/pokemon/Pokemon.kt @@ -539,6 +539,8 @@ open class Pokemon : ShowdownIdentifiable { */ internal var heldItem: ItemStack = ItemStack.EMPTY + var isItemHidden: Boolean = false + init { storeCoordinates.subscribe { if (it != null && it.store !is PCStore && this.tetheringId != null) afterOnServer(seconds = 0.05F) { this.tetheringId = null } } storeCoordinates.subscribe { diff --git a/common/src/main/resources/assets/cobblemon/textures/gui/summary/item_hidden.png b/common/src/main/resources/assets/cobblemon/textures/gui/summary/item_hidden.png new file mode 100644 index 0000000000..060689cfe3 Binary files /dev/null and b/common/src/main/resources/assets/cobblemon/textures/gui/summary/item_hidden.png differ diff --git a/common/src/main/resources/assets/cobblemon/textures/gui/summary/item_visible.png b/common/src/main/resources/assets/cobblemon/textures/gui/summary/item_visible.png new file mode 100644 index 0000000000..161a420e24 Binary files /dev/null and b/common/src/main/resources/assets/cobblemon/textures/gui/summary/item_visible.png differ diff --git a/common/src/main/resources/data/cobblemon/tags/item/wearable/eyes.json b/common/src/main/resources/data/cobblemon/tags/item/wearable/eyes.json new file mode 100644 index 0000000000..5d784d5b79 --- /dev/null +++ b/common/src/main/resources/data/cobblemon/tags/item/wearable/eyes.json @@ -0,0 +1,9 @@ +{ + "replace": false, + "values": [ + "cobblemon:black_glasses", + "cobblemon:choice_specs", + "cobblemon:safety_goggles", + "cobblemon:wise_glasses" + ] +} \ No newline at end of file diff --git a/common/src/main/resources/data/cobblemon/tags/item/wearable/hats.json b/common/src/main/resources/data/cobblemon/tags/item/wearable/hats.json new file mode 100644 index 0000000000..df6862afb2 --- /dev/null +++ b/common/src/main/resources/data/cobblemon/tags/item/wearable/hats.json @@ -0,0 +1,12 @@ +{ + "replace": false, + "values": [ + "#minecraft:banners", + "cobblemon:rocky_helmet", + "cobblemon:exp_share", + "cobblemon:kings_rock", + "cobblemon:choice_band", + "cobblemon:focus_band", + "cobblemon:muscle_band" + ] +} \ No newline at end of file diff --git a/common/src/main/resources/data/cobblemon/tags/item/wearable/hidden.json b/common/src/main/resources/data/cobblemon/tags/item/wearable/hidden.json new file mode 100644 index 0000000000..ea3ef393ba --- /dev/null +++ b/common/src/main/resources/data/cobblemon/tags/item/wearable/hidden.json @@ -0,0 +1,7 @@ +{ + "replace": true, + "values": [ + "#cobblemon:held/is_held_item", + "#cobblemon:berries" + ] +} \ No newline at end of file