Skip to content

Commit

Permalink
Merge pull request #469 from P3pp3rF1y/1.20.x-dev
Browse files Browse the repository at this point in the history
Release merge
  • Loading branch information
P3pp3rF1y authored Sep 20, 2024
2 parents 320f263 + 6000b7a commit ea80e32
Show file tree
Hide file tree
Showing 11 changed files with 325 additions and 116 deletions.
28 changes: 20 additions & 8 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,11 @@ jobs:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v1
- uses: actions/checkout@v4
with:
fetch-depth: 200 # Fetch 200 latest commits to make sure changelog can be created from merge commits
- name: Set up JDK 17
uses: actions/setup-java@v2
uses: actions/setup-java@v4
with:
java-version: 17
distribution: zulu
Expand All @@ -19,7 +21,7 @@ jobs:
env:
USERNAME: ${{ secrets.USERNAME }}
READ_PACKAGES_TOKEN: ${{ secrets.READ_PACKAGES_TOKEN }}
uses: nick-invision/retry@v2
uses: nick-invision/retry@v3
with:
timeout_minutes: 10
max_attempts: 3
Expand All @@ -29,10 +31,22 @@ jobs:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
run: ./gradlew build publish
- name: Cleanup old artifacts
uses: actions/delete-package-versions@v3
uses: actions/delete-package-versions@v5
with:
package-name: 'sophisticatedstorage.sophisticatedstorage'
package-type: 'maven'
min-versions-to-keep: 10
- name: Publish to CurseForge
env:
CURSEFORGE_TOKEN: ${{ secrets.CURSEFORGE_TOKEN }}
run: |
BRANCH_NAME=${GITHUB_REF##*/}
if [[ "$BRANCH_NAME" =~ ^[0-9]+\.[0-9]+\.([0-9]+|x)$ ]]; then
./gradlew curseforge
else
echo "Branch name does not match the pattern: $BRANCH_NAME. Skipping CurseForge upload."
exit 0
fi
- name: Code Quality
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
Expand All @@ -43,7 +57,7 @@ jobs:
echo "VERSION_NAME=$(${{github.workspace}}/gradlew -q printVersionName | awk -F "version:" '{printf $2}')" >> $GITHUB_OUTPUT
id: version
- name : Compile version message
uses: actions/github-script@v6
uses: actions/github-script@v7
with:
script: |
const gh = ${{ toJSON(github) }};
Expand All @@ -64,11 +78,9 @@ jobs:
core.setOutput('EMBED_DESCRIPTION', description);
id: embed
- name: Send Discord Notification
uses: tsickert/discord-webhook@v5.3.0
uses: tsickert/discord-webhook@v6.0.0
with:
webhook-url: ${{ secrets.DISCORD_WEBHOOK }}
embeds: ${{steps.embed.outputs.EMBEDS}}
content: null
embed-title: "${{steps.embed.outputs.EMBED_TITLE}}"
embed-url: "${{steps.embed.outputs.EMBED_URL}}"
embed-description: "${{steps.embed.outputs.EMBED_DESCRIPTION}}"
Expand Down
112 changes: 112 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ plugins {
id "maven-publish"
id 'net.neoforged.gradle' version '[6.0.18,6.2)'
id 'org.parchmentmc.librarian.forgegradle' version '1.+'
id "net.darkhax.curseforgegradle" version "1.1.15"
}

idea {
Expand Down Expand Up @@ -238,6 +239,117 @@ sonarqube {
}
}

task generateChangelog {
doLast {
def changelog = new StringBuilder()

// Function to remove characters with Unicode code points 129 or higher
def removeHighUnicodeChars = { text ->
text.codePoints()
.filter { codePoint -> codePoint <= 0x007F } // Keep only ASCII characters (U+0000 to U+007F)
.collect { codePoint -> new String(Character.toChars(codePoint)) }
.join('')
}

// Function to format commit messages with nesting
def formatMultilineMessage = { message ->
// Split message by lines, trim whitespace, and create formatted list
def lines = message.split('\n')
def formattedMessage = lines[0].trim() // First line as top-level list item
if (lines.size() > 1) {
formattedMessage += "\n" + lines[1..-1].collect { line ->
// Trim the line and remove leading dash if present
def trimmedLine = line.trim()
if (trimmedLine.startsWith('-')) {
trimmedLine = trimmedLine.substring(1).trim()
}
" - ${trimmedLine}" // Nested list for additional lines
}.join('\n')
}
return formattedMessage
}

// Function to remove [DEV] section from commit message
def removeDevSection = { message ->
def devIndex = message.indexOf('[DEV]')
if (devIndex != -1) {
return message.substring(0, devIndex).trim()
}
return message
}

// Get the latest commit hash
def latestCommitHash = "git rev-parse HEAD".execute().text.trim()

// Check if the latest commit is a merge commit
def parentCommits = "git rev-list --parents -n 1 ${latestCommitHash}".execute().text.split()
logger.info("Parent commits: ${parentCommits}")

def commitMessages = []
if (parentCommits.size() > 2) { // Merge commit has more than 2 parents
def firstParent = parentCommits[1]
def secondParent = parentCommits[2]
def gitLogCommand = [
"bash", "-c", "git log --pretty=format:%B ${firstParent}..${secondParent}"
]
commitMessages = gitLogCommand.execute().text.split('\n\n') // Split by two newlines for each commit
logger.info("Merge commit, ran git log command: ${gitLogCommand.join(' ')} and got ${commitMessages}")
} else {
// Single commit log
commitMessages = "git log -1 --pretty=%B".execute().text.split('\n\n')
// Split by two newlines for each commit
logger.info("Single commit, ran git log command: git log -1 --pretty=%B and got ${commitMessages}");
}

def features = []
def fixes = []
commitMessages.each { commitMessage ->
commitMessage = removeHighUnicodeChars(commitMessage) // Remove high Unicode characters
commitMessage = removeDevSection(commitMessage) // Remove [DEV] section

if (commitMessage.startsWith('feat: ')) {
features.add(commitMessage.replaceFirst('feat: ', '').trim())
} else if (commitMessage.startsWith('fix: ')) {
fixes.add(commitMessage.replaceFirst('fix: ', '').trim())
}
}

if (features) {
changelog.append("### Features\n")
features.each { feature -> changelog.append("- ${formatMultilineMessage(feature)}\n") }
}

if (fixes) {
changelog.append("### Fixes\n")
fixes.each { fix -> changelog.append("- ${formatMultilineMessage(fix)}\n") }
}

// Store the changelog in a project property or an environment variable
logger.info("Compiled changelog: " + changelog.toString())
project.ext.changelog = changelog.toString()
}
project.ext.changelog = ""
}

task curseforge(type: net.darkhax.curseforgegradle.TaskPublishCurseForge) {
dependsOn 'generateChangelog'

apiToken = System.getenv("CURSEFORGE_TOKEN")
def mainFile = upload(project.curseforge_id, file("${project.buildDir}/libs/${archivesBaseName}-${version}.jar"))
mainFile.changelogType = 'markdown'
mainFile.changelog = {project.ext.changelog}
mainFile.addModLoader('NeoForge')
mainFile.addModLoader('Forge')
mainFile.releaseType = "${release_type}"
"${release_versions}".split(',').each {
mainFile.addGameVersion("${it}")
}
mainFile.addRequirement('sophisticated-core')
mainFile.addOptional('jei')
mainFile.addOptional('crafting-tweaks')
onlyIf { !project.ext.changelog.isEmpty() }
}

task printVersionName {
println "version:" + project.version
}
Expand Down
7 changes: 6 additions & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ org.gradle.daemon=false

mod_id=sophisticatedstorage
mod_group_id=sophisticatedstorage
mod_version=0.10.26
mod_version=0.10.30
sonar_project_key=sophisticatedstorage:SophisticatedStorage
github_package_url=https://maven.pkg.github.com/P3pp3rF1y/SophisticatedStorage

Expand All @@ -14,6 +14,11 @@ neo_version=47.1.5
neo_version_range=[47.1,)
loader_version_range=[47,)

#publish
curseforge_id=619320
release_type=release
release_versions=1.20.1

#deps
jei_mc_version=1.20.1-forge
jei_version=15.3.0.4
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
import net.p3pp3rf1y.sophisticatedcore.api.IDisplaySideStorage;
import net.p3pp3rf1y.sophisticatedcore.util.InventoryHelper;
import net.p3pp3rf1y.sophisticatedcore.util.WorldHelper;
import net.p3pp3rf1y.sophisticatedstorage.Config;
import net.p3pp3rf1y.sophisticatedstorage.common.gui.StorageContainerMenu;
import net.p3pp3rf1y.sophisticatedstorage.init.ModBlocks;
import net.p3pp3rf1y.sophisticatedstorage.item.CapabilityStorageWrapper;
Expand Down Expand Up @@ -132,7 +133,7 @@ public BlockState updateShape(BlockState state, Direction facing, BlockState fac
}
} else if (getConnectedDirection(state) == facing) {
level.getBlockEntity(currentPos, ModBlocks.CHEST_BLOCK_ENTITY_TYPE.get()).ifPresent(be -> {
if (!level.isClientSide() && !be.isBeingUpgraded()) {
if (!level.isClientSide() && !be.isBeingUpgraded() && !be.isPacked()) {
if (be.isMainChest() && state.getBlock() instanceof ChestBlock chestBlock) {
be.dropSecondPartContents(chestBlock, facingPos);
} else if (!be.isMainChest()) {
Expand Down Expand Up @@ -349,11 +350,18 @@ public boolean onDestroyedByPlayer(BlockState state, Level level, BlockPos pos,
if (state.getValue(TYPE) != ChestType.SINGLE) {
level.getBlockEntity(pos, ModBlocks.CHEST_BLOCK_ENTITY_TYPE.get()).ifPresent(be -> {
be.setDestroyedByPlayer();
if (be.isPacked() && !be.isMainChest()) {
if ((be.isPacked() || Boolean.TRUE.equals(Config.COMMON.dropPacked.get())) && !be.isMainChest()) {
//copy storage wrapper to "not main" chest so that its data can be transferred to stack properly
BlockPos otherPartPos = pos.relative(getConnectedDirection(state));
level.getBlockEntity(otherPartPos, ModBlocks.CHEST_BLOCK_ENTITY_TYPE.get())
.ifPresent(mainBe -> be.getStorageWrapper().load(mainBe.getStorageWrapper().save(new CompoundTag())));
.ifPresent(mainBe -> {
be.getStorageWrapper().load(mainBe.getStorageWrapper().save(new CompoundTag()));

//remove main chest contents
CompoundTag contentsTag = new CompoundTag();
contentsTag.put(StorageWrapper.CONTENTS_TAG, new CompoundTag());
mainBe.getStorageWrapper().load(contentsTag);
});
}
});
}
Expand Down Expand Up @@ -447,14 +455,17 @@ public boolean canChangeDisplaySide(BlockState state) {
}

@Override
public BlockPos getNeighborPos(BlockState state, BlockPos origin, Direction facing) {
public List<BlockPos> getNeighborPos(BlockState state, BlockPos origin, Direction facing) {
if (state.getValue(TYPE) == ChestType.SINGLE) {
return origin.relative(facing);
return List.of(origin.relative(facing));
} else {
if (getConnectedDirection(state) == facing) {
return origin.relative(facing).relative(facing);
Direction connectedDirection = getConnectedDirection(state);
if (connectedDirection == facing) {
return List.of(origin.relative(facing).relative(facing));
} else if (connectedDirection.getOpposite() == facing) {
return List.of(origin.relative(facing));
}
return origin.relative(facing);
return List.of(origin.relative(facing), origin.relative(connectedDirection).relative(facing));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ public boolean tryFillUpgrades(Player player, InteractionHand hand, Level level,
}

@SuppressWarnings("java:S1172") // Parameter used in overrides
public BlockPos getNeighborPos(BlockState state, BlockPos origin, Direction facing) {
return origin.relative(facing);
public List<BlockPos> getNeighborPos(BlockState state, BlockPos origin, Direction facing) {
return List.of(origin.relative(facing));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ public ItemStack getWrappedStorageStack() {

@Override
protected void onUpgradeRefresh() {
if (!isDroppingContents && level != null && !level.isClientSide && getBlockState().getBlock() instanceof IStorageBlock storageBlock) {
if (canRefreshUpgrades() && getBlockState().getBlock() instanceof IStorageBlock storageBlock) {
storageBlock.setTicking(level, getBlockPos(), getBlockState(), !storageWrapper.getUpgradeHandler().getWrappersThatImplement(ITickableUpgrade.class).isEmpty());
}
}
Expand Down Expand Up @@ -158,6 +158,10 @@ public ITrackedContentsItemHandler getInventoryForInputOutput() {
storageWrapper.setUpgradeCachesInvalidatedHandler(this::onUpgradeCachesInvalidated);
}

protected boolean canRefreshUpgrades() {
return !isDroppingContents && level != null && !level.isClientSide;
}

@SuppressWarnings("java:S1172") //parameter used in override
protected ItemStack addWrappedStorageStackData(ItemStack cloneItemStack, BlockState state) {
return cloneItemStack;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ public void addDropData(ItemStack stack, StorageBlockEntity be) {
}
WoodStorageBlockItem.setPacked(stack, true);
StorageBlockItem.setShowsTier(stack, be.shouldShowTier());
WoodStorageBlockItem.setNumberOfUpgradeSlots(stack, storageWrapper.getInventoryHandler().getSlots());
WoodStorageBlockItem.setNumberOfInventorySlots(stack, storageWrapper.getInventoryHandler().getSlots());
WoodStorageBlockItem.setNumberOfUpgradeSlots(stack, storageWrapper.getUpgradeHandler().getSlots());
}
}
Expand Down Expand Up @@ -214,13 +214,14 @@ protected void packStorage(Player player, InteractionHand hand, WoodStorageBlock
player.setItemInHand(hand, ItemStack.EMPTY);
}
}
b.setPacked(true);

BlockState blockState = b.getBlockState();
if (blockState.getBlock() instanceof StorageBlockBase storageBlock && blockState.getValue(StorageBlockBase.TICKING)) {
storageBlock.setTicking(player.level(), b.getBlockPos(), blockState, false);
}

b.setPacked(true);

b.removeFromController();

WorldHelper.notifyBlockUpdate(b);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,4 +113,9 @@ public boolean canBeConnected() {
public boolean canBeLinked() {
return !packed;
}

@Override
protected boolean canRefreshUpgrades() {
return super.canRefreshUpgrades() && !packed;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -559,6 +559,10 @@ private void insertIntoInternalAndCalculated(int slotToStartFrom, long amountToI
}

if (amountToSet != 0) {
if (!slotDefinitions.containsKey(slot + 1)) {
SophisticatedStorage.LOGGER.error("Compression inventory is in an invalid state. Slot {} is compressible, there's stack remaining to insert but slot {} is not defined.\nSlot Definitions\n{}", slot, slot + 1, slotDefinitions);
break;
}
totalMultiplier /= getPrevSlotMultiplier(slot + 1);
}
slot++;
Expand Down Expand Up @@ -738,5 +742,16 @@ public void setCompressible(boolean compressible) {
public boolean isCompressible() {
return isCompressible;
}

@Override
public String toString() {
return "SlotDefinition{" +
"item=" + item +
", prevSlotMultiplier=" + prevSlotMultiplier +
", slotLimit=" + slotLimit +
", isAccessible=" + isAccessible +
", isCompressible=" + isCompressible +
'}';
}
}
}
Loading

0 comments on commit ea80e32

Please sign in to comment.