Skip to content

Commit

Permalink
fix a few bugs!
Browse files Browse the repository at this point in the history
  • Loading branch information
LemmaEOF committed Feb 16, 2020
1 parent 22a7940 commit 1d830e8
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 7 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ yarn_build=3
loader_version=0.7.6+build.179

# Mod Properties
mod_version = 1.0.0
mod_version = 1.0.1
maven_group = io.github.alloffabric
archives_base_name = olbm

Expand Down
4 changes: 2 additions & 2 deletions src/main/java/io/github/alloffabric/olbm/OLBData.java
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,8 @@ private static void loadEntries(String from, JsonObject json) {
List<String> keys = new ArrayList<>(bagObj.keySet());
Collections.sort(keys);
for (String key : keys) {
if (OLBM.LOOT_BAG_TYPES.containsId(new Identifier(key))) {
OLBM.logger.error("[OLBM] Table type named {} already exists, skipping it in {}", key, from);
if (OLBM.LOOT_BAG_TYPES.hasId(new Identifier(key))) {
OLBM.logger.error("[OLBM] Loot bag type named {} already exists, skipping it in {}", key, from);
continue;
}
JsonElement elem = bagObj.get(key);
Expand Down
21 changes: 19 additions & 2 deletions src/main/java/io/github/alloffabric/olbm/OLBM.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import io.github.alloffabric.olbm.api.LootBagType;
import io.github.alloffabric.olbm.inventory.LootBagContainer;
import io.github.alloffabric.olbm.util.OLBRegistry;
import net.fabricmc.api.ModInitializer;
import net.fabricmc.fabric.api.client.itemgroup.FabricItemGroupBuilder;
import net.fabricmc.fabric.api.container.ContainerProviderRegistry;
Expand All @@ -17,16 +18,32 @@
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Random;

public class OLBM implements ModInitializer {
public static final String MODID = "olbm";

public static final Logger logger = LogManager.getLogger();

public static final Registry<LootBagType> LOOT_BAG_TYPES = new SimpleRegistry<>();
public static final OLBRegistry<LootBagType> LOOT_BAG_TYPES = new OLBRegistry<>();

public static final ItemGroup OLBM_GROUP = FabricItemGroupBuilder.build(new Identifier(MODID, "olbm_group"), () -> new ItemStack(Items.ENDER_CHEST));
public static final ItemGroup OLBM_GROUP = FabricItemGroupBuilder.build(new Identifier(MODID, "olbm_group"), () -> {
Random random = new Random();
List<Item> potential = new ArrayList<>();
for (LootBagType type : LOOT_BAG_TYPES) {
if (type.getBag() != Items.AIR) {
potential.add(type.getBag());
}
}
if (!potential.isEmpty()) {
return new ItemStack(potential.get(random.nextInt(potential.size())));
} else {
return new ItemStack(Items.ENDER_CHEST);
}
});

@Override
public void onInitialize() {
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/io/github/alloffabric/olbm/util/OLBRegistry.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package io.github.alloffabric.olbm.util;

import net.minecraft.util.Identifier;
import net.minecraft.util.registry.SimpleRegistry;

/**
* Exists *purely* so we have access to a `containsId()` method on the server. Thaaaaaanks, ProGuard.
*/
public class OLBRegistry<T> extends SimpleRegistry<T> {
public boolean hasId(Identifier id) {
return this.entries.containsKey(id);
}
}
3 changes: 2 additions & 1 deletion src/main/resources/assets/olbm/lang/en_us.json
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
{
"tooltip.olbm.source": "Powered by OLBM"
"tooltip.olbm.source": "Powered by OLBM",
"itemGroup.olbm.olbm_group": "Loot Bags"
}
6 changes: 5 additions & 1 deletion src/main/resources/fabric.mod.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,10 @@
"mixins.starter.json"
],
"depends": {
"fabricloader": ">=0.4.0"
"fabricloader": ">=0.4.0",
"fabric": "*",
"jankson": ">=2.0.0",
"staticdata": "*",
"artifice": "*"
}
}

0 comments on commit 1d830e8

Please sign in to comment.