Skip to content

Commit d760604

Browse files
committed
Chest, walkim, and calryex carrots don't explode.
1 parent 7132b3b commit d760604

File tree

7 files changed

+56
-37
lines changed

7 files changed

+56
-37
lines changed

common/src/main/java/generations/gg/generations/core/generationscore/common/client/screen/NineSlice.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package generations.gg.generations.core.generationscore.common.client.screen
22

3+
import net.minecraft.client.gui.Gui
34
import net.minecraft.client.gui.GuiGraphics
45
import net.minecraft.resources.ResourceLocation
56

common/src/main/java/generations/gg/generations/core/generationscore/common/world/container/GenerationsContainers.kt

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -36,12 +36,14 @@ object GenerationsContainers {
3636
val GENERIC: RegistrySupplier<MenuType<GenericChestContainer<*>>> = CONTAINERS.register(
3737
"generic"
3838
) {
39-
MenuRegistry.ofExtended { containerId: Int, playerInventory: Inventory, buf: FriendlyByteBuf ->
39+
MenuRegistry.ofExtended { containerId, playerInventory, buf ->
40+
val width = buf.readVarInt()
41+
val height = buf.readVarInt()
42+
val lock = buf.readVarInt()
4043
GenericChestContainer(
4144
containerId,
42-
playerInventory, SimpleItemStorage(buf.readVarInt()),
43-
buf.readVarInt(),
44-
buf.readVarInt()
45+
playerInventory, SimpleItemStorage(width * height),
46+
width, height, lock
4547
)
4648
}
4749
}

common/src/main/java/generations/gg/generations/core/generationscore/common/world/container/GenericChestContainer.kt

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,12 @@ import net.minecraft.world.item.ItemStack
1717

1818
open class GenericChestContainer<T>(
1919
containerId: Int,
20-
@JvmField val playerInventory: Inventory,
20+
val playerInventory: Inventory,
2121
private val container: T,
2222
val inventoryWidth: Int,
2323
val inventoryHeight: Int,
24-
protected val locked: Int = -1
25-
) : AbstractContainerMenu(
26-
GenerationsContainers.GENERIC.get(),
27-
containerId
28-
) where T: CommonStorage<ItemResource>, T: UpdateManager<ItemStorageData> {
24+
lock: Int = -1
25+
) : AbstractContainerMenu(GenerationsContainers.GENERIC.get(), containerId) where T: CommonStorage<ItemResource>, T: UpdateManager<ItemStorageData> {
2926
@JvmField
3027
val guiWidth: Int = 14 + this.inventoryWidth * 18
3128
@JvmField
@@ -41,13 +38,13 @@ open class GenericChestContainer<T>(
4138

4239
this.playerInventoryX = guiWidth / 2 - 80
4340

44-
populatePlayer(playerInventory, playerInventoryX, guiHeight - 82, 1, 3, 9)
45-
populatePlayer(playerInventory, playerInventoryX, guiHeight - 24, 0, 1, 9)
41+
populatePlayer(playerInventory, playerInventoryX, guiHeight - 82, 1, 3, 9, lock)
42+
populatePlayer(playerInventory, playerInventoryX, guiHeight - 24, 0, 1, 9, lock)
4643
}
4744

4845
private fun <V> populate(container: V, x: Int, y: Int, startingRow: Int, rows: Int, columns: Int) where V : CommonStorage<ItemResource> {
49-
for (row in 0..<rows) {
50-
for (column in 0..<columns) {
46+
for (row in 0..< rows) {
47+
for (column in 0..< columns) {
5148
val slot = column + (startingRow + row) * columns
5249
val xSlot = x + column * 18
5350
val ySlot = y + row * 18
@@ -57,14 +54,16 @@ open class GenericChestContainer<T>(
5754
}
5855
}
5956

60-
private fun populatePlayer(container: Inventory, x: Int, y: Int, startingRow: Int, rows: Int, columns: Int) {
57+
private fun populatePlayer(container: Inventory, x: Int, y: Int, startingRow: Int, rows: Int, columns: Int, lock: Int) {
58+
59+
6160
for (row in 0..<rows) {
6261
for (column in 0..<columns) {
6362
val slot = column + (startingRow + row) * columns
6463
val xSlot = x + column * 18
6564
val ySlot = y + row * 18
6665

67-
this.addSlot(if(locked == slot) LockedSlot(container, slot, xSlot, ySlot) else Slot(container, slot, x, y))
66+
this.addSlot(if(lock == slot) LockedSlot(container, slot, xSlot, ySlot) else Slot(container, slot, xSlot, ySlot))
6867
}
6968
}
7069
}

common/src/main/java/generations/gg/generations/core/generationscore/common/world/container/GenericContainer.kt

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
package generations.gg.generations.core.generationscore.common.world.container
22

3+
import dev.architectury.registry.menu.ExtendedMenuProvider
34
import dev.architectury.registry.menu.MenuRegistry
45
import earth.terrarium.common_storage_lib.item.util.ItemStorageData
56
import earth.terrarium.common_storage_lib.resources.item.ItemResource
67
import earth.terrarium.common_storage_lib.storage.base.CommonStorage
78
import earth.terrarium.common_storage_lib.storage.base.UpdateManager
9+
import net.minecraft.network.FriendlyByteBuf
810
import net.minecraft.network.chat.Component
911
import net.minecraft.server.level.ServerPlayer
1012
import net.minecraft.world.MenuProvider
@@ -14,19 +16,26 @@ import net.minecraft.world.inventory.AbstractContainerMenu
1416

1517
object GenericContainer {
1618

17-
fun <T> openScreen(storage: T, width: Int, height: Int, title: Component, player: Player, lockedSlot: Int = -1) where T: CommonStorage<ItemResource>, T: UpdateManager<ItemStorageData> {
19+
fun <T> openScreen(storage: T, width: Int, height: Int, title: Component, player: Player, lock: Int = -1) where T: CommonStorage<ItemResource>, T: UpdateManager<ItemStorageData> {
20+
1821
if (!player.isLocalPlayer) MenuRegistry.openExtendedMenu(
1922
player as ServerPlayer,
20-
object : MenuProvider {
23+
object : MenuProvider, ExtendedMenuProvider {
2124
override fun createMenu(id: Int, inventory: Inventory, player: Player): AbstractContainerMenu {
22-
return GenericChestContainer(id, inventory, storage, width, height, lockedSlot)
25+
return GenericChestContainer(id, inventory, storage, width, height, lock)
2326
}
2427

2528
override fun getDisplayName(): Component {
2629
return title
2730
}
31+
32+
override fun saveExtraData(buffer: FriendlyByteBuf) {
33+
buffer.writeVarInt(width)
34+
buffer.writeVarInt(height)
35+
buffer.writeVarInt(lock)
36+
}
2837
}
29-
) { byteBuf -> byteBuf.writeVarInt(width).writeVarInt(height).writeVarInt(lockedSlot) }
38+
)
3039
}
3140

3241
// override fun createMenu(i: Int, arg: Inventory, arg2: Player): AbstractContainerMenu? {

common/src/main/java/generations/gg/generations/core/generationscore/common/world/item/CalyrexSteedItem.kt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,11 @@ class CalyrexSteedItem(name: String, arg: Properties, private val speices: Speci
2626
if (!level.isClientSide() && usedHand == InteractionHand.MAIN_HAND) {
2727
val carrots = getCarrots(player.getItemInHand(usedHand))
2828

29-
val isFull = (0..18).map(carrots::get).all { it.amount >=64 }
29+
val isFull = (0..< 18).map(carrots::get).all { it.amount >=64 }
3030

3131
if (!isFull) {
3232

33-
(0..18).forEach { carrots.filter(it) { it.item.equals(Items.CARROT) } }
33+
(0..<18).forEach { carrots.filter(it) { it.item.equals(Items.CARROT) } }
3434

3535
GenericContainer.openScreen(carrots, 9, 2, Component.translatable(defaultTranslation), player, player.inventory.selected)
3636
return InteractionResultHolder.success(player.getItemInHand(usedHand))

common/src/main/java/generations/gg/generations/core/generationscore/common/world/item/WalkmonItem.kt

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import generations.gg.generations.core.generationscore.common.network.packets.S2
1111
import generations.gg.generations.core.generationscore.common.util.DataKeys
1212
import generations.gg.generations.core.generationscore.common.util.TEXT_CODEC
1313
import generations.gg.generations.core.generationscore.common.util.TEXT_STREAM_CODEC
14+
import generations.gg.generations.core.generationscore.common.util.extensions.component
1415
import generations.gg.generations.core.generationscore.common.util.extensions.get
1516
import generations.gg.generations.core.generationscore.common.world.container.GenericContainer
1617
import generations.gg.generations.core.generationscore.common.world.item.components.GenerationsDataComponents
@@ -31,7 +32,7 @@ import net.minecraft.world.item.ItemStack
3132
import net.minecraft.world.item.JukeboxPlayable
3233
import net.minecraft.world.level.Level
3334

34-
class WalkmonItem(properties: Properties, private val row: Int, type: String) : Item(properties) {
35+
class WalkmonItem(properties: Properties, private val row: Int, type: String) : Item(properties.component(GenerationsDataComponents.WALKMON_DATA, WalkmonData(0, 0, false, Component.literal("Walkmon")))) {
3536
private val defaultTranslation: String = "container.$type"
3637

3738
override fun use(level: Level, player: Player, usedHand: InteractionHand): InteractionResultHolder<ItemStack> {
@@ -42,7 +43,7 @@ class WalkmonItem(properties: Properties, private val row: Int, type: String) :
4243

4344
if(walkmon != null) {
4445

45-
if (player.isShiftKeyDown) GenericContainer.openScreen(SimpleItemStorage(PlayerContext.ofHand(player, usedHand), GenerationsStorage.ITEM_CONTENTS.componentType(), 9 * row), 9, row, walkmon.title.takeUnless { it == Component.EMPTY } ?: Component.translatable(defaultTranslation), player, player.inventory.selected)
46+
if (player.isShiftKeyDown) GenericContainer.openScreen(SimpleItemStorage(stack, GenerationsStorage.ITEM_CONTENTS, 9 * row), 9, row, walkmon.title.takeUnless { it == Component.EMPTY } ?: Component.translatable(defaultTranslation), player, player.inventory.selected)
4647
else {
4748
walkmon.toggle()
4849
}
@@ -119,20 +120,22 @@ class WalkmonItem(properties: Properties, private val row: Int, type: String) :
119120

120121
private fun ItemStorageData.next(): JukeboxPlayable? {
121122
val size = stacks.size
122-
123-
var index = currentSlot
123+
var index = currentSlot + 1
124124

125125
while (index < size) {
126-
index++
127-
128126
val stack = stacks[index]
129-
if(stack.isEmpty) continue
127+
if (stack.isEmpty) {
128+
index++
129+
continue
130+
}
130131

131132
val playable = stack.resource.get(DataComponents.JUKEBOX_PLAYABLE)
132-
if(playable != null) {
133+
if (playable != null) {
133134
currentSlot = index
134135
return playable
135136
}
137+
138+
index++
136139
}
137140

138141
return null

common/src/main/java/generations/gg/generations/core/generationscore/common/world/level/block/entities/generic/GenericChestBlockEntity.kt

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ class GenericChestBlockEntity @JvmOverloads constructor(
4040
private var width: Int = 9,
4141
private var height: Int = 1,
4242
private var defaultTranslation: String = "container.chest"
43-
) :
44-
RandomizableContainerBlockEntity(GenerationsBlockEntities.GENERIC_CHEST.get(), arg, arg2), LidBlockEntity {
43+
) : RandomizableContainerBlockEntity(GenerationsBlockEntities.GENERIC_CHEST.get(), arg, arg2), LidBlockEntity {
4544
private val openersCounter: ContainerOpenersCounter = object : ContainerOpenersCounter() {
4645
override fun onOpen(level: Level, pos: BlockPos, state: BlockState) {
4746
this@GenericChestBlockEntity.playSound(state, SoundEvents.CHEST_OPEN)
@@ -66,6 +65,8 @@ class GenericChestBlockEntity @JvmOverloads constructor(
6665

6766
private val chestLidController = ChestLidController()
6867

68+
private var items: NonNullList<ItemStack> = NonNullList.withSize(width * height, ItemStack.EMPTY)
69+
6970
override fun getContainerSize(): Int {
7071
return width * height
7172
}
@@ -79,13 +80,13 @@ class GenericChestBlockEntity @JvmOverloads constructor(
7980
this.width = tag.getInt("width")
8081
this.height = tag.getInt("height")
8182
this.defaultTranslation = tag.getString("defaultTranslation")
82-
// this.items = NonNullList.withSize(this.containerSize, ItemStack.EMPTY)
83-
// if (!this.tryLoadLootTable(tag)) ContainerHelper.loadAllItems(tag, this.items, provider)
83+
this.items = NonNullList.withSize(this.containerSize, ItemStack.EMPTY)
84+
if (!this.tryLoadLootTable(tag)) ContainerHelper.loadAllItems(tag, this.items, provider)
8485
}
8586

8687
override fun saveAdditional(tag: CompoundTag, provider: HolderLookup.Provider) {
8788
super.saveAdditional(tag, provider)
88-
// if (!this.trySaveLootTable(tag)) ContainerHelper.saveAllItems(tag, this.items, provider)
89+
if (!this.trySaveLootTable(tag)) ContainerHelper.saveAllItems(tag, this.items, provider)
8990
tag.putInt("width", width)
9091
tag.putInt("height", height)
9192
tag.putString("defaultTranslation", defaultTranslation)
@@ -125,11 +126,15 @@ class GenericChestBlockEntity @JvmOverloads constructor(
125126
}
126127

127128
override fun getItems(): NonNullList<ItemStack> {
128-
return NonNullList.create()
129+
return items
129130
}
130131

132+
// override fun getItem(index: Int): ItemStack {
133+
// return if (index in 0 until items.size) items[index] else ItemStack.EMPTY
134+
// }
135+
131136
override fun setItems(itemStacks: NonNullList<ItemStack>) {
132-
// this.items = itemStacks
137+
this.items = itemStacks
133138
}
134139

135140
override fun getOpenNess(partialTicks: Float): Float {

0 commit comments

Comments
 (0)