Skip to content

Commit

Permalink
Implement matching blocks to a BeaconData instance
Browse files Browse the repository at this point in the history
  • Loading branch information
Joel-Paul committed May 18, 2024
1 parent c5a9be6 commit 6f91c3c
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
17 changes: 16 additions & 1 deletion src/main/java/issame/material_beacons/DatapackLoader.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,14 @@
import com.google.gson.Gson;
import issame.material_beacons.config.BeaconConfig;
import issame.material_beacons.config.BeaconData;
import issame.material_beacons.config.BlockOrTag;
import net.fabricmc.fabric.api.resource.ResourceManagerHelper;
import net.fabricmc.fabric.api.resource.SimpleSynchronousResourceReloadListener;
import net.minecraft.block.Block;
import net.minecraft.resource.ResourceManager;
import net.minecraft.resource.ResourceType;
import net.minecraft.util.Identifier;
import org.jetbrains.annotations.Nullable;

import java.io.IOException;
import java.io.InputStream;
Expand Down Expand Up @@ -43,7 +46,19 @@ public void reload(ResourceManager manager) {
});
}

public static HashSet<BeaconData> getBeaconConfigs() {
public static HashSet<BeaconData> getBeaconData() {
return beaconData;
}

@Nullable
public static BeaconData findMatchingData(Block block) {
for (BeaconData data : beaconData) {
for (BlockOrTag blockOrTag : data.getBase()) {
if (blockOrTag.has(block)) {
return data;
}
}
}
return null;
}
}
12 changes: 10 additions & 2 deletions src/main/java/issame/material_beacons/config/BlockOrTag.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,20 @@ public boolean isTag() {
return tag != null;
}

public boolean has(Block other) {
if (isBlock()) {
return other == block;
} else {
return other.getRegistryEntry().isIn(tag);
}
}

@Override
public String toString() {
if (isBlock()) {
return "Block: " + block;
return block.toString();
} else {
return "Tag: " + tag;
return tag.toString();
}
}
}

0 comments on commit 6f91c3c

Please sign in to comment.