Skip to content

Commit

Permalink
Check slots before modification
Browse files Browse the repository at this point in the history
  • Loading branch information
shedaniel committed Jul 22, 2024
1 parent cd45e2d commit e6c8d55
Show file tree
Hide file tree
Showing 13 changed files with 60 additions and 18 deletions.
7 changes: 4 additions & 3 deletions .github/workflows/curseforge.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,17 +14,18 @@ jobs:
if: "!contains(github.event.head_commit.message, 'ci skip')"
steps:
- uses: actions/checkout@v1
- name: Set up JDK 11
- name: Set up JDK 16
uses: actions/setup-java@v1
with:
java-version: 11
java-version: 16
- name: Clean Gradle
run: ./gradlew clean --refresh-dependencies --stacktrace
env:
danielshe_curse_api_key: ${{ secrets.CF_API_KEY }}
BRANCH_NAME: ${{ github.ref }}
MAVEN_PASS: ${{ secrets.MAVEN_PASS }}
- name: Upload to CurseForge and Maven
run: ./gradlew build publish releaseOnCf --stacktrace
run: ./gradlew build publish releaseOnCf publish --stacktrace
env:
danielshe_curse_api_key: ${{ secrets.CF_API_KEY }}
BRANCH_NAME: ${{ github.ref }}
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ jobs:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v1
- name: Set up JDK 11
- name: Set up JDK 16
uses: actions/setup-java@v1
with:
java-version: 11
java-version: 16
- name: Build with Gradle
run: ./gradlew clean build --refresh-dependencies --stacktrace
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public interface DumpHandler<T extends AbstractContainerMenu> {

static StackAccessor getOccupiedSlotWithRoomForStack(ItemStack stack, List<StackAccessor> inventoryStacks) {
for (StackAccessor inventoryStack : inventoryStacks) {
if (canStackAddMore(inventoryStack.getItemStack(), stack)) {
if (canStackAddMore(inventoryStack.getItemStack(), stack) && inventoryStack.canPlace(stack)) {
return inventoryStack;
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,10 @@ static <T extends AbstractContainerMenu> void returnSlotToPlayerInventory(Contai
DumpHandler<T> dumpHandler = context.getContainerInfo().getDumpHandler();
ItemStack stackToReturn = stackAccessor.getItemStack();
if (!stackToReturn.isEmpty()) {
if (!stackAccessor.allowModification(context.getPlayerEntity())) {
error("rei.rei.no.slot.in.inv");
}

for (; stackToReturn.getCount() > 0; stackAccessor.takeStack(1)) {
ItemStack stackToInsert = stackToReturn.copy();
stackToInsert.setCount(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

package me.shedaniel.rei.server;

import net.minecraft.world.entity.player.Player;
import net.minecraft.world.inventory.Slot;
import net.minecraft.world.item.ItemStack;

Expand All @@ -47,4 +48,14 @@ public void setItemStack(ItemStack stack) {
public ItemStack takeStack(int amount) {
return slot.remove(amount);
}

@Override
public boolean allowModification(Player player) {
return slot.mayPickup(player) && slot.mayPlace(getItemStack());
}

@Override
public boolean canPlace(ItemStack stack) {
return slot.mayPlace(stack);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@

package me.shedaniel.rei.server;

import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;

public interface StackAccessor {
Expand All @@ -31,4 +32,12 @@ public interface StackAccessor {
void setItemStack(ItemStack stack);

ItemStack takeStack(int amount);

default boolean allowModification(Player player) {
return true;
}

default boolean canPlace(ItemStack stack) {
return true;
}
}
2 changes: 1 addition & 1 deletion RoughlyEnoughItems-default-plugin/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,5 +5,5 @@ loom {
}

dependencies {
compile project(path: ':RoughlyEnoughItems-api', configuration: 'dev')
compileOnly project(path: ':RoughlyEnoughItems-api', configuration: 'dev')
}
2 changes: 1 addition & 1 deletion RoughlyEnoughItems-runtime/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,6 @@ loom {
}

dependencies {
compile project(path: ':RoughlyEnoughItems-api', configuration: 'dev')
compileOnly project(path: ':RoughlyEnoughItems-api', configuration: 'dev')
modCompileOnly("alexiil.mc.lib:libblockattributes-fluids:0.8.3-pre.3")
}
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ protected void fillInputSlot(StackAccessor slot, ItemStack toBeTakenStack) {
}

takenStack.setCount(1);
if (!slot.canPlace(takenStack)) {
return;
}

if (slot.getItemStack().isEmpty()) {
slot.setItemStack(takenStack);
} else {
Expand Down Expand Up @@ -161,13 +165,22 @@ protected void returnInputs() {
}

public int method_7371(ItemStack itemStack) {
boolean rejectedModification = false;
for (int i = 0; i < inventoryStacks.size(); i++) {
ItemStack itemStack1 = this.inventoryStacks.get(i).getItemStack();
if (!itemStack1.isEmpty() && areItemsEqual(itemStack, itemStack1) && !itemStack1.isDamaged() && !itemStack1.isEnchanted() && !itemStack1.hasCustomHoverName()) {
return i;
if (!this.inventoryStacks.get(i).allowModification(player)) {
rejectedModification = true;
} else {
return i;
}
}
}

if (rejectedModification) {
throw new IllegalStateException("Unable to take item from inventory due to slot not allowing modification! Item requested: " + itemStack);
}

return -1;
}

Expand Down
16 changes: 10 additions & 6 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
plugins {
id("forgified-fabric-loom") version("0.6.66") apply false
id("dev.architectury.loom") version("0.9.0-SNAPSHOT") apply false
id("maven-publish")
id("java")
id("java-library")
id("net.minecrell.licenser") version("0.4.1")
id("org.cadixdev.licenser") version("0.6.1")
id("com.matthewprenger.cursegradle") version("1.4.0")
}

Expand All @@ -20,8 +20,8 @@ group = "me.shedaniel"

allprojects {
apply plugin: 'maven-publish'
apply plugin: 'forgified-fabric-loom'
apply plugin: 'net.minecrell.licenser'
apply plugin: 'dev.architectury.loom'
apply plugin: 'org.cadixdev.licenser'

sourceCompatibility = targetCompatibility = 1.8

Expand All @@ -31,8 +31,12 @@ allprojects {
}

repositories {
maven { url "https://maven.shedaniel.me" }
maven { url "https://maven.terraformersmc.com/releases" }
maven { url "https://maven.shedaniel.me/" }
}

jar {
from "LICENSE"
}

processResources {
Expand Down Expand Up @@ -163,7 +167,7 @@ task remapMavenJar(type: RemapJarTask, dependsOn: jar) {

dependencies {
subprojects.each {
compile project(path: ":${it.name}", configuration: "dev")
compileOnly project(path: ":${it.name}", configuration: "dev")
include project(path: ":${it.name}", configuration: "remapped")
}
}
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
org.gradle.jvmargs=-Xmx3G
base_version=5.12
base_version=5.12.1
supported_version=1.16.4/5
minecraft_version=1.16.5
fabricloader_version=0.12.12
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.8.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.6.4-all.zip
2 changes: 1 addition & 1 deletion settings.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@ pluginManagement {
repositories {
maven { url "https://maven.shedaniel.me/" }
maven { url "https://maven.fabricmc.net/" }
maven { url "https://files.minecraftforge.net/maven/" }
gradlePluginPortal()
maven { url "https://files.minecraftforge.net/maven/" }
}
}

Expand Down

0 comments on commit e6c8d55

Please sign in to comment.