Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 20 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,23 +29,40 @@ Here is a list of implemented feature and considered features to be implemented:
- [ ] Lockable by player
- [x] Backpack model render on player's back when equipped
- Supported on vanilla and Bauble, BaubleEx is not supported yet.
- Supported to be opened by other players when equipped.
- [x] Dyeing

### Upgrades

- [x] stack upgrade
- [x] exponential stack upgrade (RSB exclusive)
- [x] inception upgrade
- [x] pickup upgrade (b/a)
- [x] feeding upgrade (b/a)
- [x] deposit upgrade (b/a)
- [x] restock upgrade (b/a)
- [x] filter upgrade (b/a)
- [ ] magnet upgrade (b/a)
- [ ] void upgrade (b/a)
- [x] void upgrade (b/a)
- [x] crafting upgrade
- [ ] everlasting upgrade
- [ ] jukebox upgrade (low priority)
- [x] jukebox upgrade (b/a)
- [ ] refill upgrade (b/a)
- [ ] compacting upgrade (b/a)
- [ ] tool swapper upgrade (b/a)
- [ ] pump upgrade (b/a)
- [ ] experience pump upgrade
- [ ] tank upgrade
- [ ] battery upgrade
- [ ] anvil upgrade

## RSB Exclusive Features

### Upgrades

- [x] exponential stack upgrade
- Changes behavior of stack upgrade to be exponentially increasing.
- [ ] armor plate upgrade (from leather to diamond)
- Adds armor value to the backpack when equipped.

## Disclaimer

Expand Down
4 changes: 2 additions & 2 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ archives_base_name = RetroSophisticatedBackpacks
# If any properties changes below this line, run `gradlew setupDecompWorkspace` and refresh gradle again to ensure everything is working correctly.

# Kotlin Options
kotlin_version = 2.3.0
forgelin_continuous_version = 2.3.0.0
kotlin_version = 2.4.0
forgelin_continuous_version = 2.4.0.0

# Boilerplate Options
use_mixins = true
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,18 @@ public final class Capabilities {
@CapabilityInject(AdvancedFilterUpgradeWrapper.class)
public static final @NotNull Capability<AdvancedFilterUpgradeWrapper> ADVANCED_FILTER_UPGRADE_WRAPPER_CAPABILITY = null;

@CapabilityInject(VoidUpgradeWrapper.class)
public static final @NotNull Capability<VoidUpgradeWrapper> VOID_UPGRADE_CAPABILITY = null;

@CapabilityInject(AdvancedVoidUpgradeWrapper.class)
public static final @NotNull Capability<AdvancedVoidUpgradeWrapper> ADVANCED_VOID_UPGRADE_CAPABILITY = null;

@CapabilityInject(JukeboxUpgradeWrapper.class)
public static final @NotNull Capability<JukeboxUpgradeWrapper> JUKEBOX_UPGRADE_CAPABILITY = null;

@CapabilityInject(AdvancedJukeboxUpgradeWrapper.class)
public static final @NotNull Capability<AdvancedJukeboxUpgradeWrapper> ADVANCED_JUKEBOX_UPGRADE_CAPABILITY = null;

// Abstract capabilities
@CapabilityInject(UpgradeWrapper.class)
public static final @NotNull Capability<UpgradeWrapper<?>> UPGRADE_CAPABILITY = null;
Expand Down Expand Up @@ -71,4 +83,10 @@ public final class Capabilities {

@CapabilityInject(IFilterUpgrade.class)
public static final @NotNull Capability<IFilterUpgrade> IFILTER_UPGRADE_CAPABILITY = null;

@CapabilityInject(IVoidUpgrade.class)
public static final @NotNull Capability<IVoidUpgrade> IVOID_UPGRADE_CAPABILITY = null;

@CapabilityInject(IJukeboxUpgrade.class)
public static final @NotNull Capability<IJukeboxUpgrade> IJUKEBOX_UPGRADE_CAPABILITY = null;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.cleanroommc.retrosophisticatedbackpacks.mixin;

import net.minecraft.entity.Entity;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;

@Mixin(Entity.class)
public interface EntityAccessor {
@Accessor("isImmuneToFire")
void rsb$setIsImmuneToFire(boolean isImmuneToFire);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.cleanroommc.retrosophisticatedbackpacks.backpack

import com.cleanroommc.retrosophisticatedbackpacks.capability.BackpackWrapper
import com.cleanroommc.retrosophisticatedbackpacks.capability.Capabilities
import com.cleanroommc.retrosophisticatedbackpacks.capability.upgrade.IVoidUpgrade
import com.cleanroommc.retrosophisticatedbackpacks.item.BackpackItem
import net.minecraft.entity.Entity
import net.minecraft.inventory.IInventory
Expand Down Expand Up @@ -135,7 +136,7 @@ object BackpackInventoryHelper {
}

for (j in 0 until wrapper.backpackInventorySize()) {
stack = wrapper.backpackItemStackHandler.insertItemToMemorySlots(stack, false)
stack = wrapper.backpackItemStackHandler.insertItemToMemorySlotsRespectVoid(stack, false)

if (transferMatched && wrapper.getStackInSlot(j).isEmpty)
continue
Expand Down Expand Up @@ -220,23 +221,30 @@ object BackpackInventoryHelper {
if (source !is IItemHandlerModifiable)
return false

if (isFull(backpackInventory))
return false

for (i in 0 until source.slots) {
val sourceStack = source.getStackInSlot(i)

if (sourceStack.isEmpty)
continue

var copiedSourceStack = sourceStack.copy()
if (wrapper.canRestock(sourceStack)) {
val processedStack =
wrapper.tryVoid(sourceStack.copy(), IVoidUpgrade.TransferSource.UPGRADE_OR_WORLD_INTERACTION)

if (processedStack.count < sourceStack.count) {
transferred = true
}

if (processedStack.isEmpty) {
source.setStackInSlot(i, ItemStack.EMPTY)
continue
}

if (wrapper.canRestock(copiedSourceStack)) {
copiedSourceStack = ItemHandlerHelper.insertItemStacked(backpackInventory, copiedSourceStack, false)
val remainder = ItemHandlerHelper.insertItemStacked(backpackInventory, processedStack, false)

if (!ItemStack.areItemStacksEqual(sourceStack, copiedSourceStack)) {
if (!ItemStack.areItemStacksEqual(sourceStack, remainder)) {
transferred = true
source.setStackInSlot(i, copiedSourceStack)
source.setStackInSlot(i, remainder)
}
}
}
Expand All @@ -262,4 +270,4 @@ object BackpackInventoryHelper {

return true
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package com.cleanroommc.retrosophisticatedbackpacks.block
import com.cleanroommc.retrosophisticatedbackpacks.RetroSophisticatedBackpacks
import com.cleanroommc.retrosophisticatedbackpacks.backpack.BackpackTier
import com.cleanroommc.retrosophisticatedbackpacks.capability.Capabilities
import com.cleanroommc.retrosophisticatedbackpacks.handler.NetworkHandler
import com.cleanroommc.retrosophisticatedbackpacks.handler.RegistryHandler
import com.cleanroommc.retrosophisticatedbackpacks.network.C2CJukeboxUpgradePacket
import com.cleanroommc.retrosophisticatedbackpacks.tileentity.BackpackTileEntity
import com.cleanroommc.retrosophisticatedbackpacks.util.IModelRegister
import com.cleanroommc.retrosophisticatedbackpacks.util.Utils.asTranslationKey
Expand All @@ -18,6 +20,7 @@ import net.minecraft.block.properties.PropertyDirection
import net.minecraft.block.state.BlockFaceShape
import net.minecraft.block.state.BlockStateContainer
import net.minecraft.block.state.IBlockState
import net.minecraft.entity.Entity
import net.minecraft.entity.EntityLivingBase
import net.minecraft.entity.player.EntityPlayer
import net.minecraft.init.SoundEvents
Expand All @@ -27,6 +30,7 @@ import net.minecraft.tileentity.TileEntity
import net.minecraft.util.*
import net.minecraft.util.math.AxisAlignedBB
import net.minecraft.util.math.BlockPos
import net.minecraft.world.Explosion
import net.minecraft.world.IBlockAccess
import net.minecraft.world.World
import net.minecraftforge.fml.common.Optional
Expand All @@ -44,7 +48,7 @@ class BackpackBlock(
val RIGHT_TANK: PropertyBool = PropertyBool.create("right_tank")
val BATTERY: PropertyBool = PropertyBool.create("battery")
val FACING: PropertyDirection = PropertyDirection.create("facing", EnumFacing.Plane.HORIZONTAL)
const val BEDROCK_RESISTANCE = 3600000
const val BEDROCK_RESISTANCE = 6000000.0F

private val BOOL_PROPERTIES = arrayOf(LEFT_TANK, RIGHT_TANK, BATTERY)
}
Expand Down Expand Up @@ -155,7 +159,17 @@ class BackpackBlock(
}

override fun getPushReaction(state: IBlockState): EnumPushReaction =
EnumPushReaction.DESTROY
EnumPushReaction.NORMAL

override fun getExplosionResistance(world: World, pos: BlockPos, exploder: Entity?, explosion: Explosion): Float {
val wrapper = world.getTileEntity(pos)?.getCapability(Capabilities.BACKPACK_CAPABILITY, null)

if (wrapper != null && wrapper.hasEverlastingJukeboxUpgrade()) {
return BEDROCK_RESISTANCE
}

return super.getExplosionResistance(world, pos, exploder, explosion)
}

override fun hasComparatorInputOverride(state: IBlockState): Boolean =
true
Expand All @@ -173,10 +187,19 @@ class BackpackBlock(
placer: EntityLivingBase,
stack: ItemStack
) {
val backpackInventory = stack.getCapability(Capabilities.BACKPACK_CAPABILITY, null) ?: return
val wrapper = stack.getCapability(Capabilities.BACKPACK_CAPABILITY, null) ?: return
val tileEntity = worldIn.getTileEntity(pos) as? BackpackTileEntity ?: return

tileEntity.wrapper.deserializeNBT(backpackInventory.serializeNBT())
tileEntity.wrapper.deserializeNBT(wrapper.serializeNBT())

if (worldIn.isRemote)
NetworkHandler.INSTANCE.sendToServer(
C2CJukeboxUpgradePacket.Stationary(
C2CJukeboxUpgradePacket.PlayingAction.TRANSFER,
"",
tileEntity.getPos()
)
)

if (stack.hasDisplayName())
tileEntity.setCustomName(stack.displayName)
Expand Down Expand Up @@ -241,7 +264,7 @@ class BackpackBlock(
val tileEntityBackpackInventory = tileEntity.getCapability(Capabilities.BACKPACK_CAPABILITY, null) ?: return
val stackBackpackInventory = stack.getCapability(Capabilities.BACKPACK_CAPABILITY, null) ?: return
stackBackpackInventory.deserializeNBT(tileEntityBackpackInventory.serializeNBT())

if (tileEntity.hasCustomName())
stack.setStackDisplayName(tileEntity.name)

Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,15 @@
package com.cleanroommc.retrosophisticatedbackpacks.capability

import com.cleanroommc.retrosophisticatedbackpacks.backpack.SortType
import com.cleanroommc.retrosophisticatedbackpacks.capability.upgrade.IJukeboxUpgrade
import com.cleanroommc.retrosophisticatedbackpacks.capability.upgrade.IVoidUpgrade
import com.cleanroommc.retrosophisticatedbackpacks.inventory.BackpackItemStackHandler
import com.cleanroommc.retrosophisticatedbackpacks.inventory.UpgradeItemStackHandler
import com.cleanroommc.retrosophisticatedbackpacks.item.BackpackItem
import com.cleanroommc.retrosophisticatedbackpacks.item.EverlastingUpgradeItem
import com.cleanroommc.retrosophisticatedbackpacks.item.ExponentialStackUpgradeItem
import com.cleanroommc.retrosophisticatedbackpacks.item.InceptionUpgradeItem
import com.cleanroommc.retrosophisticatedbackpacks.item.JukeboxUpgradeItem
import com.cleanroommc.retrosophisticatedbackpacks.item.StackUpgradeItem
import com.cleanroommc.retrosophisticatedbackpacks.util.BackpackItemStackHelper
import net.minecraft.entity.player.EntityPlayer
Expand All @@ -16,12 +20,12 @@ import net.minecraftforge.common.capabilities.Capability
import net.minecraftforge.common.util.INBTSerializable
import net.minecraftforge.items.CapabilityItemHandler
import net.minecraftforge.items.IItemHandler
import net.minecraftforge.fml.common.FMLCommonHandler
import java.util.*

class BackpackWrapper(
var backpackInventorySize: () -> Int = { 27 },
var upgradeSlotsSize: () -> Int = { 1 },
var uuid: UUID = UUID.randomUUID(),
) : IItemHandler, ISidelessCapabilityProvider, INBTSerializable<NBTTagCompound> {
companion object {
private const val BACKPACK_INVENTORY_TAG = "BackpackInventory"
Expand All @@ -43,7 +47,16 @@ class BackpackWrapper(
const val DEFAULT_ACCENT_COLOR: Int = -0x9dd1e6
}


var uuid: UUID? = null
get() {
if (field == null && FMLCommonHandler.instance().effectiveSide.isServer) {
field = UUID.randomUUID()
}
return field
}
var isCached: Boolean = false

var backpackItemStackHandler = BackpackItemStackHandler(backpackInventorySize(), this)
var upgradeItemStackHandler = UpgradeItemStackHandler(upgradeSlotsSize())
var sortType: SortType = SortType.BY_NAME
Expand Down Expand Up @@ -128,6 +141,14 @@ class BackpackWrapper(

return true
}

fun hasJukeboxUpgrade(): Boolean =
upgradeItemStackHandler.inventory.map(ItemStack::getItem).filterIsInstance<JukeboxUpgradeItem>()
.isNotEmpty()

fun hasEverlastingJukeboxUpgrade(): Boolean =
upgradeItemStackHandler.inventory.map(ItemStack::getItem).filterIsInstance<EverlastingUpgradeItem>()
.isNotEmpty()

fun canNestBackpack(): Boolean =
upgradeItemStackHandler.inventory.map(ItemStack::getItem).filterIsInstance<InceptionUpgradeItem>().any()
Expand Down Expand Up @@ -162,20 +183,31 @@ class BackpackWrapper(

fun canInsert(stack: ItemStack): Boolean {
val filterUpgrades = gatherCapabilityUpgrades(Capabilities.IFILTER_UPGRADE_CAPABILITY)
.filter { it.enabled }

return if (filterUpgrades.isEmpty()) true
else filterUpgrades.any { it.canInsert(stack) }
return filterUpgrades.isEmpty() || filterUpgrades.any { it.canInsert(stack) }
}

fun canExtract(slotIndex: Int): Boolean {
val stack = getStackInSlot(slotIndex)
val filterUpgrades = gatherCapabilityUpgrades(Capabilities.IFILTER_UPGRADE_CAPABILITY)
.filter { it.enabled }

return if (filterUpgrades.isEmpty()) true
else filterUpgrades.any { it.canInsert(stack) }
return filterUpgrades.isEmpty() || filterUpgrades.any { it.canExtract(stack) }
}

fun tryVoid(stack: ItemStack, transferSource: IVoidUpgrade.TransferSource): ItemStack {
var currentStack = stack
val upgrades = gatherCapabilityUpgrades(Capabilities.IVOID_UPGRADE_CAPABILITY)

for (upgrade in upgrades) {
currentStack = upgrade.tryVoid(this, backpackItemStackHandler, currentStack, transferSource)
if (currentStack.isEmpty) return currentStack
}

return currentStack
}

fun getJukeboxUpgrade(): IJukeboxUpgrade? =
gatherCapabilityUpgrades(Capabilities.IJUKEBOX_UPGRADE_CAPABILITY).firstOrNull()

// Setting related

Expand Down Expand Up @@ -256,6 +288,8 @@ class BackpackWrapper(
nbt.setTag(UPGRADE_SLOTS_TAG, upgradesNbt)
nbt.setInteger(BACKPACK_INVENTORY_SIZE_TAG, backpackInventorySize())
nbt.setInteger(UPGRADE_SLOTS_SIZE_TAG, upgradeSlotsSize())
if (uuid != null)
nbt.setUniqueId(UUID_TAG, uuid!!)

nbt.setInteger(MAIN_COLOR_TAG, mainColor)
nbt.setInteger(ACCENT_COLOR_TAG, accentColor)
Expand All @@ -275,7 +309,6 @@ class BackpackWrapper(
backpackItemStackHandler.sortLockedSlots.map { if (it) 1 else 0 }.map(Int::toByte).toByteArray()
)

nbt.setUniqueId(UUID_TAG, uuid)
return nbt
}

Expand All @@ -285,7 +318,8 @@ class BackpackWrapper(
if (nbt.hasKey(UPGRADE_SLOTS_SIZE_TAG))
upgradeSlotsSize = { nbt.getInteger(UPGRADE_SLOTS_SIZE_TAG) }

uuid = nbt.getUniqueId(UUID_TAG)!!
if (nbt.hasUniqueId(UUID_TAG))
uuid = nbt.getUniqueId(UUID_TAG)

backpackItemStackHandler = BackpackItemStackHandler(backpackInventorySize(), this)
upgradeItemStackHandler = UpgradeItemStackHandler(upgradeSlotsSize())
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
package com.cleanroommc.retrosophisticatedbackpacks.capability.upgrade

import com.cleanroommc.retrosophisticatedbackpacks.RetroSophisticatedBackpacks
import com.cleanroommc.retrosophisticatedbackpacks.backpack.BackpackDataFixer
import com.cleanroommc.retrosophisticatedbackpacks.capability.Capabilities
import com.cleanroommc.retrosophisticatedbackpacks.inventory.ExposedItemStackHandler
import com.cleanroommc.retrosophisticatedbackpacks.item.FeedingUpgradeItem
import com.cleanroommc.retrosophisticatedbackpacks.util.BackpackItemStackHelper
import com.cleanroommc.retrosophisticatedbackpacks.util.Utils.asTranslationKey
import net.minecraft.item.ItemFood
import net.minecraft.item.ItemStack
import net.minecraft.nbt.NBTTagCompound
import net.minecraft.util.EnumFacing
import net.minecraftforge.common.capabilities.Capability
import net.minecraftforge.fml.common.Loader
import net.minecraftforge.items.IItemHandler
import squeek.applecore.api.AppleCoreAPI

class AdvancedFeedingUpgradeWrapper : AdvancedUpgradeWrapper<FeedingUpgradeItem>(), IFeedingUpgrade {
companion object {
Expand Down
Loading