Skip to content

Threshold switch improvements #8097

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: mc1.20.1/dev
Choose a base branch
from
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// 1.20.1 2025-03-06T11:39:12.3943554 Registrate Provider for create [Recipes, Advancements, Loot Tables, Tags (blocks), Tags (items), Tags (fluids), Tags (entity_types), Blockstates, Item models, Lang (en_us/en_ud)]
// 1.20.1 2025-03-23T15:20:19.1974883 Registrate Provider for create [Recipes, Advancements, Loot Tables, Tags (blocks), Tags (items), Tags (fluids), Tags (entity_types), Blockstates, Item models, Lang (en_us/en_ud)]
60bbdf92d2ac9824ea6144955c74043a6005f79d assets/create/blockstates/acacia_window.json
6a67703c2697d81b7dc83e9d72a66f9c9ff08383 assets/create/blockstates/acacia_window_pane.json
c3ae87b62e81d8e9476eccd793bb1548d74c66a1 assets/create/blockstates/adjustable_chain_gearshift.json
Expand Down Expand Up @@ -4705,8 +4705,11 @@ f400870b8dbcd14238be3ec99c419093073ba3a6 data/create/tags/blocks/postboxes.json
55dccb895bbdacfbd6ee9005486cd3fe9df01249 data/create/tags/blocks/safe_nbt.json
79418bd729cef417b322cef9b491e7ae83317d61 data/create/tags/blocks/seats.json
7d783d948cc49503fb645045fe9ef48906b74341 data/create/tags/blocks/simple_mounted_storage.json
da544bd0281138617f5cd6b2a04920ccf7034d4b data/create/tags/blocks/single_block_inventories.json
f02fc9781e8f0ae33ed3b98cf4f46ba6927c7ff8 data/create/tags/blocks/sugar_cane_variants.json
8a6ad3c63fb0c436ec8109f39358213930effd5a data/create/tags/blocks/table_cloths.json
35133e95f1c8fdd7a1c21afcc231fc0bffefb9a8 data/create/tags/blocks/threshold_switch_ignore_fluids.json
4a3abc1f941fb5d74afa6a3b6d00c9809f2fcc2d data/create/tags/blocks/threshold_switch_ignore_items.json
5def5088f7fd31b80e6f28c1c4ea146aa9d7d15b data/create/tags/blocks/toolboxes.json
2589b135c0e96ad29076569e144528fe32ea5b39 data/create/tags/blocks/tracks.json
1b6977d9a399cf6ee042e3f8f5e64e4d3cda5489 data/create/tags/blocks/tree_attachments.json
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"values": []
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"values": [
{
"id": "mekanism:basic_fluid_tank",
"required": false
},
{
"id": "mekanism:advanced_fluid_tank",
"required": false
},
{
"id": "mekanism:elite_fluid_tank",
"required": false
},
{
"id": "mekanism:ultimate_fluid_tank",
"required": false
}
]
}
2 changes: 2 additions & 0 deletions src/main/java/com/simibubi/create/AllTags.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,8 @@ public enum AllBlockTags {
SUGAR_CANE_VARIANTS,
NON_HARVESTABLE,
SINGLE_BLOCK_INVENTORIES,
THRESHOLD_SWITCH_IGNORE_ITEMS,
THRESHOLD_SWITCH_IGNORE_FLUIDS,

CORALS,

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.util.List;

import com.simibubi.create.AllTags.AllBlockTags;
import com.simibubi.create.compat.thresholdSwitch.FunctionalStorage;
import com.simibubi.create.compat.thresholdSwitch.SophisticatedStorage;
import com.simibubi.create.compat.thresholdSwitch.StorageDrawers;
Expand Down Expand Up @@ -144,12 +145,12 @@ public void updateCurrentLevel() {
currentMaxLevel = StorageDrawers.getTotalStorageSpace(observedInventory.getInventory());
*/

} else if (observedInventory.hasInventory() || observedTank.hasInventory()) {
} else if (shouldMeasureItems() || shouldMeasureFluids()) {
currentMinLevel = 0;
currentLevel = 0;
currentMaxLevel = 0;

if (observedInventory.hasInventory()) {
if (shouldMeasureItems()) {

// Item inventory
IItemHandler inv = observedInventory.getInventory();
Expand Down Expand Up @@ -181,7 +182,7 @@ public void updateCurrentLevel() {
}
}

if (observedTank.hasInventory()) {
if (shouldMeasureFluids()) {
// Fluid inventory
IFluidHandler tank = observedTank.getInventory();
for (int slot = 0; slot < tank.getTanks(); slot++) {
Expand Down Expand Up @@ -248,6 +249,22 @@ private BlockPos getTargetPos() {
return worldPosition.relative(ThresholdSwitchBlock.getTargetDirection(getBlockState()));
}

private boolean shouldMeasureItems() {
BlockPos target = getTargetPos();
if (AllBlockTags.THRESHOLD_SWITCH_IGNORE_ITEMS.matches(level.getBlockState(target))) {
return false;
}
return observedInventory.hasInventory();
}

private boolean shouldMeasureFluids() {
BlockPos target = getTargetPos();
if (AllBlockTags.THRESHOLD_SWITCH_IGNORE_FLUIDS.matches(level.getBlockState(target))) {
return false;
}
return observedTank.hasInventory();
}

public ItemStack getDisplayItemForScreen() {
BlockPos target = getTargetPos();
return new ItemStack(level.getBlockState(target)
Expand All @@ -273,15 +290,26 @@ public MutableComponent format(int value, boolean stacks) {
}

public ThresholdType getTypeOfCurrentTarget() {
if (observedInventory.hasInventory())
if (shouldMeasureItems())
return ThresholdType.ITEM;
if (observedTank.hasInventory())
if (shouldMeasureFluids())
return ThresholdType.FLUID;
if (level.getBlockEntity(getTargetPos()) instanceof ThresholdSwitchObservable)
return ThresholdType.CUSTOM;
return ThresholdType.UNSUPPORTED;
}

public int getValueStep(boolean stacks) {
if (level.getBlockEntity(getTargetPos()) instanceof ThresholdSwitchObservable observable)
return observable.getValueStep(stacks);
int valueStep = 1;
if (getTypeOfCurrentTarget() == ThresholdType.FLUID)
valueStep = 1000;
else if (stacks)
valueStep = 64;
return valueStep;
}

protected void scheduleBlockTick() {
Block block = getBlockState().getBlock();
if (!level.getBlockTicks()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@
import net.minecraft.network.chat.MutableComponent;

public interface ThresholdSwitchObservable {

public int getMaxValue();

public int getMinValue();

public int getCurrentValue();

public MutableComponent format(int value);


default public int getValueStep(boolean stacks) { return stacks ? 64 : 1; }

}
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ protected void init() {

if (onAbove.getState() / valueStep == 0 && state / valueStep == 0)
return;

if (onAbove.getState() / valueStep <= state / valueStep) {
onAbove.setState((state + valueStep) / valueStep * valueStep);
onAbove.onChanged();
Expand Down Expand Up @@ -152,16 +152,13 @@ protected void renderWindow(GuiGraphics graphics, int mouseX, int mouseY, float
inputBg.render(graphics, x + 44, y + 21);
inputBg.render(graphics, x + 44, y + 21 + 24);

int valueStep = 1;
int valueStep = getValueStep();
boolean stacks = inStacks.getState() == 1;
if (typeOfCurrentTarget == ThresholdType.FLUID)
valueStep = 1000;

if (forItems) {
Component suffix =
inStacks.getState() == 0 ? CreateLang.translateDirect("schedule.condition.threshold.items")
: CreateLang.translateDirect("schedule.condition.threshold.stacks");
valueStep = inStacks.getState() == 0 ? 1 : 64;
graphics.drawString(font, suffix, x + 105, y + 28, 0xFFFFFFFF, true);
graphics.drawString(font, suffix, x + 105, y + 28 + 24, 0xFFFFFFFF, true);

Expand Down Expand Up @@ -328,12 +325,7 @@ private void updateInputBoxes() {

private int getValueStep() {
boolean stacks = inStacks.getState() == 1;
int valueStep = 1;
if (blockEntity.getTypeOfCurrentTarget() == ThresholdType.FLUID)
valueStep = 1000;
else if (stacks)
valueStep = 64;
return valueStep;
return blockEntity.getValueStep(stacks);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,9 @@ private static void genBlockTags(RegistrateTagsProvider<Block> provIn) {
TagGen.addOptional(prov.tag(AllBlockTags.ROOTS.tag), Mods.TF,
List.of("root", "liveroot_block", "mangrove_root"));

TagGen.addOptional(prov.tag(AllBlockTags.THRESHOLD_SWITCH_IGNORE_ITEMS.tag), Mods.MEK,
List.of("basic_fluid_tank", "advanced_fluid_tank", "elite_fluid_tank", "ultimate_fluid_tank"));

Comment on lines +168 to +170
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could this not be done from the json file if that contains the mod separately? That way it could be Open-Close by letting people edit the JSON file which should be possible to target with datapacks, or not?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This method is called as part of the process of generating the datapack json files, and shouldn't run anywhere else.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, so it is the other way around. The JSON file was generated from this.

// VALIDATE

for (AllBlockTags tag : AllBlockTags.values()) {
Expand Down