Skip to content

Commit

Permalink
Merge pull request #9 from Kasualix/mc/1.16.5
Browse files Browse the repository at this point in the history
Backport to 1.16.5
  • Loading branch information
MichaelHillcox authored Dec 29, 2023
2 parents 1fd5934 + f7b074d commit a6795e8
Show file tree
Hide file tree
Showing 17 changed files with 170 additions and 208 deletions.
29 changes: 0 additions & 29 deletions .github/workflows/build.yml

This file was deleted.

25 changes: 7 additions & 18 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,30 +8,19 @@ on:
jobs:
build:
runs-on: ubuntu-latest
if: |
!contains(github.event.head_commit.message, '[ciskip]')
steps:
- uses: actions/checkout@v3
- name: Set up JDK
- name: Set up JDK 8
uses: actions/setup-java@v2
with:
java-version: '8'
distribution: 'temurin'
java-version: '17'
- name: Build with Gradle
- name: Setup Gradle
uses: gradle/gradle-build-action@v2
with:
arguments: build
- name: Publish to Maven & Curseforge
uses: gradle/gradle-build-action@v2
arguments: build publish publishMods --no-daemon
env:
SAPS_TOKEN: ${{ secrets.SAPS_TOKEN }}
CURSEFORGE_KEY: ${{ secrets.CURSEFORGE_KEY }}
with:
arguments: publish curseforgePublish
- name: Release to Github
uses: "softprops/action-gh-release@v1"
with:
body_path: "./CHANGELOG.md"
prerelease: false
files: |
./+(forge|fabric)/build/libs/*+@(mc+([0-9]).+([0-9]).+([0-9])).jar
MODRINTH_TOKEN: ${{ secrets.MODRINTH_TOKEN }}
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
CURSE_TOKEN: ${{ secrets.CURSEFORGE_KEY }}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -18,3 +18,5 @@ classes/
.settings
*.launch
.DS_Store

.architectury-transformer
6 changes: 3 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Accelerated Decay Changelog

## [0.1.3]
## [69.0.0]

### Fixed
### Changed

- Added protection around clients being able to call server events
- Backported to 1.16.5 thanks to [@Kasualix](https://github.com/Kasualix)
94 changes: 88 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
plugins {
id "architectury-plugin" version "3.4-SNAPSHOT"
id "dev.architectury.loom" version "0.12.0-SNAPSHOT" apply false
id "dev.architectury.loom" version "1.4-SNAPSHOT" apply false
id "me.modmuss50.mod-publish-plugin" version "0.4.5"
}

architectury {
Expand Down Expand Up @@ -30,24 +31,105 @@ allprojects {

ext.ENV = System.getenv()
ext.SNAPSHOT = ENV.SNAPSHOT != null && (ENV.SNAPSHOT == "true" || ENV.SNAPSHOT == true)
ext.MAVEN_URL = "https://maven.saps.dev/${SNAPSHOT ? "snapshots" : "releases"}"
ext.MAVEN_VERSION = rootProject.version + (SNAPSHOT ? "-SNAPSHOT" : "")

archivesBaseName = rootProject.archives_base_name
version = "${rootProject.mod_version}+mc${rootProject.minecraft_version}"
version = "${rootProject.mod_version}" + (SNAPSHOT ? "-SNAPSHOT" : "")
group = rootProject.maven_group

repositories {
}

tasks.withType(JavaCompile) {
options.encoding = "UTF-8"
options.release = 17
options.release = 8
}

java {
withSourcesJar()
}

publishing {
repositories {
if (providers.environmentVariable("SAPS_TOKEN").isPresent()) {
maven {
url "https://maven.saps.dev/${providers.environmentVariable("SNAPSHOT").map { "snapshots" }.getOrElse("releases")}"
credentials {
username = "errormikey"
password = "${providers.environmentVariable("SAPS_TOKEN").get()}"
}
}
}
}
}
}

task curseforgePublish
publishMods {
dryRun = providers.environmentVariable("CURSE_TOKEN").getOrNull() == null
changelog = file("./CHANGELOG.md").text
version = "${mod_version}"
type = STABLE

def fabricOptions = publishOptions {
file = project.provider { project(":fabric").tasks.remapJar }.flatMap { it.archiveFile }
displayName = "[FABRIC][${rootProject.minecraft_version}] ${project.name} ${mod_version}"
modLoaders.add("fabric")
}

def forgeOptions = publishOptions {
file = project.provider { project(":forge").tasks.remapJar }.flatMap { it.archiveFile }
displayName = "[FORGE][${rootProject.minecraft_version}] ${project.name} ${mod_version}"
modLoaders.add("neoforge")
}

def curseForgeOptions = curseforgeOptions {
accessToken = providers.environmentVariable("CURSE_TOKEN")
projectId = "${curseforge_id}"
minecraftVersions.add("${minecraft_version}")
}

def modrinthOptions = modrinthOptions {
accessToken = providers.environmentVariable("MODRINTH_TOKEN")
projectId = "${modrinth_id}"
minecraftVersions.add("${minecraft_version}")
}

curseforge("curseforgeFabric") {
from(curseForgeOptions, fabricOptions)
requires {
slug = "architectury-api"
slug = "fabric-api"
}
}

curseforge("curseforgeForge") {
from(curseForgeOptions, forgeOptions)
requires {
slug = "architectury-api"
}
}

modrinth("modrinthFabric") {
from(modrinthOptions, fabricOptions)
requires {
slug = "architectury-api"
slug = "fabric-api"
}
}

modrinth("modrinthForge") {
from(modrinthOptions, forgeOptions)
requires {
slug = "architectury-api"
}
}

github {
file = project.provider { project(":forge").tasks.remapJar }.flatMap { it.archiveFile }
additionalFiles.from project.provider { project(":fabric").tasks.remapJar }.flatMap { it.archiveFile }

repository = "${project.github_repo}"
accessToken = providers.environmentVariable("GITHUB_TOKEN")
commitish = providers.environmentVariable("GITHUB_SHA").orElse("dryRun")
tagName = providers.environmentVariable("GITHUB_REF_NAME").orElse("dryRun")
}
}
14 changes: 0 additions & 14 deletions common/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,6 @@ publishing {
mavenCommon(MavenPublication) {
artifactId = "${rootProject.archivesBaseName}-${project.name}"
from components.java

version = MAVEN_VERSION
}
}

repositories {
if (ENV.SAPS_TOKEN) {
maven {
url MAVEN_URL
credentials {
username = "errormikey"
password = "${ENV.SAPS_TOKEN}"
}
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package pro.mikey.accelerateddecay;

import io.netty.util.internal.ConcurrentSet;
import net.minecraft.core.BlockPos;
import net.minecraft.resources.ResourceKey;
import net.minecraft.server.level.ServerLevel;
Expand All @@ -13,61 +14,54 @@
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.level.gameevent.GameEvent;
import net.minecraft.world.level.levelgen.structure.BoundingBox;
import net.minecraft.world.level.material.FluidState;

import java.time.Instant;
import java.time.temporal.ChronoUnit;
import java.util.*;
import java.util.ArrayDeque;
import java.util.Deque;
import java.util.HashSet;
import java.util.Set;

public class AcceleratedDecay {
public static final String MOD_ID = "accelerateddecay";

private static final List<TimedDimBlockPos> timeBasedScanLocations = new ArrayList<>();

public static void init() {

}
private static final Set<TimedDimBlockPos> timeBasedScanLocations = new ConcurrentSet<>();

public static void levelTickPostEvent(ServerLevel serverLevel) {
if (timeBasedScanLocations.isEmpty()) {
return;
}

Instant now = Instant.now();
List<TimedDimBlockPos> locations = timeBasedScanLocations.stream()
.filter(e -> !e.checkAfter.isAfter(now) && serverLevel.dimension().equals(e.dim))
.toList();

if (locations.isEmpty()) {
return;
}
for (TimedDimBlockPos location : timeBasedScanLocations) {
if (!location.checkAfter.isAfter(now) && serverLevel.dimension().equals(location.dim)) {
if (location.player == null || !location.player.isAlive()) {
continue;
}

for (TimedDimBlockPos location : locations) {
if (location.player == null || !location.player.isAlive()) {
continue;
}
Set<BlockPos> yeetLeaves = seekLeaves(serverLevel, location.pos);

Set<BlockPos> yeetLeaves = seekLeaves(serverLevel, location.pos);
boolean isFirst = true;
for (BlockPos yeetLeaf : yeetLeaves) {
BlockState blockState = serverLevel.getBlockState(yeetLeaf);
if (!blockState.is(BlockTags.LEAVES)) {
continue;
}

boolean isFirst = true;
for (BlockPos yeetLeaf : yeetLeaves) {
BlockState blockState = serverLevel.getBlockState(yeetLeaf);
if (!blockState.is(BlockTags.LEAVES)) {
continue;
}
// Allow events to block us
if (!CrossPlatform.emitBlockBrokeEvent(serverLevel, yeetLeaf, blockState, location.player)) {
continue;
}

// Allow events to block us
if (!CrossPlatform.emitBlockBrokeEvent(serverLevel, yeetLeaf, blockState, location.player)) {
continue;
destroyBlockWithOptionalSoundAndParticles(serverLevel, yeetLeaf, true, 512, location.player, isFirst);
isFirst = false;
}

destroyBlockWithOptionalSoundAndParticles(serverLevel, yeetLeaf, true, 512, location.player, isFirst);
isFirst = false;
timeBasedScanLocations.remove(location);
}

timeBasedScanLocations.remove(location);
}
}

Expand All @@ -82,20 +76,21 @@ public static void breakEvent(Level level, BlockState state, BlockPos blockPos,

private static final BlockPos[] SCAN_LOCATIONS;
static {
var box = new BoundingBox(BlockPos.ZERO).inflatedBy(1);
BoundingBox box = new BoundingBox(-1, -1, -1, 1, 1, 1);
SCAN_LOCATIONS = BlockPos.betweenClosedStream(box).map(BlockPos::immutable).filter(e -> !e.equals(BlockPos.ZERO)).distinct().toArray(BlockPos[]::new);
}

private static Set<BlockPos> seekLeaves(Level level, BlockPos pos) {
Set<BlockPos> validLocations = new HashSet<>();
Set<BlockPos> walked = new HashSet<>();
Deque<BlockPos> nextToScan = new ArrayDeque<>(List.of(pos));
Deque<BlockPos> nextToScan = new ArrayDeque<>();
nextToScan.add(pos);

while (!nextToScan.isEmpty()) {
var currentLocation = nextToScan.pop();
BlockPos currentLocation = nextToScan.pop();
for (BlockPos offset : SCAN_LOCATIONS) {
BlockPos nextLocation = currentLocation.offset(offset);
var state = level.getBlockState(nextLocation);
BlockState state = level.getBlockState(nextLocation);

if (state.getBlock() instanceof LeavesBlock && !state.getValue(BlockStateProperties.PERSISTENT) && state.getValue(BlockStateProperties.DISTANCE) == 7 && validLocations.add(nextLocation)) {
if (walked.add(nextLocation)) {
Expand All @@ -120,20 +115,27 @@ public static void destroyBlockWithOptionalSoundAndParticles(Level level, BlockP
}

if (bl) {
BlockEntity blockEntity = blockState.hasBlockEntity() ? level.getBlockEntity(blockPos) : null;
BlockEntity blockEntity = blockState.getBlock().isEntityBlock() ? level.getBlockEntity(blockPos) : null;
Block.dropResources(blockState, level, blockPos, blockEntity, player, ItemStack.EMPTY);
}

boolean bl2 = level.setBlock(blockPos, fluidState.createLegacyBlock(), 3, i);
if (bl2) {
level.gameEvent(player, GameEvent.BLOCK_DESTROY, blockPos);
level.levelEvent(player, 2001, blockPos, Block.getId(blockState));
}
}

record TimedDimBlockPos(
Instant checkAfter,
BlockPos pos,
ResourceKey<Level> dim,
ServerPlayer player
) {}
static final class TimedDimBlockPos {
private final Instant checkAfter;
private final BlockPos pos;
private final ResourceKey<Level> dim;
private final ServerPlayer player;

public TimedDimBlockPos(Instant checkAfter, BlockPos pos, ResourceKey<Level> dim, ServerPlayer player) {
this.checkAfter = checkAfter;
this.pos = pos;
this.dim = dim;
this.player = player;
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"required": true,
"package": "pro.mikey.accelerateddecay.mixin",
"compatibilityLevel": "JAVA_17",
"compatibilityLevel": "JAVA_8",
"minVersion": "0.7",
"client": [],
"mixins": [],
Expand Down
Loading

0 comments on commit a6795e8

Please sign in to comment.