Misc other tidying up

This commit is contained in:
Sollace 2020-04-25 13:32:33 +02:00
parent a36f6580bb
commit 54a4309825
30 changed files with 156 additions and 196 deletions

View file

@ -1,60 +1,30 @@
package com.minelittlepony.unicopia; package com.minelittlepony.unicopia;
import java.io.IOException; import java.util.HashSet;
import java.nio.file.Files; import java.util.Set;
import java.nio.file.Path;
import java.util.List;
import com.google.common.collect.Lists;
import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
import com.google.gson.annotations.Expose; import com.google.gson.annotations.Expose;
import com.google.gson.stream.JsonReader; import com.minelittlepony.common.util.GamePaths;
import com.google.gson.stream.JsonWriter; import com.minelittlepony.common.util.settings.JsonConfig;
public class Config { public class Config extends JsonConfig {
private static Config INSTANCE = new Config();
private static final Gson GSON = new GsonBuilder()
.excludeFieldsWithoutExposeAnnotation()
.setPrettyPrinting()
.create();
@Deprecated
public static Config getInstance() { public static Config getInstance() {
return INSTANCE; return Unicopia.getConfig();
} }
static void init(Path directory) { public Config() {
Path file = directory.resolve("unicopia.json"); super(GamePaths.getConfigDirectory().resolve("unicopia.json"));
try {
if (Files.exists(file)) {
try(JsonReader reader = new JsonReader(Files.newBufferedReader(file))) {
INSTANCE = GSON.fromJson(reader, Config.class);
}
}
} catch (IOException e) {
e.printStackTrace();
} finally {
if (INSTANCE == null) {
INSTANCE = new Config();
}
}
INSTANCE.file = file;
INSTANCE.save();
} }
private Path file;
@Expose(deserialize = false) @Expose(deserialize = false)
private final String speciesWhiteListComment = private final String speciesWhiteListComment =
"A whitelist of races permitted on the server. " + "A whitelist of races permitted on the server. " +
"Races added to this list can be used by anyone, whilst any ones left off are not permitted. " + "Races added to this list can be used by anyone, whilst any ones left off are not permitted. " +
"An empty list disables whitelisting entirely."; "An empty list disables whitelisting entirely.";
@Expose @Expose
private final List<Race> speciesWhiteList = Lists.newArrayList(); private final Set<Race> speciesWhiteList = new HashSet<>();
@Expose(deserialize = false) @Expose(deserialize = false)
private final String preferredRaceComment = private final String preferredRaceComment =
@ -71,7 +41,7 @@ public class Config {
@Expose @Expose
private boolean ignoreMineLP = false; private boolean ignoreMineLP = false;
public List<Race> getSpeciesWhiteList() { public Set<Race> getSpeciesWhiteList() {
return speciesWhiteList; return speciesWhiteList;
} }
@ -100,20 +70,4 @@ public class Config {
return preferredRace; return preferredRace;
} }
public void save() {
try {
Files.deleteIfExists(file);
} catch (IOException e1) {
e1.printStackTrace();
}
try (JsonWriter writer = new JsonWriter(Files.newBufferedWriter(file))) {
writer.setIndent(" ");
GSON.toJson(this, Config.class, writer);
} catch (IOException e) {
e.printStackTrace();
}
}
} }

View file

@ -26,6 +26,10 @@ public class InteractionManager {
return 0; return 0;
} }
public Race getPreferredRace() {
return Unicopia.getConfig().getPrefferedRace();
}
/** /**
* Side-independent method to create a new player. * Side-independent method to create a new player.
* *

View file

@ -2,6 +2,7 @@ package com.minelittlepony.unicopia;
import java.util.Arrays; import java.util.Arrays;
import java.util.Map; import java.util.Map;
import java.util.Set;
import java.util.function.Function; import java.util.function.Function;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -71,7 +72,11 @@ public enum Race {
return false; return false;
} }
return isDefault() || Config.getInstance().getSpeciesWhiteList().isEmpty() || Config.getInstance().getSpeciesWhiteList().contains(this); Set<Race> whitelist = Unicopia.getConfig().getSpeciesWhiteList();
return isDefault()
|| whitelist.isEmpty()
|| whitelist.contains(this);
} }
public Race validate(PlayerEntity sender) { public Race validate(PlayerEntity sender) {

View file

@ -21,7 +21,7 @@ public interface USounds {
SoundEvent RECORD_FUNK = register("record.funk"); SoundEvent RECORD_FUNK = register("record.funk");
static SoundEvent register(String name) { static SoundEvent register(String name) {
Identifier id = new Identifier(Unicopia.MODID, name); Identifier id = new Identifier("unicopia", name);
return Registry.register(Registry.SOUND_EVENT, id, new SoundEvent(id)); return Registry.register(Registry.SOUND_EVENT, id, new SoundEvent(id));
} }

View file

@ -6,8 +6,8 @@ import net.minecraft.tag.Tag;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
public interface UTags { public interface UTags {
Tag<Item> CURSED_ARTEFACTS = TagRegistry.item(new Identifier(Unicopia.MODID, "cursed_artefacts")); Tag<Item> CURSED_ARTEFACTS = TagRegistry.item(new Identifier("unicopia", "cursed_artefacts"));
Tag<Item> HAMMERPACE_IMMUNE = TagRegistry.item(new Identifier(Unicopia.MODID, "hammerspace_immune")); Tag<Item> HAMMERPACE_IMMUNE = TagRegistry.item(new Identifier("unicopia", "hammerspace_immune"));
static void bootstrap() { } static void bootstrap() { }
} }

View file

@ -7,7 +7,6 @@ import net.minecraft.resource.ResourceType;
import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger; import org.apache.logging.log4j.Logger;
import com.minelittlepony.common.util.GamePaths;
import com.minelittlepony.unicopia.ability.Abilities; import com.minelittlepony.unicopia.ability.Abilities;
import com.minelittlepony.unicopia.advancement.BOHDeathCriterion; import com.minelittlepony.unicopia.advancement.BOHDeathCriterion;
import com.minelittlepony.unicopia.block.UBlocks; import com.minelittlepony.unicopia.block.UBlocks;
@ -22,13 +21,24 @@ import com.minelittlepony.unicopia.network.Channel;
import com.minelittlepony.unicopia.structure.UStructures; import com.minelittlepony.unicopia.structure.UStructures;
public class Unicopia implements ModInitializer { public class Unicopia implements ModInitializer {
public static final String MODID = "unicopia";
public static final Logger LOGGER = LogManager.getLogger(); public static final Logger LOGGER = LogManager.getLogger();
private static Config CONFIG;
public static Config getConfig() {
if (CONFIG == null) {
CONFIG = new Config();
}
return CONFIG;
}
public Unicopia() {
getConfig();
}
@Override @Override
public void onInitialize() { public void onInitialize() {
Config.init(GamePaths.getConfigDirectory());
Channel.bootstrap(); Channel.bootstrap();
UTags.bootstrap(); UTags.bootstrap();
Commands.bootstrap(); Commands.bootstrap();
@ -41,6 +51,6 @@ public class Unicopia implements ModInitializer {
CriterionsRegistry.register(BOHDeathCriterion.INSTANCE); CriterionsRegistry.register(BOHDeathCriterion.INSTANCE);
ResourceManagerHelper.get(ResourceType.SERVER_DATA).registerReloadListener(Pages.instance()); ResourceManagerHelper.get(ResourceType.SERVER_DATA).registerReloadListener(Pages.instance());
ResourceManagerHelper.get(ResourceType.CLIENT_RESOURCES).registerReloadListener(AffineIngredients.instance()); ResourceManagerHelper.get(ResourceType.CLIENT_RESOURCES).registerReloadListener(AffineIngredients.getInstance());
} }
} }

View file

@ -1,7 +1,6 @@
package com.minelittlepony.unicopia.block; package com.minelittlepony.unicopia.block;
import com.minelittlepony.unicopia.TreeType; import com.minelittlepony.unicopia.TreeType;
import com.minelittlepony.unicopia.Unicopia;
import com.minelittlepony.unicopia.gas.CloudAnvilBlock; import com.minelittlepony.unicopia.gas.CloudAnvilBlock;
import com.minelittlepony.unicopia.gas.CloudBlock; import com.minelittlepony.unicopia.gas.CloudBlock;
import com.minelittlepony.unicopia.gas.CloudDoorBlock; import com.minelittlepony.unicopia.gas.CloudDoorBlock;
@ -72,7 +71,7 @@ public interface UBlocks {
static <T extends Block> T register(T block, String name) { static <T extends Block> T register(T block, String name) {
return Registry.BLOCK.add(new Identifier(Unicopia.MODID, name), block); return Registry.BLOCK.add(new Identifier("unicopia", name), block);
} }
static void bootstrap() { } static void bootstrap() { }

View file

@ -0,0 +1,60 @@
package com.minelittlepony.unicopia.client;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import com.minelittlepony.unicopia.InteractionManager;
import com.minelittlepony.unicopia.Race;
import com.minelittlepony.unicopia.Unicopia;
import com.minelittlepony.unicopia.entity.player.Pony;
import com.minelittlepony.unicopia.util.dummy.DummyClientPlayerEntity;
import com.mojang.authlib.GameProfile;
import net.minecraft.client.MinecraftClient;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
public class ClientInteractionManager extends InteractionManager {
@Override
@Nonnull
public PlayerEntity createPlayer(Entity observer, GameProfile profile) {
if (observer.world instanceof ClientWorld) {
return new DummyClientPlayerEntity((ClientWorld)observer.world, profile);
}
return super.createPlayer(observer, profile);
}
@Override
public boolean isClientPlayer(@Nullable PlayerEntity player) {
if (MinecraftClient.getInstance().player == player) {
return true;
}
if (MinecraftClient.getInstance().player == null || player == null) {
return false;
}
return Pony.equal(MinecraftClient.getInstance().player, player);
}
@Override
public Race getPreferredRace() {
if (!Unicopia.getConfig().ignoresMineLittlePony()
&& MinecraftClient.getInstance().player != null) {
Race race = MineLPConnector.getPlayerPonyRace();
if (!race.isDefault()) {
return race;
}
}
return Unicopia.getConfig().getPrefferedRace();
}
@Override
public int getViewMode() {
return MinecraftClient.getInstance().options.perspective;
}
}

View file

@ -4,7 +4,6 @@ import java.util.HashSet;
import java.util.Set; import java.util.Set;
import com.minelittlepony.unicopia.KeyBind; import com.minelittlepony.unicopia.KeyBind;
import com.minelittlepony.unicopia.Unicopia;
import com.minelittlepony.unicopia.ability.Abilities; import com.minelittlepony.unicopia.ability.Abilities;
import com.minelittlepony.unicopia.entity.player.Pony; import com.minelittlepony.unicopia.entity.player.Pony;
@ -15,7 +14,6 @@ import net.minecraft.client.options.KeyBinding;
import net.minecraft.client.util.InputUtil; import net.minecraft.client.util.InputUtil;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
class KeyBindingsHandler { class KeyBindingsHandler {
private final MinecraftClient client = MinecraftClient.getInstance(); private final MinecraftClient client = MinecraftClient.getInstance();
@ -27,7 +25,7 @@ class KeyBindingsHandler {
public void addKeybind(KeyBind p) { public void addKeybind(KeyBind p) {
KeyBindingRegistry.INSTANCE.addCategory(p.getKeyCategory()); KeyBindingRegistry.INSTANCE.addCategory(p.getKeyCategory());
FabricKeyBinding b = FabricKeyBinding.Builder.create(new Identifier(Unicopia.MODID, p.getKeyName()), InputUtil.Type.KEYSYM, p.getKeyCode(), p.getKeyCategory()).build(); FabricKeyBinding b = FabricKeyBinding.Builder.create(new Identifier("unicopia", p.getKeyName()), InputUtil.Type.KEYSYM, p.getKeyCode(), p.getKeyCategory()).build();
KeyBindingRegistry.INSTANCE.register(b); KeyBindingRegistry.INSTANCE.register(b);
bindings.add(b); bindings.add(b);

View file

@ -2,25 +2,20 @@ package com.minelittlepony.unicopia.client;
import static com.minelittlepony.unicopia.EquinePredicates.MAGI; import static com.minelittlepony.unicopia.EquinePredicates.MAGI;
import javax.annotation.Nonnull;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import com.minelittlepony.common.event.ClientReadyCallback; import com.minelittlepony.common.event.ClientReadyCallback;
import com.minelittlepony.unicopia.Config;
import com.minelittlepony.unicopia.InteractionManager; import com.minelittlepony.unicopia.InteractionManager;
import com.minelittlepony.unicopia.Race; import com.minelittlepony.unicopia.Race;
import com.minelittlepony.unicopia.ability.Abilities; import com.minelittlepony.unicopia.ability.Abilities;
import com.minelittlepony.unicopia.block.UBlocks; import com.minelittlepony.unicopia.block.UBlocks;
import com.minelittlepony.unicopia.container.SpellbookResultSlot; import com.minelittlepony.unicopia.container.SpellbookResultSlot;
import com.minelittlepony.unicopia.ducks.Colourful; import com.minelittlepony.unicopia.ducks.Colourful;
import com.minelittlepony.unicopia.entity.player.Pony;
import com.minelittlepony.unicopia.item.UItems; import com.minelittlepony.unicopia.item.UItems;
import com.minelittlepony.unicopia.magic.spell.SpellRegistry; import com.minelittlepony.unicopia.magic.spell.SpellRegistry;
import com.minelittlepony.unicopia.mixin.client.DefaultTexturesRegistry; import com.minelittlepony.unicopia.mixin.client.DefaultTexturesRegistry;
import com.minelittlepony.unicopia.network.Channel; import com.minelittlepony.unicopia.network.Channel;
import com.minelittlepony.unicopia.network.MsgRequestCapabilities; import com.minelittlepony.unicopia.network.MsgRequestCapabilities;
import com.minelittlepony.unicopia.util.dummy.DummyClientPlayerEntity;
import com.mojang.authlib.GameProfile;
import net.fabricmc.api.ClientModInitializer; import net.fabricmc.api.ClientModInitializer;
import net.fabricmc.fabric.api.client.rendering.v1.ColorProviderRegistry; import net.fabricmc.fabric.api.client.rendering.v1.ColorProviderRegistry;
import net.fabricmc.fabric.api.event.client.ClientTickCallback; import net.fabricmc.fabric.api.event.client.ClientTickCallback;
@ -31,31 +26,21 @@ import net.minecraft.client.color.world.BiomeColors;
import net.minecraft.client.color.world.GrassColors; import net.minecraft.client.color.world.GrassColors;
import net.minecraft.client.texture.SpriteAtlasTexture; import net.minecraft.client.texture.SpriteAtlasTexture;
import net.minecraft.client.util.SpriteIdentifier; import net.minecraft.client.util.SpriteIdentifier;
import net.minecraft.client.world.ClientWorld;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity; import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.BlockItem; import net.minecraft.item.BlockItem;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.BlockRenderView; import net.minecraft.world.BlockRenderView;
public class UnicopiaClient extends InteractionManager implements ClientModInitializer { public class UnicopiaClient implements ClientModInitializer {
private final KeyBindingsHandler keyboard = new KeyBindingsHandler(); private final KeyBindingsHandler keyboard = new KeyBindingsHandler();
/** private Race lastPreferredRace = InteractionManager.instance().getPreferredRace();
* The race preferred by the client - as determined by mine little pony.
* Human if minelp was not installed.
*
* This is not neccessarily the _actual_ race used for the player,
* as the server may not allow certain race types, or the player may override
* this option in-game themselves.
*/
private static Race clientPlayerRace = getclientPlayerRace();
@Override @Override
public void onInitializeClient() { public void onInitializeClient() {
clientPlayerRace = getclientPlayerRace(); lastPreferredRace = InteractionManager.instance().getPreferredRace();
InteractionManager.INSTANCE = this; InteractionManager.INSTANCE = new ClientInteractionManager();
URenderers.bootstrap(); URenderers.bootstrap();
@ -80,58 +65,18 @@ public class UnicopiaClient extends InteractionManager implements ClientModIniti
PlayerEntity player = client.player; PlayerEntity player = client.player;
if (player != null && !player.removed) { if (player != null && !player.removed) {
Race newRace = getclientPlayerRace(); Race newRace = InteractionManager.instance().getPreferredRace();
if (newRace != clientPlayerRace) { if (newRace != lastPreferredRace) {
clientPlayerRace = newRace; lastPreferredRace = newRace;
Channel.REQUEST_CAPABILITIES.send(new MsgRequestCapabilities(player, clientPlayerRace)); Channel.REQUEST_CAPABILITIES.send(new MsgRequestCapabilities(lastPreferredRace));
} }
} }
keyboard.onKeyInput(); keyboard.onKeyInput();
} }
@Override
@Nonnull
public PlayerEntity createPlayer(Entity observer, GameProfile profile) {
if (observer.world instanceof ClientWorld) {
return new DummyClientPlayerEntity((ClientWorld)observer.world, profile);
}
return super.createPlayer(observer, profile);
}
@Override
public boolean isClientPlayer(@Nullable PlayerEntity player) {
if (MinecraftClient.getInstance().player == player) {
return true;
}
if (MinecraftClient.getInstance().player == null || player == null) {
return false;
}
return Pony.equal(MinecraftClient.getInstance().player, player);
}
@Override
public int getViewMode() {
return MinecraftClient.getInstance().options.perspective;
}
private static Race getclientPlayerRace() {
if (!Config.getInstance().ignoresMineLittlePony()
&& MinecraftClient.getInstance().player != null) {
Race race = MineLPConnector.getPlayerPonyRace();
if (!race.isDefault()) {
return race;
}
}
return Config.getInstance().getPrefferedRace();
}
private static int getLeavesColor(BlockState state, @Nullable BlockRenderView world, @Nullable BlockPos pos, int tint) { private static int getLeavesColor(BlockState state, @Nullable BlockRenderView world, @Nullable BlockPos pos, int tint) {
Block block = state.getBlock(); Block block = state.getBlock();

View file

@ -56,7 +56,7 @@ public class MagicParticle extends SpriteBillboardParticle {
@Override @Override
public ParticleTextureSheet getType() { public ParticleTextureSheet getType() {
return ParticleTextureSheet.PARTICLE_SHEET_OPAQUE; return ParticleTextureSheet.TERRAIN_SHEET;
} }
@Override @Override

View file

@ -1,7 +1,6 @@
package com.minelittlepony.unicopia.client.render; package com.minelittlepony.unicopia.client.render;
import com.minelittlepony.unicopia.InteractionManager; import com.minelittlepony.unicopia.InteractionManager;
import com.minelittlepony.unicopia.Unicopia;
import com.minelittlepony.unicopia.client.render.model.CuccoonEntityModel; import com.minelittlepony.unicopia.client.render.model.CuccoonEntityModel;
import com.minelittlepony.unicopia.entity.CuccoonEntity; import com.minelittlepony.unicopia.entity.CuccoonEntity;
import com.mojang.blaze3d.systems.RenderSystem; import com.mojang.blaze3d.systems.RenderSystem;
@ -17,7 +16,7 @@ import net.minecraft.util.Identifier;
public class CuccoonEntityRenderer extends LivingEntityRenderer<CuccoonEntity, CuccoonEntityModel> { public class CuccoonEntityRenderer extends LivingEntityRenderer<CuccoonEntity, CuccoonEntityModel> {
private static final Identifier TEXTURE = new Identifier(Unicopia.MODID, "textures/entity/cuccoon.png"); private static final Identifier TEXTURE = new Identifier("unicopia", "textures/entity/cuccoon.png");
public CuccoonEntityRenderer(EntityRenderDispatcher manager, EntityRendererRegistry.Context context) { public CuccoonEntityRenderer(EntityRenderDispatcher manager, EntityRendererRegistry.Context context) {
super(manager, new CuccoonEntityModel(), 1); super(manager, new CuccoonEntityModel(), 1);

View file

@ -1,6 +1,5 @@
package com.minelittlepony.unicopia.client.render; package com.minelittlepony.unicopia.client.render;
import com.minelittlepony.unicopia.Unicopia;
import com.minelittlepony.unicopia.entity.SpearEntity; import com.minelittlepony.unicopia.entity.SpearEntity;
import net.fabricmc.fabric.api.client.rendereregistry.v1.EntityRendererRegistry; import net.fabricmc.fabric.api.client.rendereregistry.v1.EntityRendererRegistry;
@ -9,7 +8,7 @@ import net.minecraft.client.render.entity.ProjectileEntityRenderer;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
public class SpearEntityRenderer extends ProjectileEntityRenderer<SpearEntity> { public class SpearEntityRenderer extends ProjectileEntityRenderer<SpearEntity> {
public static final Identifier TEXTURE = new Identifier(Unicopia.MODID, "textures/entity/projectiles/spear.png"); public static final Identifier TEXTURE = new Identifier("unicopia", "textures/entity/projectiles/spear.png");
public SpearEntityRenderer(EntityRenderDispatcher manager, EntityRendererRegistry.Context context) { public SpearEntityRenderer(EntityRenderDispatcher manager, EntityRendererRegistry.Context context) {
super(manager); super(manager);

View file

@ -2,8 +2,8 @@ package com.minelittlepony.unicopia.command;
import java.util.function.Function; import java.util.function.Function;
import com.minelittlepony.unicopia.Config;
import com.minelittlepony.unicopia.Race; import com.minelittlepony.unicopia.Race;
import com.minelittlepony.unicopia.Unicopia;
import com.mojang.brigadier.CommandDispatcher; import com.mojang.brigadier.CommandDispatcher;
import com.mojang.brigadier.builder.LiteralArgumentBuilder; import com.mojang.brigadier.builder.LiteralArgumentBuilder;
@ -22,9 +22,9 @@ class RacelistCommand {
builder.then(CommandManager.literal("allow") builder.then(CommandManager.literal("allow")
.then(CommandManager.argument("race", new RaceArgument()) .then(CommandManager.argument("race", new RaceArgument())
.executes(context -> toggle(context.getSource(), context.getSource().getPlayer(), context.getArgument("race", Race.class), "allowed", race -> { .executes(context -> toggle(context.getSource(), context.getSource().getPlayer(), context.getArgument("race", Race.class), "allowed", race -> {
boolean result = Config.getInstance().getSpeciesWhiteList().remove(race); boolean result = Unicopia.getConfig().getSpeciesWhiteList().remove(race);
Config.getInstance().save(); Unicopia.getConfig().save();
return result; return result;
})) }))
@ -32,9 +32,9 @@ class RacelistCommand {
builder.then(CommandManager.literal("disallow") builder.then(CommandManager.literal("disallow")
.then(CommandManager.argument("race", new RaceArgument()) .then(CommandManager.argument("race", new RaceArgument())
.executes(context -> toggle(context.getSource(), context.getSource().getPlayer(), context.getArgument("race", Race.class), "disallowed", race -> { .executes(context -> toggle(context.getSource(), context.getSource().getPlayer(), context.getArgument("race", Race.class), "disallowed", race -> {
boolean result = Config.getInstance().getSpeciesWhiteList().add(race); boolean result = Unicopia.getConfig().getSpeciesWhiteList().add(race);
Config.getInstance().save(); Unicopia.getConfig().save();
return result; return result;
})) }))

View file

@ -17,7 +17,7 @@ import net.minecraft.util.DefaultedList;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
public class SpellbookResultSlot extends SpellBookContainer.SpellbookSlot { public class SpellbookResultSlot extends SpellBookContainer.SpellbookSlot {
public static final Identifier EMPTY_GEM_SLOT = new Identifier("unicopia", "empty_slot_gem"); public static final Identifier EMPTY_GEM_SLOT = new Identifier("unicopia", "item/empty_gem_slot");
private final Pony player; private final Pony player;
private final SpellBookInventory craftMatrix; private final SpellBookInventory craftMatrix;

View file

@ -1,17 +1,20 @@
package com.minelittlepony.unicopia.container; package com.minelittlepony.unicopia.container;
import com.minelittlepony.unicopia.Unicopia; import net.fabricmc.fabric.api.container.ContainerFactory;
import net.fabricmc.fabric.api.container.ContainerProviderRegistry; import net.fabricmc.fabric.api.container.ContainerProviderRegistry;
import net.minecraft.container.Container;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
public interface UContainers { public interface UContainers {
Identifier BAG_OF_HOLDING = new Identifier(Unicopia.MODID, "bag_of_holding"); Identifier BAG_OF_HOLDING = register("bag_of_holding", BagOfHoldingContainer::new);
Identifier SPELL_BOOK = new Identifier(Unicopia.MODID, "spell_book"); Identifier SPELL_BOOK = register("spell_book", SpellBookContainer::new);
static void bootstrap() { static Identifier register(String name, ContainerFactory<Container> factory) {
ContainerProviderRegistry.INSTANCE.registerFactory(BAG_OF_HOLDING, BagOfHoldingContainer::new); Identifier id = new Identifier("unicopia", name);
ContainerProviderRegistry.INSTANCE.registerFactory(SPELL_BOOK, SpellBookContainer::new); ContainerProviderRegistry.INSTANCE.registerFactory(BAG_OF_HOLDING, factory);
return id;
} }
static void bootstrap() { }
} }

View file

@ -13,8 +13,6 @@ import com.google.common.collect.Maps;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.GsonBuilder; import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.minelittlepony.unicopia.Unicopia;
import net.fabricmc.fabric.api.resource.IdentifiableResourceReloadListener; import net.fabricmc.fabric.api.resource.IdentifiableResourceReloadListener;
import net.minecraft.resource.JsonDataLoader; import net.minecraft.resource.JsonDataLoader;
import net.minecraft.resource.ResourceManager; import net.minecraft.resource.ResourceManager;
@ -23,7 +21,7 @@ import net.minecraft.util.Util;
import net.minecraft.util.profiler.Profiler; import net.minecraft.util.profiler.Profiler;
public class Pages extends JsonDataLoader implements IdentifiableResourceReloadListener { public class Pages extends JsonDataLoader implements IdentifiableResourceReloadListener {
private static final Identifier ID = new Identifier(Unicopia.MODID, "pages"); private static final Identifier ID = new Identifier("unicopia", "pages");
private static final Gson GSON = new GsonBuilder() private static final Gson GSON = new GsonBuilder()
.setPrettyPrinting() .setPrettyPrinting()
.disableHtmlEscaping() .disableHtmlEscaping()

View file

@ -37,17 +37,17 @@ class AffineIngredient implements SpellIngredient {
@Override @Override
public ItemStack getStack() { public ItemStack getStack() {
return AffineIngredients.instance().getIngredient(res).getStack(); return AffineIngredients.getInstance().getIngredient(res).getStack();
} }
@Override @Override
public Stream<ItemStack> getStacks() { public Stream<ItemStack> getStacks() {
return AffineIngredients.instance().getIngredient(res).getStacks(); return AffineIngredients.getInstance().getIngredient(res).getStacks();
} }
@Override @Override
public boolean matches(ItemStack other, int materialMult) { public boolean matches(ItemStack other, int materialMult) {
return AffineIngredients.instance().getIngredient(res).matches(other, materialMult); return AffineIngredients.getInstance().getIngredient(res).matches(other, materialMult);
} }
@Nonnull @Nonnull

View file

@ -5,8 +5,6 @@ import com.google.common.collect.Maps;
import com.google.gson.Gson; import com.google.gson.Gson;
import com.google.gson.GsonBuilder; import com.google.gson.GsonBuilder;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.minelittlepony.unicopia.Unicopia;
import net.fabricmc.fabric.api.resource.IdentifiableResourceReloadListener; import net.fabricmc.fabric.api.resource.IdentifiableResourceReloadListener;
import net.minecraft.resource.JsonDataLoader; import net.minecraft.resource.JsonDataLoader;
import net.minecraft.resource.ResourceManager; import net.minecraft.resource.ResourceManager;
@ -14,16 +12,16 @@ import net.minecraft.util.Identifier;
import net.minecraft.util.profiler.Profiler; import net.minecraft.util.profiler.Profiler;
public class AffineIngredients extends JsonDataLoader implements IdentifiableResourceReloadListener { public class AffineIngredients extends JsonDataLoader implements IdentifiableResourceReloadListener {
private static final Identifier ID = new Identifier(Unicopia.MODID, "ingredients"); private static final Identifier ID = new Identifier("unicopia", "ingredients");
private static final Gson GSON = new GsonBuilder() private static final Gson GSON = new GsonBuilder()
.setPrettyPrinting() .setPrettyPrinting()
.disableHtmlEscaping() .disableHtmlEscaping()
.create(); .create();
private static final AffineIngredients instance = new AffineIngredients(); private static final AffineIngredients INSTANCE = new AffineIngredients();
public static AffineIngredients instance() { public static AffineIngredients getInstance() {
return instance; return INSTANCE;
} }
private final Map<Identifier, SpellIngredient> storedIngredients = Maps.newHashMap(); private final Map<Identifier, SpellIngredient> storedIngredients = Maps.newHashMap();

View file

@ -4,8 +4,6 @@ import java.util.Random;
import javax.annotation.Nullable; import javax.annotation.Nullable;
import com.minelittlepony.unicopia.Unicopia;
import net.minecraft.block.BlockState; import net.minecraft.block.BlockState;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityCategory; import net.minecraft.entity.EntityCategory;
@ -227,7 +225,7 @@ public class ButterflyEntity extends AmbientEntity {
WHITE_MONARCH, WHITE_MONARCH,
BRIMSTONE; BRIMSTONE;
private final Identifier skin = new Identifier(Unicopia.MODID, "textures/entity/butterfly/" + name().toLowerCase() + ".png"); private final Identifier skin = new Identifier("unicopia", "textures/entity/butterfly/" + name().toLowerCase() + ".png");
public Identifier getSkin() { public Identifier getSkin() {
return skin; return skin;

View file

@ -2,8 +2,6 @@ package com.minelittlepony.unicopia.entity;
import java.util.List; import java.util.List;
import com.minelittlepony.unicopia.Unicopia;
import net.fabricmc.fabric.api.entity.FabricEntityTypeBuilder; import net.fabricmc.fabric.api.entity.FabricEntityTypeBuilder;
import net.minecraft.entity.Entity; import net.minecraft.entity.Entity;
import net.minecraft.entity.EntityCategory; import net.minecraft.entity.EntityCategory;
@ -37,7 +35,7 @@ public interface UEntities {
EntityType<SpearEntity> THROWN_SPEAR = register("thrown_spear", FabricEntityTypeBuilder.<SpearEntity>create(EntityCategory.MISC, SpearEntity::new).trackable(100, 10)); EntityType<SpearEntity> THROWN_SPEAR = register("thrown_spear", FabricEntityTypeBuilder.<SpearEntity>create(EntityCategory.MISC, SpearEntity::new).trackable(100, 10));
static <T extends Entity> EntityType<T> register(String name, FabricEntityTypeBuilder<T> builder) { static <T extends Entity> EntityType<T> register(String name, FabricEntityTypeBuilder<T> builder) {
return Registry.register(Registry.ENTITY_TYPE, new Identifier(Unicopia.MODID, name), builder.build()); return Registry.register(Registry.ENTITY_TYPE, new Identifier("unicopia", name), builder.build());
} }
static void bootstrap() { static void bootstrap() {

View file

@ -1,6 +1,5 @@
package com.minelittlepony.unicopia.item; package com.minelittlepony.unicopia.item;
import com.minelittlepony.unicopia.Unicopia;
import com.minelittlepony.unicopia.util.CustomStatusEffect; import com.minelittlepony.unicopia.util.CustomStatusEffect;
import com.minelittlepony.unicopia.util.MagicalDamageSource; import com.minelittlepony.unicopia.util.MagicalDamageSource;
@ -12,7 +11,7 @@ import net.minecraft.util.Identifier;
public interface UEffects { public interface UEffects {
StatusEffect FOOD_POISONING = new CustomStatusEffect(new Identifier(Unicopia.MODID, "food_poisoning"), StatusEffectType.BENEFICIAL, 3484199) StatusEffect FOOD_POISONING = new CustomStatusEffect(new Identifier("unicopia", "food_poisoning"), StatusEffectType.BENEFICIAL, 3484199)
.setSilent() .setSilent()
.direct((p, e, i) -> { .direct((p, e, i) -> {
StatusEffectInstance nausea = e.getStatusEffect(StatusEffects.NAUSEA); StatusEffectInstance nausea = e.getStatusEffect(StatusEffects.NAUSEA);

View file

@ -3,7 +3,6 @@ package com.minelittlepony.unicopia.item;
import static com.minelittlepony.unicopia.EquinePredicates.*; import static com.minelittlepony.unicopia.EquinePredicates.*;
import com.minelittlepony.unicopia.USounds; import com.minelittlepony.unicopia.USounds;
import com.minelittlepony.unicopia.Unicopia;
import com.minelittlepony.unicopia.block.UBlocks; import com.minelittlepony.unicopia.block.UBlocks;
import com.minelittlepony.unicopia.entity.UEntities; import com.minelittlepony.unicopia.entity.UEntities;
import com.minelittlepony.unicopia.magic.spell.ScorchSpell; import com.minelittlepony.unicopia.magic.spell.ScorchSpell;
@ -71,7 +70,7 @@ public interface UItems {
Item SLIME_DROP = register(new BlockItem(UBlocks.SLIME_DROP, new Item.Settings().group(ItemGroup.MATERIALS)), "slime_drop"); Item SLIME_DROP = register(new BlockItem(UBlocks.SLIME_DROP, new Item.Settings().group(ItemGroup.MATERIALS)), "slime_drop");
Item SLIME_LAYER = register(new BlockItem(UBlocks.SLIME_LAYER, new Item.Settings().group(ItemGroup.DECORATIONS)), "slime_layer"); Item SLIME_LAYER = register(new BlockItem(UBlocks.SLIME_LAYER, new Item.Settings().group(ItemGroup.DECORATIONS)), "slime_layer");
Item MISTED_DOOR = register(new TallBlockItem(UBlocks.MISTED_GLASS_DOOR, new Item.Settings().group(ItemGroup.REDSTONE)), "misted_door"); Item MISTED_GLASS_DOOR = register(new TallBlockItem(UBlocks.MISTED_GLASS_DOOR, new Item.Settings().group(ItemGroup.REDSTONE)), "misted_glass_door");
Item LIBRARY_DOOR = register(new TallBlockItem(UBlocks.LIBRARY_DOOR, new Item.Settings().group(ItemGroup.REDSTONE)), "library_door"); Item LIBRARY_DOOR = register(new TallBlockItem(UBlocks.LIBRARY_DOOR, new Item.Settings().group(ItemGroup.REDSTONE)), "library_door");
Item BAKERY_DOOR = register(new TallBlockItem(UBlocks.BAKERY_DOOR, new Item.Settings().group(ItemGroup.REDSTONE)), "bakery_door"); Item BAKERY_DOOR = register(new TallBlockItem(UBlocks.BAKERY_DOOR, new Item.Settings().group(ItemGroup.REDSTONE)), "bakery_door");
Item DIAMOND_DOOR = register(new TallBlockItem(UBlocks.DIAMOND_DOOR, new Item.Settings().group(ItemGroup.REDSTONE)), "diamond_door"); Item DIAMOND_DOOR = register(new TallBlockItem(UBlocks.DIAMOND_DOOR, new Item.Settings().group(ItemGroup.REDSTONE)), "diamond_door");
@ -154,7 +153,7 @@ public interface UItems {
Item BUTTERFLY_SPAWN_EGG = register(new SpawnEggItem(UEntities.BUTTERFLY, 0x222200, 0xaaeeff, new Item.Settings().group(ItemGroup.MISC)), "butterfly_spawn_egg"); Item BUTTERFLY_SPAWN_EGG = register(new SpawnEggItem(UEntities.BUTTERFLY, 0x222200, 0xaaeeff, new Item.Settings().group(ItemGroup.MISC)), "butterfly_spawn_egg");
static <T extends Item> T register(T item, String name) { static <T extends Item> T register(T item, String name) {
return Registry.ITEM.add(new Identifier(Unicopia.MODID, name), item); return Registry.ITEM.add(new Identifier("unicopia", name), item);
} }
static MusicDiscItem createRecord(SoundEvent sound) { static MusicDiscItem createRecord(SoundEvent sound) {

View file

@ -19,7 +19,7 @@ public class MsgPlayerAbility implements Channel.Packet {
private final String abilityJson; private final String abilityJson;
public MsgPlayerAbility(Ability<?> power, Ability.IData data) { MsgPlayerAbility(Ability<?> power, Ability.IData data) {
powerIdentifier = power.getKeyName(); powerIdentifier = power.getKeyName();
abilityJson = gson.toJson(data, power.getPackageType()); abilityJson = gson.toJson(data, power.getPackageType());
} }

View file

@ -20,7 +20,7 @@ public class MsgPlayerCapabilities implements Channel.Packet {
private final CompoundTag compoundTag; private final CompoundTag compoundTag;
public MsgPlayerCapabilities(PacketByteBuf buffer) { MsgPlayerCapabilities(PacketByteBuf buffer) {
newRace = Race.values()[buffer.readInt()]; newRace = Race.values()[buffer.readInt()];
try (InputStream in = new ByteBufInputStream(buffer)) { try (InputStream in = new ByteBufInputStream(buffer)) {
compoundTag = NbtIo.readCompressed(in); compoundTag = NbtIo.readCompressed(in);

View file

@ -4,18 +4,17 @@ import com.minelittlepony.unicopia.Race;
import com.minelittlepony.unicopia.entity.player.Pony; import com.minelittlepony.unicopia.entity.player.Pony;
import net.fabricmc.fabric.api.network.PacketContext; import net.fabricmc.fabric.api.network.PacketContext;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.util.PacketByteBuf; import net.minecraft.util.PacketByteBuf;
public class MsgRequestCapabilities implements Channel.Packet { public class MsgRequestCapabilities implements Channel.Packet {
private final Race race; private final Race race;
public MsgRequestCapabilities(PacketByteBuf buffer) { MsgRequestCapabilities(PacketByteBuf buffer) {
race = Race.values()[buffer.readInt()]; race = Race.values()[buffer.readInt()];
} }
public MsgRequestCapabilities(PlayerEntity player, Race preferredRace) { public MsgRequestCapabilities(Race preferredRace) {
race = preferredRace; race = preferredRace;
} }
@ -34,5 +33,4 @@ public class MsgRequestCapabilities implements Channel.Packet {
Channel.PLAYER_CAPABILITIES.send(context.getPlayer(), new MsgPlayerCapabilities(true, player)); Channel.PLAYER_CAPABILITIES.send(context.getPlayer(), new MsgPlayerCapabilities(true, player));
} }
} }

View file

@ -22,7 +22,7 @@ public class MsgSpawnRainbow implements Channel.Packet {
z = entity.getZ(); z = entity.getZ();
} }
public MsgSpawnRainbow(PacketByteBuf buffer) { MsgSpawnRainbow(PacketByteBuf buffer) {
id = buffer.readVarInt(); id = buffer.readVarInt();
x = buffer.readDouble(); x = buffer.readDouble();
y = buffer.readDouble(); y = buffer.readDouble();

View file

@ -4,7 +4,6 @@ import java.util.Arrays;
import java.util.Random; import java.util.Random;
import java.util.function.Function; import java.util.function.Function;
import com.minelittlepony.unicopia.Unicopia;
import com.mojang.datafixers.Dynamic; import com.mojang.datafixers.Dynamic;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
@ -33,9 +32,9 @@ import net.minecraft.world.gen.feature.StructureFeature;
class CloudDungeonFeature extends AbstractTempleFeature<DefaultFeatureConfig> { class CloudDungeonFeature extends AbstractTempleFeature<DefaultFeatureConfig> {
private static final BlockPos POS = new BlockPos(4, 0, 15); private static final BlockPos POS = new BlockPos(4, 0, 15);
private static final Identifier[] VARIANTS = new Identifier[] { private static final Identifier[] VARIANTS = new Identifier[] {
new Identifier(Unicopia.MODID, "cloud/temple_small"), new Identifier("unicopia", "cloud/temple_small"),
new Identifier(Unicopia.MODID, "cloud/house_small"), new Identifier("unicopia", "cloud/house_small"),
new Identifier(Unicopia.MODID, "cloud/island_small") new Identifier("unicopia", "cloud/island_small")
}; };
public CloudDungeonFeature(Function<Dynamic<?>, ? extends DefaultFeatureConfig> func) { public CloudDungeonFeature(Function<Dynamic<?>, ? extends DefaultFeatureConfig> func) {

View file

@ -4,7 +4,6 @@ import java.util.Arrays;
import java.util.Random; import java.util.Random;
import java.util.function.Function; import java.util.function.Function;
import com.minelittlepony.unicopia.Unicopia;
import com.mojang.datafixers.Dynamic; import com.mojang.datafixers.Dynamic;
import net.minecraft.nbt.CompoundTag; import net.minecraft.nbt.CompoundTag;
@ -33,11 +32,11 @@ import net.minecraft.world.gen.feature.StructureFeature;
class RuinFeature extends AbstractTempleFeature<DefaultFeatureConfig> { class RuinFeature extends AbstractTempleFeature<DefaultFeatureConfig> {
private static final BlockPos POS = new BlockPos(4, 0, 15); private static final BlockPos POS = new BlockPos(4, 0, 15);
private static final Identifier[] VARIANTS = new Identifier[] { private static final Identifier[] VARIANTS = new Identifier[] {
new Identifier(Unicopia.MODID, "ground/tower"), new Identifier("unicopia", "ground/tower"),
new Identifier(Unicopia.MODID, "ground/temple_with_book"), new Identifier("unicopia", "ground/temple_with_book"),
new Identifier(Unicopia.MODID, "ground/temple_without_book"), new Identifier("unicopia", "ground/temple_without_book"),
new Identifier(Unicopia.MODID, "ground/wizard_tower_red"), new Identifier("unicopia", "ground/wizard_tower_red"),
new Identifier(Unicopia.MODID, "ground/wizard_tower_blue") new Identifier("unicopia", "ground/wizard_tower_blue")
}; };
public RuinFeature(Function<Dynamic<?>, ? extends DefaultFeatureConfig> func) { public RuinFeature(Function<Dynamic<?>, ? extends DefaultFeatureConfig> func) {

View file

@ -1,7 +1,5 @@
package com.minelittlepony.unicopia.structure; package com.minelittlepony.unicopia.structure;
import com.minelittlepony.unicopia.Unicopia;
import net.minecraft.structure.StructurePieceType; import net.minecraft.structure.StructurePieceType;
import net.minecraft.util.Identifier; import net.minecraft.util.Identifier;
import net.minecraft.util.registry.Registry; import net.minecraft.util.registry.Registry;
@ -18,11 +16,11 @@ public interface UStructures {
StructureFeature<DefaultFeatureConfig> RUIN = feature("ruin", new RuinFeature(DefaultFeatureConfig::deserialize)); StructureFeature<DefaultFeatureConfig> RUIN = feature("ruin", new RuinFeature(DefaultFeatureConfig::deserialize));
static StructurePieceType part(String id, StructurePieceType type) { static StructurePieceType part(String id, StructurePieceType type) {
return Registry.register(Registry.STRUCTURE_PIECE, new Identifier(Unicopia.MODID, id), type); return Registry.register(Registry.STRUCTURE_PIECE, new Identifier("unicopia", id), type);
} }
static <C extends FeatureConfig, F extends Feature<C>> F feature(String id, F feature) { static <C extends FeatureConfig, F extends Feature<C>> F feature(String id, F feature) {
return Registry.register(Registry.FEATURE, new Identifier(Unicopia.MODID, id), feature); return Registry.register(Registry.FEATURE, new Identifier("unicopia", id), feature);
} }
static void bootstrap() { } static void bootstrap() { }