mirror of
https://gitlab.com/cable-mc/cobblemon.git
synced 2026-11-26 10:08:53 -05:00
Started implementing renderable held items. Only working client side at the moment.
This commit is contained in:
1 parent
cc1f40a165
commit
e08ddc4fc4
10 files changed
+172
-2
No files matched your search
@@ -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))
|
||||
|
||||
@@ -89,6 +89,8 @@ class Summary private constructor(party: Collection<Pokemon?>, 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<Pokemon?>, 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(
|
||||
|
||||
+104
-1
@@ -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<String, MatrixWrapper> = 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(
|
||||
|
||||
@@ -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<*>) {
|
||||
|
||||
@@ -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 {
|
||||
|
||||
Binary file not shown.
|
After Width: | Height: | Size: 274 B |
Binary file not shown.
|
After Width: | Height: | Size: 246 B |
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"replace": false,
|
||||
"values": [
|
||||
"cobblemon:black_glasses",
|
||||
"cobblemon:choice_specs",
|
||||
"cobblemon:safety_goggles",
|
||||
"cobblemon:wise_glasses"
|
||||
]
|
||||
}
|
||||
@@ -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"
|
||||
]
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
{
|
||||
"replace": true,
|
||||
"values": [
|
||||
"#cobblemon:held/is_held_item",
|
||||
"#cobblemon:berries"
|
||||
]
|
||||
}
|
||||
Reference in new issue
Block a user