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
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
- Fixed compatibility issue with Enchancement caused by mixins not chaining.
- Fixed `/reload` breaking some functionality.
- Fixed lang overrides not being respected in some cases.
- Added some config options to revert the loot table and recipe changes by the mod.
- Added some config options to revert the loot table and recipe changes by the mod.
- Fixed mapped doors dropping duplicate items when broken.
11 changes: 10 additions & 1 deletion buildSrc/src/main/kotlin/common.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@ plugins {
idea
}

dependencies {
testImplementation("org.junit.jupiter:junit-jupiter:5.11.4")
testRuntimeOnly("org.junit.platform:junit-platform-launcher:1.11.4")
}

tasks.test {
useJUnitPlatform()
}

version = "${prop("mod.version")}+${dep("minecraft")}-$loaderName"
base.archivesName = prop("mod.id")

Expand Down Expand Up @@ -75,4 +84,4 @@ stonecutterBuild.replacements.string {
stonecutterBuild.replacements.string {
direction = stonecutterBuild.eval(mc, ">1.21.2")
replace("DirectionProperty", "EnumProperty<Direction>")
}
}
23 changes: 23 additions & 0 deletions src/main/java/dev/tazer/clutternomore/common/CHooks.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.Property;
import net.minecraft.world.level.block.state.properties.SlabType;
import net.minecraft.world.level.storage.loot.LootParams;
import net.minecraft.world.level.storage.loot.parameters.LootContextParams;
Expand All @@ -36,11 +37,33 @@ public static List<ItemStack> getDrops(List<ItemStack> old, BlockState state, Se
) {
Item item = state.getBlock().asItem();
if (ShapeMap.isShape(item) && ClutterNoMore.STARTUP_CONFIG.INHERIT_LOOT_TABLES.value()) {
if (isNonLowerMultiBlockPart(state)) return old;

LootParams.Builder lootparams$builder = (new LootParams.Builder(level)).withParameter(LootContextParams.ORIGIN, Vec3.atCenterOf(pos)).withParameter(LootContextParams.TOOL, tool).withOptionalParameter(LootContextParams.THIS_ENTITY, entity).withOptionalParameter(LootContextParams.BLOCK_ENTITY, blockEntity);
BlockState newState = Block.byItem(ShapeMap.getParent(item)).defaultBlockState();
for (Property<?> property : state.getProperties()) {
newState = copyProperty(state, newState, property);
}
return newState.getDrops(lootparams$builder);
}

return old;
}

private static boolean isNonLowerMultiBlockPart(BlockState state) {
for (Property<?> property : state.getProperties()) {
if (MultiBlockLootPart.isNonLower(property.getName(), propertyValueName(state, property))) {
return true;
}
}
return false;
}

private static <T extends Comparable<T>> String propertyValueName(BlockState state, Property<T> property) {
return property.getName(state.getValue(property));
}

private static <T extends Comparable<T>> BlockState copyProperty(BlockState source, BlockState target, Property<T> property) {
return target.hasProperty(property) ? target.setValue(property, source.getValue(property)) : target;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package dev.tazer.clutternomore.common;

final class MultiBlockLootPart {
private MultiBlockLootPart() {}

static boolean isNonLower(String property, String value) {
return (property.equals("half") || property.equals("third")) && (value.equals("middle") || value.equals("upper"));
}
}
24 changes: 24 additions & 0 deletions src/test/java/dev/tazer/clutternomore/common/CHooksTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package dev.tazer.clutternomore.common;

import org.junit.jupiter.api.Test;

import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;

class CHooksTest {
@Test
void suppressesOnlyNonLowerMultiBlockParts() {
assertFalse(MultiBlockLootPart.isNonLower("half", "lower"));
assertTrue(MultiBlockLootPart.isNonLower("half", "upper"));

assertFalse(MultiBlockLootPart.isNonLower("third", "lower"));
assertTrue(MultiBlockLootPart.isNonLower("third", "middle"));
assertTrue(MultiBlockLootPart.isNonLower("third", "upper"));
}

@Test
void ignoresUnrelatedPropertiesAndValues() {
assertFalse(MultiBlockLootPart.isNonLower("facing", "upper"));
assertFalse(MultiBlockLootPart.isNonLower("half", "top"));
}
}