Skip to content

Commit

Permalink
fix blockstate resetting on every recipe cycle, minor item additions
Browse files Browse the repository at this point in the history
  • Loading branch information
ttttdoy committed Jul 5, 2024
1 parent f5df83d commit 559f2bd
Show file tree
Hide file tree
Showing 11 changed files with 36 additions and 44 deletions.
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,6 @@
# BUGS
- [ ] items inputted into machines from their sides are voided out of existence
- [ ] (minor) tool gun anim speeds up when you have multiple tool guns at once
- [ ] AbstractMachineMenu#getScaledProgress always returns 0 (temporarily fixed with using a maxProgress value)
- [ ] Fluid texture on diesel machine needs to be normalized
- [ ] tool gun stacking up/absorbing clicks when not equipped
- [ ] happy block explosion not actually exploding an area
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ abstract class AbstractMachineBlockEntity<T: AbstractMachineBlockEntity<T>>(
open fun adjustSaveAdditionalProgressive(pTag: CompoundTag) {}
final override fun adjustSaveAdditional(pTag: CompoundTag) {
adjustSaveAdditionalProgressive(pTag)
// currentRecipe.ifPresent { pTag.putInt(PROGRESS_KEY, progress) } // todo figure out why progress isn't syncing to the client
// currentRecipe.ifPresent { pTag.putInt(PROGRESS_KEY, progress) }
pTag.putInt(PROGRESS_KEY, progress); pTag.putInt(MAX_PROGRESS_KEY, maxProgress)
}

Expand Down Expand Up @@ -161,11 +161,9 @@ abstract class AbstractMachineBlockEntity<T: AbstractMachineBlockEntity<T>>(

if (energy >= div) {
if (progress >= it.time && recipeDone(pLevel, pPos, pState, pBlockEntity, it)) {
// todo this needs a more elegant solution instead of toggling the blockstate to false whenever the recipe completes (needs to only turn off when the input ingredients are not met)
pLevel.setBlockAndUpdate(pPos, pState.setValue(BlockStateProperties.POWERED, false))
energyDivision = null
currentRecipe = Optional.empty()
progress = 0
progress = 0; maxProgress = 0
} else {
progress++
pLevel.setBlockAndUpdate(pPos, pState.setValue(BlockStateProperties.POWERED, true))
Expand All @@ -174,16 +172,18 @@ abstract class AbstractMachineBlockEntity<T: AbstractMachineBlockEntity<T>>(
} else progress--
}, {
val sLevel = level
if (sLevel != null) {
sLevel?.let {
// println("NOTICE: Inventory: ${this.getItem(0)}") //todo uncomment this later
val recipe = recipeDial.getRecipeFor(this, sLevel)
recipe.ifPresent {
if (consumeRecipe(pLevel, pPos, pState, pBlockEntity, it)) currentRecipe = recipe
maxProgress = it.time
}
} else {
pLevel.setBlockAndUpdate(pPos, pState.setValue(BlockStateProperties.POWERED, false))
noRecipeTick(pLevel, pPos, pState, pBlockEntity)
recipe.ifPresentOrElse({
if (consumeRecipe(pLevel, pPos, pState, pBlockEntity, it)) {
currentRecipe = recipe
maxProgress = it.time
}
}, {
pLevel.setBlockAndUpdate(pPos, pState.setValue(BlockStateProperties.POWERED, false))
noRecipeTick(pLevel, pPos, pState, pBlockEntity)
})
}
})
postTick(pLevel, pPos, pState, pBlockEntity)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ abstract class AbstractMachineMenu<T : AbstractMachineBlockEntity.Progressive<T,
repeat(3) { y -> repeat(9) { x -> addSlot(Slot(inventory, x + y * 9 + 9, 8 + x * 18, inventoryY + y * 18)) } }
}

// todo investigate "Invalid slotIndex:37" when trying to shift click items from the output slot on machines
// todo side note: quickMoveStack shouldn't be final since TE_INVENTORY_SLOT_COUNT wouldn't be the same for every machine
open val containerSlotCount: Int = 1 // number of inventory slots the block entity has
final override fun quickMoveStack(playerIn: Player, pIndex: Int): ItemStack {
val sourceSlot = slots[pIndex]
if (!sourceSlot.hasItem()) return ItemStack.EMPTY //EMPTY_ITEM
Expand All @@ -46,35 +45,18 @@ abstract class AbstractMachineMenu<T : AbstractMachineBlockEntity.Progressive<T,
// Check if the slot clicked is one of the vanilla container slots
if (pIndex < VANILLA_FIRST_SLOT_INDEX + VANILLA_SLOT_COUNT) {
// This is a vanilla container slot so merge the stack into the tile inventory
if (!moveItemStackTo(
sourceStack,
TE_INVENTORY_FIRST_SLOT_INDEX, TE_INVENTORY_FIRST_SLOT_INDEX
+ TE_INVENTORY_SLOT_COUNT, false
)
) {
return ItemStack.EMPTY // EMPTY_ITEM
}
} else if (pIndex < TE_INVENTORY_FIRST_SLOT_INDEX + TE_INVENTORY_SLOT_COUNT) {
if (!moveItemStackTo(sourceStack, TE_INVENTORY_FIRST_SLOT_INDEX, TE_INVENTORY_FIRST_SLOT_INDEX + containerSlotCount, false)) return ItemStack.EMPTY // EMPTY_ITEM
} else if (pIndex < TE_INVENTORY_FIRST_SLOT_INDEX + containerSlotCount) {
// This is a TE slot so merge the stack into the players inventory
if (!moveItemStackTo(
sourceStack,
VANILLA_FIRST_SLOT_INDEX,
VANILLA_FIRST_SLOT_INDEX + VANILLA_SLOT_COUNT,
false
)
) {
return ItemStack.EMPTY
}
if (!moveItemStackTo(sourceStack, VANILLA_FIRST_SLOT_INDEX, VANILLA_FIRST_SLOT_INDEX + VANILLA_SLOT_COUNT, false)) return ItemStack.EMPTY
} else {
println("Invalid slotIndex:$pIndex")
return ItemStack.EMPTY
}
// If stack size == 0 (the entire stack was moved) set slot contents to null
if (sourceStack.count == 0) {
sourceSlot.set(ItemStack.EMPTY)
} else {
sourceSlot.setChanged()
}
} else sourceSlot.setChanged()
sourceSlot.onTake(playerIn, sourceStack)
return copyOfSourceStack
}
Expand All @@ -100,8 +82,5 @@ abstract class AbstractMachineMenu<T : AbstractMachineBlockEntity.Progressive<T,
const val VANILLA_SLOT_COUNT = HOTBAR_SLOT_COUNT + PLAYER_INVENTORY_SLOT_COUNT
const val VANILLA_FIRST_SLOT_INDEX = 0
const val TE_INVENTORY_FIRST_SLOT_INDEX = VANILLA_FIRST_SLOT_INDEX + VANILLA_SLOT_COUNT

// THIS YOU HAVE TO DEFINE!
const val TE_INVENTORY_SLOT_COUNT = 1 // must be the number of slots you have!
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class DoughMachineMenu(
pContainerId, inventory, parent, 142, 84
) {
override fun getScaledProgress(): Int = ((parent.progress.toFloat() / parent.maxProgress.toFloat()) * 24).toInt()
override val containerSlotCount: Int = 3

constructor(pContainerId: Int, inventory: Inventory, byteBuf: FriendlyByteBuf) : this(
pContainerId, inventory,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ class WheatCrusherMenu(
pContainerId, inventory, parent, 174, 116
) {
override fun getScaledProgress(): Int = ((parent.progress.toFloat() / parent.maxProgress.toFloat()) * 48).toInt()
override val containerSlotCount: Int = 2

constructor(pContainerId: Int, inventory: Inventory, byteBuf: FriendlyByteBuf) : this(
pContainerId, inventory,
Expand Down
2 changes: 2 additions & 0 deletions src/main/kotlin/breadmod/datagen/ModItemModelProvider.kt
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,8 @@ class ModItemModelProvider(
singleItem(ModItems.RF_BREAD_BOOTS)
singleItem(ModBlocks.BREAD_DOOR)
singleItem(ModItems.CREATURE)
singleItem(ModItems.CAPRISPIN)
singleItem(ModItems.TOAST)
handheldItem(ModItems.BREAD_GUN_ITEM)

fenceInventory("bread_fence", modLoc("${ModelProvider.BLOCK_FOLDER}/bread_block"))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ class USEnglishLanguageProvider(
add(ModItems.TOOL_GUN)
add(ModBlocks.GENERATOR)
add(ModItems.CREATURE)
add(ModItems.CAPRISPIN)
add(ModItems.TOAST)

add(ModCreativeTabs.MAIN_TAB, "Bread Mod")
add(ModCreativeTabs.SPECIALS_TAB, "Bread Mod: Specials")
Expand Down
13 changes: 8 additions & 5 deletions src/main/kotlin/breadmod/registry/item/ModItems.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,13 @@ object ModItems {
val BREAD_SHIELD: RegistryObject<BreadShieldItem> = deferredRegister.register("bread_shield") { BreadShieldItem() }
val DOPED_BREAD: RegistryObject<DopedBreadItem> = deferredRegister.register("doped_bread") { DopedBreadItem() }
val BREAD_SLICE: RegistryObject<Item> = deferredRegister.register("bread_slice") {
Item(Item.Properties().food(FoodProperties.Builder().nutrition(1).fast().build())) }
val FLOUR: RegistryObject<Item> = deferredRegister.register("flour") {Item(Item.Properties())}
val DOUGH: RegistryObject<Item> = deferredRegister.register("dough") {Item(Item.Properties())}
Item(Item.Properties().food(FoodProperties.Builder().nutrition(2).fast().build())) }
val TOAST: RegistryObject<Item> = deferredRegister.register("toast") {
Item(Item.Properties().food(FoodProperties.Builder().nutrition(5).fast().build())) }
val FLOUR: RegistryObject<Item> = deferredRegister.register("flour") { Item(Item.Properties()) }
val DOUGH: RegistryObject<Item> = deferredRegister.register("dough") { Item(Item.Properties()) }

val ALUMINA: RegistryObject<Item> = deferredRegister.register("alumina") {Item(Item.Properties())}
val ALUMINA: RegistryObject<Item> = deferredRegister.register("alumina") { Item(Item.Properties()) }

val BREAD_AMULET: RegistryObject<Item> = deferredRegister.register("bread_amulet") { BreadAmuletItem() }

Expand Down Expand Up @@ -81,8 +83,9 @@ object ModItems {
val BREAD_GUN_ITEM: RegistryObject<ProjectileWeaponItem> = deferredRegister.register("bread_gun") { BreadGunItem() }
val BREAD_BULLET_ITEM: RegistryObject<Item> = deferredRegister.register("bread_bullet") { Item(Item.Properties()) }
val TOOL_GUN: RegistryObject<Item> = deferredRegister.register(TOOL_GUN_DEF) { ToolGunItem() }
val CAPRISPIN: RegistryObject<Item> = deferredRegister.register("caprispin") { Item(Item.Properties()) }

val CREATURE: RegistryObject<Item> = deferredRegister.register("creature") {Item(Item.Properties())}
val CREATURE: RegistryObject<Item> = deferredRegister.register("creature") { Item(Item.Properties()) }

val TEST_DISC: RegistryObject<RecordItem> = deferredRegister.register("music_disc_test") {
RecordItem(15, ModSounds.TEST_SOUND, Item.Properties()
Expand Down
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"animation": {
"frametime": 1
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 559f2bd

Please sign in to comment.