Skip to content

Commit

Permalink
partial migration of default blocks to data
Browse files Browse the repository at this point in the history
  • Loading branch information
Caltinor committed Nov 28, 2024
1 parent 9e4f6b7 commit 0646bb2
Show file tree
Hide file tree
Showing 74 changed files with 125 additions and 978 deletions.
6 changes: 6 additions & 0 deletions src/main/java/harmonised/pmmo/config/codecs/ObjectData.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.TagKey;
import net.minecraft.util.StringRepresentable;
import net.minecraft.world.item.Items;

Expand Down Expand Up @@ -302,6 +303,11 @@ public Builder addTag(String... id) {
this.tagValues.addAll(Arrays.asList(id));
return this;
}
public Builder addTag(TagKey<?>...id) {
var ids = Arrays.stream(id).map(key -> "#"+key.location()).toList();
this.tagValues.addAll(ids);
return this;
}
public Builder addReq(ReqType type, Map<String, Long> req) {
this.reqs.put(type, req);
return this;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
package harmonised.pmmo.setup.datagen.defaultpacks;

import harmonised.pmmo.api.enums.EventType;
import harmonised.pmmo.api.enums.ReqType;
import harmonised.pmmo.config.codecs.ObjectData;
import harmonised.pmmo.setup.datagen.PmmoDataProvider;
import harmonised.pmmo.util.RegistryUtil;
import net.minecraft.data.PackOutput;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.BlockTags;
import net.minecraft.tags.TagKey;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.neoforged.neoforge.common.Tags;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;

public class DefaultBlockConfigProvider extends PmmoDataProvider<ObjectData> {
Map<ResourceLocation, ObjectData.Builder> data = new HashMap<>();
public DefaultBlockConfigProvider(PackOutput gen) {
super(gen, "default", "pmmo/blocks", ObjectData.CODEC.codec());
}

@Override
protected void start() {
populateData();
data.forEach((id, builder) -> this.add(id, builder.end()));
}

private void populateData() {
miningBreak(Blocks.COAL_ORE, 25L, Tags.Blocks.ORES_COAL);
miningBreak(Blocks.DEEPSLATE_COAL_ORE, 50L);
miningBreak(Blocks.COPPER_ORE, 30L, Tags.Blocks.ORES_COPPER);
miningBreak(Blocks.DEEPSLATE_COPPER_ORE, 60L);
miningBreak(Blocks.IRON_ORE, 150L, Tags.Blocks.ORES_IRON);
miningBreak(Blocks.DEEPSLATE_IRON_ORE, 300L);
miningBreak(Blocks.GOLD_ORE, 200L, Tags.Blocks.ORES_GOLD);
miningBreak(Blocks.DEEPSLATE_GOLD_ORE, 400L);
miningBreak(Blocks.NETHER_GOLD_ORE, 400L);
miningBreak(Blocks.REDSTONE_ORE, 150L, Tags.Blocks.ORES_REDSTONE);
miningBreak(Blocks.DEEPSLATE_REDSTONE_ORE, 300L);
miningBreak(Blocks.DIAMOND_ORE, 750L, Tags.Blocks.ORES_DIAMOND);
miningBreak(Blocks.DEEPSLATE_DIAMOND_ORE, 750L);
miningBreak(Blocks.EMERALD_ORE, 400L, Tags.Blocks.ORES_EMERALD);
miningBreak(Blocks.DEEPSLATE_EMERALD_ORE, 10000L);
miningBreak(Blocks.LAPIS_ORE, 50L, Tags.Blocks.ORES_LAPIS);
miningBreak(Blocks.DEEPSLATE_LAPIS_ORE, 100L);
miningBreak(Blocks.NETHER_QUARTZ_ORE, 100L, Tags.Blocks.ORES_QUARTZ);
miningBreak(Blocks.ANCIENT_DEBRIS, 1500L);

tagGet(BlockTags.BASE_STONE_OVERWORLD)
.addTag(BlockTags.BASE_STONE_NETHER)
.addTag("polished_andesite", "polished_deepslate","polished_diorite","polished_granite",
"cobblestone", "cobbled_deepslate")
.addXpValues(EventType.BLOCK_BREAK, Map.of("mining", 10L));

tagGet(BlockTags.LOGS)
.addXpValues(EventType.BLOCK_BREAK, Map.of("woodcutting", 80L))
.addXpValues(EventType.BLOCK_PLACE, Map.of("building", 10L))
.addReq(ReqType.BREAK, Map.of("woodcutting", 0L));
tagGet(BlockTags.LEAVES)
.addXpValues(EventType.BLOCK_BREAK, Map.of("woodcutting", 11L))
.addReq(ReqType.BREAK, Map.of("woodcutting", 0L));
tagGet(BlockTags.PLANKS)
.addXpValues(EventType.BLOCK_BREAK, Map.of("woodcutting", 50L))
.addXpValues(EventType.BLOCK_PLACE, Map.of("building", 10L))
.addReq(ReqType.BREAK, Map.of("woodcutting", 0L))
.addReq(ReqType.PLACE, Map.of("woodcutting", 0L));
tagGet(BlockTags.SAPLINGS)
.addXpValues(EventType.GROW, Map.of("farming", 300L))
.addReq(ReqType.PLACE, Map.of("farming", 5L, "woodcutting", 10L));
}

private void miningBreak(Block block, long xp, TagKey<?>...tags) {
get(block)
.addXpValues(EventType.BLOCK_BREAK, Map.of("mining", xp))
.addTag(tags)
.addReq(ReqType.BREAK, Map.of("mining", 0L));
}
private ObjectData.Builder get(Block block) {
return data.computeIfAbsent(RegistryUtil.getId(block), i -> ObjectData.build());}

private ObjectData.Builder tagGet(TagKey<Block> tag) {
return data.computeIfAbsent(tag.location(), i -> ObjectData.build()).addTag(tag);
}

@Override
public String getName() {return "Project MMO Default Block Generator";}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.data.PackOutput;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.tags.TagKey;
import net.minecraft.world.effect.MobEffectInstance;
import net.minecraft.world.effect.MobEffects;
import net.minecraft.world.food.FoodProperties;
Expand All @@ -23,6 +24,7 @@
import net.minecraft.world.item.Items;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.Blocks;
import net.neoforged.neoforge.common.Tags;
import org.apache.commons.lang3.function.TriFunction;

import java.util.Arrays;
Expand All @@ -38,7 +40,7 @@
public class DefaultItemConfigProvider extends PmmoDataProvider<ObjectData> {
Map<ResourceLocation, ObjectData.Builder> data = new HashMap<>();
public DefaultItemConfigProvider(PackOutput gen) {
super(gen, "easy", "pmmo/items", ObjectData.CODEC.codec());
super(gen, "default", "pmmo/items", ObjectData.CODEC.codec());
}

@Override
Expand All @@ -59,6 +61,27 @@ private void populateData() {
get(Items.NETHER_QUARTZ_ORE).addTag("#c:ores/quartz").addXpValues(EventType.SMELT, Map.of("smithing", 100L));
get(Items.REDSTONE_ORE).addTag("#c:ores/redstone").addXpValues(EventType.SMELT, Map.of("smithing", 200L));

//BLOCK TOOLTIP PARITY SETTINGS
miningBreak(Blocks.COAL_ORE, 25L, Tags.Blocks.ORES_COAL);
miningBreak(Blocks.DEEPSLATE_COAL_ORE, 50L);
miningBreak(Blocks.COPPER_ORE, 30L, Tags.Blocks.ORES_COPPER);
miningBreak(Blocks.DEEPSLATE_COPPER_ORE, 60L);
miningBreak(Blocks.IRON_ORE, 150L, Tags.Blocks.ORES_IRON);
miningBreak(Blocks.DEEPSLATE_IRON_ORE, 300L);
miningBreak(Blocks.GOLD_ORE, 200L, Tags.Blocks.ORES_GOLD);
miningBreak(Blocks.DEEPSLATE_GOLD_ORE, 400L);
miningBreak(Blocks.NETHER_GOLD_ORE, 400L);
miningBreak(Blocks.REDSTONE_ORE, 150L, Tags.Blocks.ORES_REDSTONE);
miningBreak(Blocks.DEEPSLATE_REDSTONE_ORE, 300L);
miningBreak(Blocks.DIAMOND_ORE, 750L, Tags.Blocks.ORES_DIAMOND);
miningBreak(Blocks.DEEPSLATE_DIAMOND_ORE, 750L);
miningBreak(Blocks.EMERALD_ORE, 400L, Tags.Blocks.ORES_EMERALD);
miningBreak(Blocks.DEEPSLATE_EMERALD_ORE, 10000L);
miningBreak(Blocks.LAPIS_ORE, 50L, Tags.Blocks.ORES_LAPIS);
miningBreak(Blocks.DEEPSLATE_LAPIS_ORE, 100L);
miningBreak(Blocks.NETHER_QUARTZ_ORE, 100L, Tags.Blocks.ORES_QUARTZ);
miningBreak(Blocks.ANCIENT_DEBRIS, 1500L);

//====FOOD============
BuiltInRegistries.ITEM.stream()
.filter(item -> new ItemStack(item).getFoodProperties(null) != null)
Expand Down Expand Up @@ -659,9 +682,9 @@ private void populateData() {
.addNBTReq(ReqType.TOOL, swordList.apply("farming"));
}

protected void miningBreak(Block block, long amount, String...tags) {
var builder = get(block.asItem()).addXpValues(EventType.BLOCK_BREAK, Map.of("mining", amount));
for (String tag : tags) {builder.addTag(tag);}
protected void miningBreak(Block block, long amount, TagKey<Block>...tags) {
var tagStrings = Arrays.stream(tags).map(key -> "#"+key.location().toString()).toArray(String[]::new);
get(block.asItem()).addXpValues(EventType.BLOCK_BREAK, Map.of("mining", amount)).addTag(tagStrings);
}

protected LogicEntry.Criteria equalsCriteria(String skill, double value, ResourceLocation key) {
Expand Down Expand Up @@ -695,5 +718,5 @@ protected ObjectData.Builder toolReq(Item tool, long asTool, long asWeapon, Stri
}

@Override
public String getName() {return "Project MMO Easy Item Generator";}
public String getName() {return "Project MMO Default Item Generator";}
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading

0 comments on commit 0646bb2

Please sign in to comment.