diff --git a/src/main/kotlin/breadmod/block/machine/entity/AbstractMachineBlockEntity.kt b/src/main/kotlin/breadmod/block/machine/entity/AbstractMachineBlockEntity.kt index 8196c759..1dffe5e0 100644 --- a/src/main/kotlin/breadmod/block/machine/entity/AbstractMachineBlockEntity.kt +++ b/src/main/kotlin/breadmod/block/machine/entity/AbstractMachineBlockEntity.kt @@ -40,7 +40,7 @@ abstract class AbstractMachineBlockEntity>( final override fun getCapability(cap: Capability): LazyOptional = getCapability(cap, null) - final override fun getCapability(cap: Capability, side: Direction?): LazyOptional + override fun getCapability(cap: Capability, side: Direction?): LazyOptional = capabilityHolder.capabilitySided(cap, /*blockState.getValue(BlockStateProperties.HORIZONTAL_FACING)*/ Direction.NORTH, side) ?: super.getCapability(cap, side) final override fun invalidateCaps() { capabilityHolder.invalidate() diff --git a/src/main/kotlin/breadmod/block/machine/entity/WheatCrusherBlockEntity.kt b/src/main/kotlin/breadmod/block/machine/entity/WheatCrusherBlockEntity.kt index 2e5e7ecf..82fb7d30 100644 --- a/src/main/kotlin/breadmod/block/machine/entity/WheatCrusherBlockEntity.kt +++ b/src/main/kotlin/breadmod/block/machine/entity/WheatCrusherBlockEntity.kt @@ -10,18 +10,24 @@ import breadmod.util.capability.EnergyBattery import breadmod.util.capability.IndexableItemHandler import breadmod.util.capability.StorageDirection import net.minecraft.core.BlockPos +import net.minecraft.core.Direction import net.minecraft.nbt.CompoundTag import net.minecraft.network.chat.Component import net.minecraft.world.MenuProvider +import net.minecraft.world.WorldlyContainer import net.minecraft.world.entity.player.Inventory import net.minecraft.world.entity.player.Player import net.minecraft.world.entity.player.StackedContents import net.minecraft.world.inventory.AbstractContainerMenu -import net.minecraft.world.inventory.CraftingContainer import net.minecraft.world.item.ItemStack import net.minecraft.world.level.Level import net.minecraft.world.level.block.state.BlockState +import net.minecraft.world.level.block.state.properties.BlockStateProperties +import net.minecraftforge.common.capabilities.Capability import net.minecraftforge.common.capabilities.ForgeCapabilities +import net.minecraftforge.common.util.LazyOptional +import net.minecraftforge.items.IItemHandlerModifiable +import net.minecraftforge.items.wrapper.SidedInvWrapper class WheatCrusherBlockEntity( pPos: BlockPos, @@ -35,8 +41,35 @@ class WheatCrusherBlockEntity( ForgeCapabilities.ITEM_HANDLER to (IndexableItemHandler(listOf( 64 to StorageDirection.STORE_ONLY, 64 to StorageDirection.EMPTY_ONLY - )) to null) -), MenuProvider, CraftingContainer { + )) to mutableListOf()) +), MenuProvider, WorldlyContainer { + + // todo this needs to be adapted into CapabilityHolder or IndexableItemHandler, i'm not sure + /// Temporary workaround for CapabilityHolder not currently supporting proper sided inv wrapping for IndexableItemHandler + private val facing = blockState.getValue(BlockStateProperties.HORIZONTAL_FACING) /*?: blockState.getValue(BlockStateProperties.FACING) ?: null*/ + private var handlers: Array> = SidedInvWrapper.create(this, facing) + + // Overriding AbstractMachineBlockEntity#getCapability to allow casting the handlers variable above + override fun getCapability(cap: Capability, side: Direction?): LazyOptional { + return when { + (cap == ForgeCapabilities.ITEM_HANDLER) -> handlers[0].cast() + else -> capabilityHolder.capabilitySided(cap, /*blockState.getValue(BlockStateProperties.HORIZONTAL_FACING)*/ Direction.NORTH, side) ?: super.getCapability(cap, side) + } + } + + // Binds slots 0 and 1 to all sides of the block + override fun getSlotsForFace(pSide: Direction): IntArray = when(pSide) { + Direction.UP, Direction.DOWN, Direction.NORTH, Direction.SOUTH, Direction.EAST, Direction.WEST -> intArrayOf(0, 1) + else -> intArrayOf() + } + + override fun canPlaceItemThroughFace(pIndex: Int, pItemStack: ItemStack, pDirection: Direction?): Boolean = + if(pDirection != null) getSlotsForFace(pDirection).contains(pIndex) else true + + // Allow all but the input slot to be extracted from all faces + override fun canTakeItemThroughFace(pIndex: Int, pStack: ItemStack, pDirection: Direction): Boolean = pIndex != 0 + /// + override fun adjustSaveAdditionalProgressive(pTag: CompoundTag) { super.adjustSaveAdditionalProgressive(pTag) pTag.put(ModMain.ID, CompoundTag().also { dataTag -> @@ -54,18 +87,6 @@ class WheatCrusherBlockEntity( capabilityHolder.capabilityOrNull(ForgeCapabilities.ENERGY)?.deserializeNBT(dataTag.getCompound("energy")) } - override fun recipeTick( - pLevel: Level, - pPos: BlockPos, - pState: BlockState, - pBlockEntity: Progressive, - recipe: WheatCrushingRecipe - ) { -// println("serverside recipe progress: ${progress}t / ${progress / 20}s") -// println("serverside recipe time: ${currentRecipe.getOrNull()?.time}t / ${currentRecipe.getOrNull()?.time?.div(20)}s") - } - - override fun createMenu(pContainerId: Int, pInventory: Inventory, pPlayer: Player): AbstractContainerMenu = WheatCrusherMenu(pContainerId, pInventory, this) diff --git a/src/main/kotlin/breadmod/block/machine/entity/menu/AbstractMachineMenu.kt b/src/main/kotlin/breadmod/block/machine/entity/menu/AbstractMachineMenu.kt index 5e12f281..bf69d8d4 100644 --- a/src/main/kotlin/breadmod/block/machine/entity/menu/AbstractMachineMenu.kt +++ b/src/main/kotlin/breadmod/block/machine/entity/menu/AbstractMachineMenu.kt @@ -34,7 +34,12 @@ abstract class AbstractMachineMenu repeat(9) { x -> addSlot(Slot(inventory, x + y * 9 + 9, 8 + x * 18, inventoryY + y * 18)) } } } - open val containerSlotCount: Int = 1 // number of inventory slots the block entity has + /** + * ### Used in [quickMoveStack] to enable shift clicking items into the target inventory + * value must match the amount of slots your block entity has + */ + open val containerSlotCount: Int = 1 + final override fun quickMoveStack(playerIn: Player, pIndex: Int): ItemStack { val sourceSlot = slots[pIndex] if (!sourceSlot.hasItem()) return ItemStack.EMPTY //EMPTY_ITEM @@ -47,7 +52,7 @@ abstract class AbstractMachineMenu = deferredRegister.register("bread_bullet") { Item(Item.Properties()) } val TOOL_GUN: RegistryObject = deferredRegister.register(TOOL_GUN_DEF) { ToolGunItem() } val CAPRISPIN: RegistryObject = deferredRegister.register("caprispin") { object : Item(Properties() - .food(FoodProperties.Builder().alwaysEat().nutrition(20).effect(MobEffectInstance(MobEffects.LEVITATION, 100, 20), 1f).build()) - .rarity(Rarity.EPIC)){ + .food(FoodProperties.Builder() + .alwaysEat() + .nutrition(20) + .effect(MobEffectInstance(MobEffects.LEVITATION, 100, 20), 1f) + .build() + ) + .rarity(Rarity.EPIC) + ){ override fun getUseAnimation(pStack: ItemStack): UseAnim = UseAnim.DRINK - } } + }} + val TOASTER_HEATING_ELEMENT: RegistryObject = deferredRegister.register("toaster_heating_element") { Item(Item.Properties()) } val CREATURE: RegistryObject = deferredRegister.register("creature") { Item(Item.Properties()) } @@ -97,7 +104,8 @@ object ModItems { RecordItem(15, ModSounds.TEST_SOUND, Item.Properties() .stacksTo(1) .rarity(Rarity.RARE), - 7900) + 7900 + ) } val PROJECT_E: ProjectEItems? = if(ModList.get().isLoaded("projecte")) ProjectEItems() else null diff --git a/src/main/resources/assets/breadmod/models/block/keyboard.json b/src/main/resources/assets/breadmod/models/block/keyboard.json index 2a01805f..88759c45 100644 --- a/src/main/resources/assets/breadmod/models/block/keyboard.json +++ b/src/main/resources/assets/breadmod/models/block/keyboard.json @@ -1,5 +1,6 @@ { "credit": "Made with Blockbench", + "parent": "block/block", "texture_size": [32, 32], "textures": { "0": "breadmod:block/keyboard_assembly", diff --git a/src/main/resources/assets/breadmod/textures/item/toaster_heating_element.png b/src/main/resources/assets/breadmod/textures/item/toaster_heating_element.png new file mode 100644 index 00000000..3c5df516 Binary files /dev/null and b/src/main/resources/assets/breadmod/textures/item/toaster_heating_element.png differ