This commit is contained in:
paulevsGitch 2020-12-27 22:45:11 +03:00
commit 71cae4850c
2 changed files with 24 additions and 10 deletions

View file

@ -1,19 +1,23 @@
package ru.betterend.config; package ru.betterend.config;
public class Configs { public class Configs {
public static final IdConfig ITEM_CONFIG = new IdConfig("items", (item, category) -> { public static final IdConfig ITEM_CONFIG = new IdConfig("items", (itemId, category) -> {
return new ConfigKey(item.getNamespace(), category, item.getPath()); return new ConfigKey(itemId.getNamespace(), category, itemId.getPath());
}); });
public static final IdConfig BLOCK_CONFIG = new IdConfig("blocks", (block, category) -> { public static final IdConfig BLOCK_CONFIG = new IdConfig("blocks", (blockId, category) -> {
return new ConfigKey(block.getNamespace(), category, block.getPath()); return new ConfigKey(blockId.getNamespace(), category, blockId.getPath());
}); });
public static final IdConfig BIOME_CONFIG = new IdConfig("biomes", (biome, entry) -> { public static final IdConfig BIOME_CONFIG = new IdConfig("biomes", (biomeId, entry) -> {
return new ConfigKey(biome.getNamespace(), biome.getPath(), entry); return new ConfigKey(biomeId.getNamespace(), biomeId.getPath(), entry);
});
public static final IdConfig ENTITY_CONFIG = new IdConfig("entities", (entityId, category) -> {
return new ConfigKey(entityId.getNamespace(), category, entityId.getPath());
}); });
public static void saveConfigs() { public static void saveConfigs() {
ITEM_CONFIG.saveChanges(); ITEM_CONFIG.saveChanges();
BLOCK_CONFIG.saveChanges(); BLOCK_CONFIG.saveChanges();
BIOME_CONFIG.saveChanges(); BIOME_CONFIG.saveChanges();
ENTITY_CONFIG.saveChanges();
} }
} }

View file

@ -9,8 +9,10 @@ import net.minecraft.entity.EntityType.EntityFactory;
import net.minecraft.entity.LivingEntity; import net.minecraft.entity.LivingEntity;
import net.minecraft.entity.SpawnGroup; import net.minecraft.entity.SpawnGroup;
import net.minecraft.entity.attribute.DefaultAttributeContainer.Builder; import net.minecraft.entity.attribute.DefaultAttributeContainer.Builder;
import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry; import net.minecraft.util.registry.Registry;
import ru.betterend.BetterEnd; import ru.betterend.BetterEnd;
import ru.betterend.config.Configs;
import ru.betterend.entity.EntityCubozoa; import ru.betterend.entity.EntityCubozoa;
import ru.betterend.entity.EntityDragonfly; import ru.betterend.entity.EntityDragonfly;
import ru.betterend.entity.EntityEndFish; import ru.betterend.entity.EntityEndFish;
@ -35,14 +37,22 @@ public class EndEntities {
} }
protected static <T extends Entity> EntityType<T> register(String name, SpawnGroup group, float width, float height, EntityFactory<T> entity) { protected static <T extends Entity> EntityType<T> register(String name, SpawnGroup group, float width, float height, EntityFactory<T> entity) {
EntityType<T> type = Registry.register(Registry.ENTITY_TYPE, BetterEnd.makeID(name), FabricEntityTypeBuilder.<T>create(group, entity).dimensions(EntityDimensions.fixed(width, height)).build()); Identifier id = BetterEnd.makeID(name);
EntityType<T> type = FabricEntityTypeBuilder.<T>create(group, entity).dimensions(EntityDimensions.fixed(width, height)).build();
if (Configs.ENTITY_CONFIG.getBoolean(id, "entities", true)) {
return Registry.register(Registry.ENTITY_TYPE, id, type);
}
return type; return type;
} }
private static <T extends LivingEntity> EntityType<T> register(String name, SpawnGroup group, float width, float height, EntityFactory<T> entity, Builder attributes, boolean fixedSize, int eggColor, int dotsColor) { private static <T extends LivingEntity> EntityType<T> register(String name, SpawnGroup group, float width, float height, EntityFactory<T> entity, Builder attributes, boolean fixedSize, int eggColor, int dotsColor) {
EntityType<T> type = Registry.register(Registry.ENTITY_TYPE, BetterEnd.makeID(name), FabricEntityTypeBuilder.<T>create(group, entity).dimensions(fixedSize ? EntityDimensions.fixed(width, height) : EntityDimensions.changing(width, height)).build()); Identifier id = BetterEnd.makeID(name);
FabricDefaultAttributeRegistry.register(type, attributes); EntityType<T> type = FabricEntityTypeBuilder.<T>create(group, entity).dimensions(fixedSize ? EntityDimensions.fixed(width, height) : EntityDimensions.changing(width, height)).build();
EndItems.registerEgg("spawn_egg_" + name, type, eggColor, dotsColor); if (Configs.ENTITY_CONFIG.getBoolean(id, "entities", true)) {
FabricDefaultAttributeRegistry.register(type, attributes);
EndItems.registerEgg("spawn_egg_" + name, type, eggColor, dotsColor);
return Registry.register(Registry.ENTITY_TYPE, BetterEnd.makeID(name), type);
}
return type; return type;
} }
} }