Skip to content

Commit

Permalink
Migrate conditional mining speed modifier and mob disguise to modules
Browse files Browse the repository at this point in the history
Need to consider if I should let modifier modules suggest a priority, as the setting of priorities feels a little arbitrary right now to anyone without a high understanding of the code, and most of the time its a single module that wants it
  • Loading branch information
KnightMiner committed Jun 13, 2023
1 parent c00a81a commit ae40120
Show file tree
Hide file tree
Showing 23 changed files with 384 additions and 85 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
{
"type": "tconstruct:mob_disguise",
"entity": "minecraft:blaze"
"type": "tconstruct:composable",
"level_display": "tconstruct:default",
"tooltip_display": "always",
"priority": 100,
"modules": [
{
"type": "tconstruct:mob_disguise",
"entity": "minecraft:blaze"
}
]
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
{
"type": "tconstruct:mob_disguise",
"entity": "minecraft:cave_spider"
"type": "tconstruct:composable",
"level_display": "tconstruct:default",
"tooltip_display": "always",
"priority": 100,
"modules": [
{
"type": "tconstruct:mob_disguise",
"entity": "minecraft:cave_spider"
}
]
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
{
"type": "tconstruct:mob_disguise",
"entity": "minecraft:creeper"
"type": "tconstruct:composable",
"level_display": "tconstruct:default",
"tooltip_display": "always",
"priority": 100,
"modules": [
{
"type": "tconstruct:mob_disguise",
"entity": "minecraft:creeper"
}
]
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
{
"type": "tconstruct:conditional_mining_speed",
"blocks": {
"type": "tconstruct:inverted",
"predicate": "tconstruct:requires_tool"
},
"require_effective": false,
"bonus": 0.5
"type": "tconstruct:composable",
"level_display": "tconstruct:default",
"tooltip_display": "always",
"priority": 125,
"modules": [
{
"type": "tconstruct:conditional_mining_speed",
"blocks": {
"type": "mantle:inverted",
"predicate": "mantle:requires_tool"
},
"require_effective": false,
"bonus": 0.5
}
]
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
{
"type": "tconstruct:mob_disguise",
"entity": "minecraft:drowned"
"type": "tconstruct:composable",
"level_display": "tconstruct:default",
"tooltip_display": "always",
"priority": 100,
"modules": [
{
"type": "tconstruct:mob_disguise",
"entity": "minecraft:drowned"
}
]
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
{
"type": "tconstruct:mob_disguise",
"entity": "minecraft:enderman"
"type": "tconstruct:composable",
"level_display": "tconstruct:default",
"tooltip_display": "always",
"priority": 100,
"modules": [
{
"type": "tconstruct:mob_disguise",
"entity": "minecraft:enderman"
}
]
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
{
"type": "tconstruct:mob_disguise",
"entity": "minecraft:husk"
"type": "tconstruct:composable",
"level_display": "tconstruct:default",
"tooltip_display": "always",
"priority": 100,
"modules": [
{
"type": "tconstruct:mob_disguise",
"entity": "minecraft:husk"
}
]
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
{
"type": "tconstruct:mob_disguise",
"entity": "minecraft:piglin_brute"
"type": "tconstruct:composable",
"level_display": "tconstruct:default",
"tooltip_display": "always",
"priority": 100,
"modules": [
{
"type": "tconstruct:mob_disguise",
"entity": "minecraft:piglin_brute"
}
]
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
{
"type": "tconstruct:mob_disguise",
"entity": "minecraft:piglin"
"type": "tconstruct:composable",
"level_display": "tconstruct:default",
"tooltip_display": "always",
"priority": 100,
"modules": [
{
"type": "tconstruct:mob_disguise",
"entity": "minecraft:piglin"
}
]
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
{
"type": "tconstruct:mob_disguise",
"entity": "minecraft:skeleton"
"type": "tconstruct:composable",
"level_display": "tconstruct:default",
"tooltip_display": "always",
"priority": 100,
"modules": [
{
"type": "tconstruct:mob_disguise",
"entity": "minecraft:skeleton"
}
]
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
{
"type": "tconstruct:mob_disguise",
"entity": "minecraft:spider"
"type": "tconstruct:composable",
"level_display": "tconstruct:default",
"tooltip_display": "always",
"priority": 100,
"modules": [
{
"type": "tconstruct:mob_disguise",
"entity": "minecraft:spider"
}
]
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
{
"type": "tconstruct:mob_disguise",
"entity": "minecraft:stray"
"type": "tconstruct:composable",
"level_display": "tconstruct:default",
"tooltip_display": "always",
"priority": 100,
"modules": [
{
"type": "tconstruct:mob_disguise",
"entity": "minecraft:stray"
}
]
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
{
"type": "tconstruct:mob_disguise",
"entity": "minecraft:wither_skeleton"
"type": "tconstruct:composable",
"level_display": "tconstruct:default",
"tooltip_display": "always",
"priority": 100,
"modules": [
{
"type": "tconstruct:mob_disguise",
"entity": "minecraft:wither_skeleton"
}
]
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
{
"type": "tconstruct:mob_disguise",
"entity": "minecraft:zombie"
"type": "tconstruct:composable",
"level_display": "tconstruct:default",
"tooltip_display": "always",
"priority": 100,
"modules": [
{
"type": "tconstruct:mob_disguise",
"entity": "minecraft:zombie"
}
]
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
{
"type": "tconstruct:mob_disguise",
"entity": "minecraft:zombified_piglin"
"type": "tconstruct:composable",
"level_display": "tconstruct:default",
"tooltip_display": "always",
"priority": 100,
"modules": [
{
"type": "tconstruct:mob_disguise",
"entity": "minecraft:zombified_piglin"
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package slimeknights.tconstruct.library.json.serializer;

import com.google.gson.JsonObject;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraftforge.registries.IForgeRegistry;
import net.minecraftforge.registries.IForgeRegistryEntry;
import slimeknights.mantle.data.GenericLoaderRegistry.IGenericLoader;
import slimeknights.mantle.data.GenericLoaderRegistry.IHaveLoader;
import slimeknights.mantle.util.JsonHelper;

import java.util.Objects;
import java.util.function.Function;

/**
* Serializer for an object with a registry entry parameter
* @param <O> Object type
* @param <V> Registry entry type
*/
public record GenericRegistryEntrySerializer<O extends IHaveLoader<?>,V extends IForgeRegistryEntry<V>>(
String key,
IForgeRegistry<V> registry,
Function<V,O> constructor,
Function<O,V> getter
) implements IGenericLoader<O> {

@Override
public O deserialize(JsonObject json) {
return constructor.apply(JsonHelper.getAsEntry(registry, json, key));
}

@Override
public void serialize(O object, JsonObject json) {
json.addProperty(key, Objects.requireNonNull(getter.apply(object).getRegistryName()).toString());
}

@Override
public O fromNetwork(FriendlyByteBuf buffer) {
return constructor.apply(buffer.readRegistryIdUnsafe(registry));
}

@Override
public void toNetwork(O object, FriendlyByteBuf buffer) {
buffer.writeRegistryIdUnsafe(registry, getter.apply(object));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,14 +16,19 @@
import slimeknights.tconstruct.library.json.predicate.block.BlockPredicate;
import slimeknights.tconstruct.library.modifiers.Modifier;
import slimeknights.tconstruct.library.modifiers.impl.IncrementalModifier;
import slimeknights.tconstruct.library.modifiers.modules.ConditionalMiningSpeedModule;
import slimeknights.tconstruct.library.tools.nbt.IToolStackView;
import slimeknights.tconstruct.library.tools.stat.ToolStats;
import slimeknights.tconstruct.library.utils.TooltipKey;

import javax.annotation.Nullable;
import java.util.List;

/** Modifier that conditionally boosts mining speed */
/**
* Modifier that conditionally boosts mining speed
* @deprecated use {@link ConditionalMiningSpeedModule}
*/
@Deprecated
@RequiredArgsConstructor
public class ConditionalMiningSpeedModifier extends IncrementalModifier {
private final IJsonPredicate<BlockState> predicate;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,28 @@

import com.google.common.collect.HashMultiset;
import com.google.common.collect.Multiset;
import com.google.gson.JsonObject;
import lombok.RequiredArgsConstructor;
import net.minecraft.network.FriendlyByteBuf;
import net.minecraft.world.entity.EntityType;
import net.minecraft.world.entity.EquipmentSlot.Type;
import net.minecraftforge.registries.ForgeRegistries;
import slimeknights.mantle.data.GenericLoaderRegistry.IGenericLoader;
import slimeknights.mantle.util.JsonHelper;
import slimeknights.tconstruct.TConstruct;
import slimeknights.tconstruct.library.json.serializer.GenericRegistryEntrySerializer;
import slimeknights.tconstruct.library.modifiers.Modifier;
import slimeknights.tconstruct.library.modifiers.impl.NoLevelsModifier;
import slimeknights.tconstruct.library.modifiers.modules.MobDisguiseModule;
import slimeknights.tconstruct.library.tools.capability.TinkerDataCapability.TinkerDataKey;
import slimeknights.tconstruct.library.tools.context.EquipmentChangeContext;
import slimeknights.tconstruct.library.tools.nbt.IToolStackView;

import java.util.Objects;

/** Modifier that makes the player less visible to a certain mob type */
/** @deprecated use {@link MobDisguiseModule} */
@Deprecated
@RequiredArgsConstructor
public class MobDisguiseModifier extends NoLevelsModifier {
/** Loader instance */
public static final IGenericLoader<MobDisguiseModifier> LOADER = new IGenericLoader<MobDisguiseModifier>() {
@Override
public MobDisguiseModifier deserialize(JsonObject json) {
return new MobDisguiseModifier(JsonHelper.getAsEntry(ForgeRegistries.ENTITIES, json, "entity"));
}

@Override
public void serialize(MobDisguiseModifier object, JsonObject json) {
json.addProperty("entity", Objects.requireNonNull(object.type.getRegistryName()).toString());
}

@Override
public MobDisguiseModifier fromNetwork(FriendlyByteBuf buffer) {
return new MobDisguiseModifier(buffer.readRegistryIdUnsafe(ForgeRegistries.ENTITIES));
}

@Override
public void toNetwork(MobDisguiseModifier object, FriendlyByteBuf buffer) {
buffer.writeRegistryIdUnsafe(ForgeRegistries.ENTITIES, object.type);
}
};
public static final TinkerDataKey<Multiset<EntityType<?>>> DISGUISES = TConstruct.createKey("mob_disguise");
public static final IGenericLoader<MobDisguiseModifier> LOADER = new GenericRegistryEntrySerializer<>("entity", ForgeRegistries.ENTITIES, MobDisguiseModifier::new, m -> m.type);
/** @deprecated use {@link MobDisguiseModule#DISGUISES} */
@Deprecated
public static final TinkerDataKey<Multiset<EntityType<?>>> DISGUISES = MobDisguiseModule.DISGUISES;

private final EntityType<?> type;

Expand Down

0 comments on commit ae40120

Please sign in to comment.