Skip to content

Commit

Permalink
fix: common itemStack nbts
Browse files Browse the repository at this point in the history
  • Loading branch information
jimchen5209 committed Apr 25, 2024
1 parent a6a2082 commit 5eb7eee
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -104,15 +104,15 @@ class HarvestBlockEntity(type: BlockEntityType<*>, pos: BlockPos, modelItem: Ite
if (originItem.isEmpty) {
setStack(slot, item)
break
} else if (originItem.count < originItem.maxCount && ItemStack.canCombine(originItem, item)) {
} else if (originItem.count < originItem.maxCount && ItemStack.areItemsAndComponentsEqual(originItem, item)) {
val count = item.count.coerceAtMost(originItem.maxCount - originItem.count)
item.decrement(count)
originItem.increment(count)
if (item.isEmpty) break
}
}
}
if (tool.damage(1, world.random, null)) {
tool.damage(1, world.random, null) {
tool.decrement(1)
tool.damage = 0
}
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/one/oktw/galaxy/gui/GUI.kt
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,7 @@ class GUI private constructor(private val type: ScreenHandlerType<out ScreenHand
for (index in slots) {
val slot = slotBindings[index]!!
val originItem = slot.stack
if (!originItem.isEmpty && slot.canInsert(item) && ItemStack.canCombine(item, originItem)) {
if (!originItem.isEmpty && slot.canInsert(item) && ItemStack.areItemsAndComponentsEqual(item, originItem)) {
val count = originItem.count + item.count
if (count <= item.maxCount) {
item.count = 0
Expand Down
16 changes: 8 additions & 8 deletions src/main/kotlin/one/oktw/galaxy/item/CustomItem.kt
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,13 @@

package one.oktw.galaxy.item

import net.minecraft.component.DataComponentTypes
import net.minecraft.component.type.AttributeModifiersComponent
import net.minecraft.component.type.CustomModelDataComponent
import net.minecraft.component.type.UnbreakableComponent
import net.minecraft.item.Item
import net.minecraft.item.ItemStack
import net.minecraft.nbt.NbtCompound
import net.minecraft.nbt.NbtList
import net.minecraft.text.Text
import net.minecraft.util.Identifier
import one.oktw.galaxy.util.CustomRegistry
Expand Down Expand Up @@ -61,13 +64,10 @@ abstract class CustomItem(override val identifier: Identifier, private val baseI
if (cacheable && this::cacheItemStack.isInitialized) return cacheItemStack.copy()

return ItemStack(baseItem).apply {
orCreateNbt.apply {
putInt("HideFlags", ItemStack.TooltipSection.values().map(ItemStack.TooltipSection::getFlag).reduce { acc, i -> acc or i }) // ALL
putInt("CustomModelData", modelData)
putBoolean("Unbreakable", true)
put("AttributeModifiers", NbtList())
}
setCustomName(this@CustomItem.getName())
set(DataComponentTypes.CUSTOM_MODEL_DATA, CustomModelDataComponent(modelData))
set(DataComponentTypes.UNBREAKABLE, UnbreakableComponent(false))
set(DataComponentTypes.ATTRIBUTE_MODIFIERS, AttributeModifiersComponent(listOf<AttributeModifiersComponent.Entry>(), false))
set(DataComponentTypes.CUSTOM_NAME, this@CustomItem.getName())
writeCustomNbt(getOrCreateSubNbt("GalaxyData"))
}.also { if (cacheable) cacheItemStack = it.copy() }
}
Expand Down

0 comments on commit 5eb7eee

Please sign in to comment.