From b75ea7dfcf5dbd77f4d8d844006f0265a0414057 Mon Sep 17 00:00:00 2001 From: Sollace Date: Wed, 30 Jan 2019 12:26:00 +0200 Subject: [PATCH] God damn it Forge. Whoever invented these @SideOnly annotations deserved to die and burn for eternity in the ninth circle of hell for their crimes --- .../com/minelittlepony/unicopia/UBlocks.java | 3 + .../com/minelittlepony/unicopia/UClient.java | 48 +++++- .../minelittlepony/unicopia/UEntities.java | 34 ++-- .../com/minelittlepony/unicopia/UItems.java | 3 + .../minelittlepony/unicopia/UMaterials.java | 2 +- .../minelittlepony/unicopia/UParticles.java | 4 + .../com/minelittlepony/unicopia/Unicopia.java | 118 ++------------ .../unicopia/UnicopiaClient.java | 152 ++++++++++++++++++ .../unicopia/block/BlockCloud.java | 3 +- .../unicopia/block/ICloudBlock.java | 15 +- .../unicopia/entity/EntityCloud.java | 3 + .../unicopia/forgebullshit/BiomeBS.java | 27 ++++ .../forgebullshit/BuildInTexturesBakery.java | 8 +- ...faultEntityCapabilitiesProxyContainer.java | 1 + .../unicopia/forgebullshit/EntityType.java | 52 ++++++ .../unicopia/forgebullshit/FBS.java | 4 + .../unicopia/forgebullshit/FUF.java | 22 +++ .../forgebullshit/NoNameSpacedResource.java | 35 ---- .../unicopia/forgebullshit/Provider.java | 1 + .../forgebullshit/RegistryLockSpinner.java | 45 ++++-- .../unicopia/forgebullshit/Storage.java | 1 + .../unicopia/input/Keyboard.java | 4 +- .../unicopia/item/ItemOfHolding.java | 16 +- .../network/MsgPlayerCapabilities.java | 4 +- .../network/MsgRequestCapabilities.java | 3 +- .../particle/client/ParticlesClient.java | 3 - 26 files changed, 399 insertions(+), 212 deletions(-) create mode 100644 src/main/java/com/minelittlepony/unicopia/UnicopiaClient.java create mode 100644 src/main/java/com/minelittlepony/unicopia/forgebullshit/BiomeBS.java create mode 100644 src/main/java/com/minelittlepony/unicopia/forgebullshit/EntityType.java create mode 100644 src/main/java/com/minelittlepony/unicopia/forgebullshit/FUF.java delete mode 100644 src/main/java/com/minelittlepony/unicopia/forgebullshit/NoNameSpacedResource.java diff --git a/src/main/java/com/minelittlepony/unicopia/UBlocks.java b/src/main/java/com/minelittlepony/unicopia/UBlocks.java index d24e6066..3bb780c7 100644 --- a/src/main/java/com/minelittlepony/unicopia/UBlocks.java +++ b/src/main/java/com/minelittlepony/unicopia/UBlocks.java @@ -23,6 +23,8 @@ import net.minecraft.item.ItemStack; import net.minecraft.world.ColorizerFoliage; import net.minecraft.world.biome.BiomeColorHelper; import net.minecraft.world.gen.feature.WorldGenTrees; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; import net.minecraftforge.registries.IForgeRegistry; public class UBlocks { @@ -61,6 +63,7 @@ public class UBlocks { apple_tree, apple_leaves); } + @SideOnly(Side.CLIENT) static void registerColors(ItemColors items, BlockColors blocks) { items.registerItemColorHandler((stack, tint) -> { @SuppressWarnings("deprecation") diff --git a/src/main/java/com/minelittlepony/unicopia/UClient.java b/src/main/java/com/minelittlepony/unicopia/UClient.java index a1e85dcc..430220bd 100644 --- a/src/main/java/com/minelittlepony/unicopia/UClient.java +++ b/src/main/java/com/minelittlepony/unicopia/UClient.java @@ -1,9 +1,51 @@ package com.minelittlepony.unicopia; -import net.minecraftforge.fml.common.FMLCommonHandler; +import javax.annotation.Nullable; -public interface UClient { - static boolean isClientSide() { +import com.minelittlepony.unicopia.forgebullshit.FUF; + +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.world.IInteractionObject; +import net.minecraftforge.fml.common.FMLCommonHandler; +import net.minecraftforge.fml.common.event.FMLInitializationEvent; +import net.minecraftforge.fml.common.event.FMLPostInitializationEvent; +import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; + +public class UClient { + + private static UClient instance; + + public static boolean isClientSide() { return FMLCommonHandler.instance().getSide().isClient(); } + + @FUF(reason = "Forced client Separation") + public static UClient instance() { + if (instance == null) { + if (isClientSide()) { + instance = new UnicopiaClient(); + } else { + instance = new UClient(); + } + } + + return instance; + } + + @FUF(reason = "Forced client Separation") + public void displayGuiToPlayer(EntityPlayer player, IInteractionObject inventory) { + player.displayGui(inventory); + } + + @FUF(reason = "Forced client Separation") + @Nullable + public EntityPlayer getPlayer() { + return null; + } + + public void preInit(FMLPreInitializationEvent event) {} + + public void init(FMLInitializationEvent event) {} + + public void posInit(FMLPostInitializationEvent event) {} } diff --git a/src/main/java/com/minelittlepony/unicopia/UEntities.java b/src/main/java/com/minelittlepony/unicopia/UEntities.java index b508a9fe..908a35ff 100644 --- a/src/main/java/com/minelittlepony/unicopia/UEntities.java +++ b/src/main/java/com/minelittlepony/unicopia/UEntities.java @@ -9,15 +9,13 @@ import com.minelittlepony.unicopia.entity.EntitySpell; import com.minelittlepony.unicopia.entity.EntitySpellbook; import com.minelittlepony.unicopia.entity.EntityProjectile; import com.minelittlepony.unicopia.entity.EntityWildCloud; +import com.minelittlepony.unicopia.forgebullshit.EntityType; import com.minelittlepony.unicopia.render.RenderCloud; import com.minelittlepony.unicopia.render.RenderGem; import com.minelittlepony.unicopia.render.RenderProjectile; import com.minelittlepony.unicopia.render.RenderSpellbook; -import net.minecraft.entity.Entity; -import net.minecraft.entity.EntityList.EntityEggInfo; import net.minecraft.entity.EnumCreatureType; -import net.minecraft.util.ResourceLocation; import net.minecraft.world.biome.Biome; import net.minecraft.world.biome.Biome.SpawnListEntry; import net.minecraft.world.biome.BiomeEnd; @@ -25,7 +23,6 @@ import net.minecraft.world.biome.BiomeHell; import net.minecraftforge.common.BiomeManager; import net.minecraftforge.fml.client.registry.RenderingRegistry; import net.minecraftforge.fml.common.registry.EntityEntry; -import net.minecraftforge.fml.common.registry.EntityEntryBuilder; import net.minecraftforge.registries.IForgeRegistry; public class UEntities { @@ -33,14 +30,15 @@ public class UEntities { private static final int BRUSHES_CHARTREUSE = 0x7FFF00; static void init(IForgeRegistry registry) { + EntityType builder = EntityType.builder(Unicopia.MODID); registry.registerAll( - new Entry(EntityCloud.class, "cloud").withEgg(BRUSHES_ROYALBLUE, BRUSHES_CHARTREUSE), - new Entry(EntityWildCloud.class, "wild_cloud"), - new Entry(EntityRacingCloud.class, "racing_cloud"), - new Entry(EntityConstructionCloud.class, "construction_cloud"), - new Entry(EntitySpell.class, "magic_spell"), - new Entry(EntitySpellbook.class, "spellbook"), - EntityEntryBuilder.create().entity(EntityProjectile.class).name("thrown_item").id(new ResourceLocation(Unicopia.MODID, "thrown_item"), 0).tracker(10, 5, true).build() + builder.creature(EntityCloud.class, "cloud").withEgg(BRUSHES_ROYALBLUE, BRUSHES_CHARTREUSE), + builder.creature(EntityWildCloud.class, "wild_cloud"), + builder.creature(EntityRacingCloud.class, "racing_cloud"), + builder.creature(EntityConstructionCloud.class, "construction_cloud"), + builder.creature(EntitySpell.class, "magic_spell"), + builder.creature(EntitySpellbook.class, "spellbook"), + builder.projectile(EntityProjectile.class, "thrown_item", 10, 5) ); } @@ -64,18 +62,4 @@ public class UEntities { }); } } - - static class Entry extends EntityEntry { - - public Entry(Class cls, String name) { - super(cls, name); - setRegistryName(Unicopia.MODID, name); - } - - Entry withEgg(int a, int b) { - setEgg(new EntityEggInfo(getRegistryName(), a, b)); - - return this; - } - } } diff --git a/src/main/java/com/minelittlepony/unicopia/UItems.java b/src/main/java/com/minelittlepony/unicopia/UItems.java index 661b426f..78971f03 100644 --- a/src/main/java/com/minelittlepony/unicopia/UItems.java +++ b/src/main/java/com/minelittlepony/unicopia/UItems.java @@ -40,6 +40,8 @@ import net.minecraft.item.crafting.ShapedRecipes; import net.minecraft.util.NonNullList; import net.minecraft.util.ResourceLocation; import net.minecraftforge.client.model.ModelLoader; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; import net.minecraftforge.registries.IForgeRegistry; import static com.minelittlepony.unicopia.Predicates.*; @@ -228,6 +230,7 @@ public class UItems { ), new ItemStack(cloud_block, 1, 2)).setRegistryName(Unicopia.MODID, "id_dont_care_just_use_it")); } + @SideOnly(Side.CLIENT) static void registerColors(ItemColors registry) { registry.registerItemColorHandler((stack, tint) -> { if (Predicates.MAGI.test(Minecraft.getMinecraft().player)) { diff --git a/src/main/java/com/minelittlepony/unicopia/UMaterials.java b/src/main/java/com/minelittlepony/unicopia/UMaterials.java index 94744efd..52265d08 100644 --- a/src/main/java/com/minelittlepony/unicopia/UMaterials.java +++ b/src/main/java/com/minelittlepony/unicopia/UMaterials.java @@ -4,5 +4,5 @@ import net.minecraft.block.material.MapColor; import net.minecraft.block.material.Material; public class UMaterials { - public static final Material cloud = (new Material(MapColor.SNOW)); + public static final Material cloud = new Material(MapColor.SNOW); } diff --git a/src/main/java/com/minelittlepony/unicopia/UParticles.java b/src/main/java/com/minelittlepony/unicopia/UParticles.java index 8127efb2..7f845f95 100644 --- a/src/main/java/com/minelittlepony/unicopia/UParticles.java +++ b/src/main/java/com/minelittlepony/unicopia/UParticles.java @@ -4,11 +4,15 @@ import com.minelittlepony.unicopia.particle.Particles; import com.minelittlepony.unicopia.particle.client.EntityMagicFX; import com.minelittlepony.unicopia.particle.client.EntityRaindropFX; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + public class UParticles { public static int MAGIC_PARTICLE; public static int RAIN_PARTICLE; + @SideOnly(Side.CLIENT) static void init() { MAGIC_PARTICLE = Particles.instance().registerParticle(EntityMagicFX::new); RAIN_PARTICLE = Particles.instance().registerParticle(EntityRaindropFX::new); diff --git a/src/main/java/com/minelittlepony/unicopia/Unicopia.java b/src/main/java/com/minelittlepony/unicopia/Unicopia.java index c6f8e82e..82f2acb2 100644 --- a/src/main/java/com/minelittlepony/unicopia/Unicopia.java +++ b/src/main/java/com/minelittlepony/unicopia/Unicopia.java @@ -3,7 +3,6 @@ package com.minelittlepony.unicopia; import net.minecraft.block.Block; import net.minecraft.block.BlockTallGrass; import net.minecraft.block.state.IBlockState; -import net.minecraft.client.Minecraft; import net.minecraft.entity.Entity; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.init.Blocks; @@ -15,11 +14,6 @@ import net.minecraft.util.SoundEvent; import net.minecraft.util.math.BlockPos; import net.minecraft.world.World; import net.minecraft.world.biome.Biome; -import net.minecraftforge.client.event.ColorHandlerEvent; -import net.minecraftforge.client.event.EntityViewRenderEvent; -import net.minecraftforge.client.event.FOVUpdateEvent; -import net.minecraftforge.client.event.RenderGameOverlayEvent; -import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType; import net.minecraftforge.event.RegistryEvent; import net.minecraftforge.event.entity.item.ItemTossEvent; import net.minecraftforge.event.entity.living.LivingEntityUseItemEvent; @@ -41,34 +35,28 @@ import net.minecraftforge.fml.common.gameevent.TickEvent.Phase; import net.minecraftforge.fml.common.network.IGuiHandler; import net.minecraftforge.fml.common.network.NetworkRegistry; import net.minecraftforge.fml.common.registry.EntityEntry; -import net.minecraftforge.fml.relauncher.Side; -import net.minecraftforge.fml.relauncher.SideOnly; - import java.util.Map; import java.util.function.Function; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.Logger; + import com.google.gson.JsonObject; import com.minelittlepony.jumpingcastle.api.IChannel; import com.minelittlepony.jumpingcastle.api.JumpingCastle; -import com.minelittlepony.jumpingcastle.api.Target; import com.minelittlepony.unicopia.advancements.UAdvancements; import com.minelittlepony.unicopia.block.ITillable; import com.minelittlepony.unicopia.command.Commands; import com.minelittlepony.unicopia.enchanting.SpellRecipe; import com.minelittlepony.unicopia.forgebullshit.FBS; -import com.minelittlepony.unicopia.hud.UHud; -import com.minelittlepony.unicopia.input.Keyboard; import com.minelittlepony.unicopia.inventory.gui.ContainerSpellBook; import com.minelittlepony.unicopia.inventory.gui.GuiSpellBook; import com.minelittlepony.unicopia.network.MsgPlayerAbility; import com.minelittlepony.unicopia.network.MsgPlayerCapabilities; import com.minelittlepony.unicopia.network.MsgRequestCapabilities; -import com.minelittlepony.unicopia.player.IPlayer; -import com.minelittlepony.unicopia.player.IView; import com.minelittlepony.unicopia.player.PlayerSpeciesList; import com.minelittlepony.unicopia.power.PowersRegistry; import com.minelittlepony.unicopia.util.crafting.CraftingManager; -import com.minelittlepony.pony.data.IPony; @Mod( modid = Unicopia.MODID, @@ -82,43 +70,16 @@ public class Unicopia implements IGuiHandler { public static final String NAME = "@NAME@"; public static final String VERSION = "@VERSION@"; - public static IChannel channel; + public static final Logger log = LogManager.getLogger(); - /** - * 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(); + public static IChannel channel; private static CraftingManager craftingManager; @EventHandler public void preInit(FMLPreInitializationEvent event) { UConfig.init(event.getModConfigurationDirectory()); - - if (UClient.isClientSide()) { - UEntities.preInit(); - UParticles.init(); - } - } - - @SideOnly(Side.CLIENT) - private static Race getclientPlayerRace() { - if (!UConfig.getInstance().ignoresMineLittlePony() - && Minecraft.getMinecraft().player != null - && MineLP.modIsActive()) { - Race race = Race.fromPonyRace(IPony.forPlayer(Minecraft.getMinecraft().player).getRace(false)); - - if (!race.isDefault()) { - return race; - } - } - - return UConfig.getInstance().getPrefferedRace(); + UClient.instance().preInit(event); } @EventHandler @@ -135,7 +96,8 @@ public class Unicopia implements IGuiHandler { FBS.init(); NetworkRegistry.INSTANCE.registerGuiHandler(this, this); - clientPlayerRace = getclientPlayerRace(); + + UClient.instance().init(event); } @EventHandler @@ -150,6 +112,7 @@ public class Unicopia implements IGuiHandler { }; Biome.REGISTRY.forEach(UEntities::registerSpawnEntries); + UClient.instance().posInit(event); } public static CraftingManager getCraftingManager() { @@ -161,12 +124,6 @@ public class Unicopia implements IGuiHandler { UItems.registerItems(event.getRegistry()); } - @SubscribeEvent - public static void registerItemColours(ColorHandlerEvent.Item event) { - UItems.registerColors(event.getItemColors()); - UBlocks.registerColors(event.getItemColors(), event.getBlockColors()); - } - @SubscribeEvent public static void registerBlocks(RegistryEvent.Register event) { UBlocks.registerBlocks(event.getRegistry()); @@ -187,39 +144,6 @@ public class Unicopia implements IGuiHandler { UEntities.init(event.getRegistry()); } - @SideOnly(Side.CLIENT) - @SubscribeEvent - public static void onGameTick(TickEvent.ClientTickEvent event) { - if (event.phase == Phase.END) { - if (Minecraft.getMinecraft().player != null) { - Race newRace = getclientPlayerRace(); - - if (newRace != clientPlayerRace) { - clientPlayerRace = newRace; - - channel.send(new MsgRequestCapabilities(Minecraft.getMinecraft().player, clientPlayerRace), Target.SERVER); - } - } - - Keyboard.getKeyHandler().onKeyInput(); - } - } - - @SideOnly(Side.CLIENT) - @SubscribeEvent - public static void setupPlayerCamera(EntityViewRenderEvent.CameraSetup event) { - - EntityPlayer player = Minecraft.getMinecraft().player; - - if (player != null) { - IView view = PlayerSpeciesList.instance().getPlayer(player).getCamera(); - - event.setRoll(view.calculateRoll()); - event.setPitch(view.calculatePitch(event.getPitch())); - event.setYaw(view.calculateYaw(event.getYaw())); - } - } - @SubscribeEvent public static void onBlockHarvested(BlockEvent.HarvestDropsEvent event) { Block block = event.getState().getBlock(); @@ -305,27 +229,10 @@ public class Unicopia implements IGuiHandler { } @EventHandler - public void onServerStarted(FMLServerStartingEvent event) { + public void onServerStart(FMLServerStartingEvent event) { Commands.init(event); } - @SideOnly(Side.CLIENT) - @SubscribeEvent - public static void onRenderHud(RenderGameOverlayEvent.Post event) { - if (event.getType() != ElementType.ALL) { - return; - } - - if (UClient.isClientSide()) { - Minecraft mc = Minecraft.getMinecraft(); - if (mc.player != null && mc.world != null) { - IPlayer player = PlayerSpeciesList.instance().getPlayer(mc.player); - - UHud.instance.renderHud(player, event.getResolution()); - } - } - } - @SubscribeEvent public static void onItemUseFinish(LivingEntityUseItemEvent.Finish event) { Entity e = event.getEntity(); @@ -335,11 +242,6 @@ public class Unicopia implements IGuiHandler { } } - @SubscribeEvent - public static void modifyFOV(FOVUpdateEvent event) { - event.setNewfov(PlayerSpeciesList.instance().getPlayer(event.getEntity()).getCamera().calculateFieldOfView(event.getFov())); - } - @Override public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) { switch (ID) { diff --git a/src/main/java/com/minelittlepony/unicopia/UnicopiaClient.java b/src/main/java/com/minelittlepony/unicopia/UnicopiaClient.java new file mode 100644 index 00000000..8225a7aa --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/UnicopiaClient.java @@ -0,0 +1,152 @@ +package com.minelittlepony.unicopia; + +import javax.annotation.Nullable; + +import com.minelittlepony.jumpingcastle.api.Target; +import com.minelittlepony.pony.data.IPony; +import com.minelittlepony.unicopia.hud.UHud; +import com.minelittlepony.unicopia.input.Keyboard; +import com.minelittlepony.unicopia.inventory.gui.GuiOfHolding; +import com.minelittlepony.unicopia.network.MsgRequestCapabilities; +import com.minelittlepony.unicopia.player.IPlayer; +import com.minelittlepony.unicopia.player.IView; +import com.minelittlepony.unicopia.player.PlayerSpeciesList; + +import net.minecraft.client.Minecraft; +import net.minecraft.client.entity.EntityPlayerSP; +import net.minecraft.entity.player.EntityPlayer; +import net.minecraft.world.IInteractionObject; +import net.minecraftforge.client.event.ColorHandlerEvent; +import net.minecraftforge.client.event.EntityViewRenderEvent; +import net.minecraftforge.client.event.FOVUpdateEvent; +import net.minecraftforge.client.event.RenderGameOverlayEvent; +import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType; +import net.minecraftforge.fml.common.Mod.EventBusSubscriber; +import net.minecraftforge.fml.common.event.FMLInitializationEvent; +import net.minecraftforge.fml.common.event.FMLPreInitializationEvent; +import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +import net.minecraftforge.fml.common.gameevent.TickEvent; +import net.minecraftforge.fml.common.gameevent.TickEvent.Phase; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; + +@EventBusSubscriber(Side.CLIENT) +public class UnicopiaClient extends UClient { + + /** + * 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(); + + private static Race getclientPlayerRace() { + if (!UConfig.getInstance().ignoresMineLittlePony() + && Minecraft.getMinecraft().player != null + && MineLP.modIsActive()) { + Race race = Race.fromPonyRace(IPony.forPlayer(Minecraft.getMinecraft().player).getRace(false)); + + if (!race.isDefault()) { + return race; + } + } + + return UConfig.getInstance().getPrefferedRace(); + } + + + @Override + public void displayGuiToPlayer(EntityPlayer player, IInteractionObject inventory) { + if (player instanceof EntityPlayerSP) { + if ("unicopia:itemofholding".equals(inventory.getGuiID())) { + Minecraft.getMinecraft().displayGuiScreen(new GuiOfHolding(inventory)); + } + } else { + super.displayGuiToPlayer(player, inventory); + } + } + + @Nullable + public EntityPlayer getPlayer() { + return Minecraft.getMinecraft().player; + } + + @SideOnly(Side.CLIENT) + @Override + public void preInit(FMLPreInitializationEvent event) { + UEntities.preInit(); + UParticles.init(); + } + + @SideOnly(Side.CLIENT) + @Override + public void init(FMLInitializationEvent event) { + clientPlayerRace = getclientPlayerRace(); + } + + @SideOnly(Side.CLIENT) + @SubscribeEvent + public static void registerItemColours(ColorHandlerEvent.Item event) { + UItems.registerColors(event.getItemColors()); + UBlocks.registerColors(event.getItemColors(), event.getBlockColors()); + } + + @SideOnly(Side.CLIENT) + @SubscribeEvent + public static void onRenderHud(RenderGameOverlayEvent.Post event) { + if (event.getType() != ElementType.ALL) { + return; + } + + if (UClient.isClientSide()) { + Minecraft mc = Minecraft.getMinecraft(); + if (mc.player != null && mc.world != null) { + IPlayer player = PlayerSpeciesList.instance().getPlayer(mc.player); + + UHud.instance.renderHud(player, event.getResolution()); + } + } + } + + @SideOnly(Side.CLIENT) + @SubscribeEvent + public static void modifyFOV(FOVUpdateEvent event) { + event.setNewfov(PlayerSpeciesList.instance().getPlayer(event.getEntity()).getCamera().calculateFieldOfView(event.getFov())); + } + + @SideOnly(Side.CLIENT) + @SubscribeEvent + public static void onGameTick(TickEvent.ClientTickEvent event) { + if (event.phase == Phase.END) { + if (Minecraft.getMinecraft().player != null) { + Race newRace = getclientPlayerRace(); + + if (newRace != clientPlayerRace) { + clientPlayerRace = newRace; + + Unicopia.channel.send(new MsgRequestCapabilities(Minecraft.getMinecraft().player, clientPlayerRace), Target.SERVER); + } + } + + Keyboard.getKeyHandler().onKeyInput(); + } + } + + @SideOnly(Side.CLIENT) + @SubscribeEvent + public static void setupPlayerCamera(EntityViewRenderEvent.CameraSetup event) { + + EntityPlayer player = Minecraft.getMinecraft().player; + + if (player != null) { + IView view = PlayerSpeciesList.instance().getPlayer(player).getCamera(); + + event.setRoll(view.calculateRoll()); + event.setPitch(view.calculatePitch(event.getPitch())); + event.setYaw(view.calculateYaw(event.getYaw())); + } + } +} diff --git a/src/main/java/com/minelittlepony/unicopia/block/BlockCloud.java b/src/main/java/com/minelittlepony/unicopia/block/BlockCloud.java index 835abf4d..eefe6934 100644 --- a/src/main/java/com/minelittlepony/unicopia/block/BlockCloud.java +++ b/src/main/java/com/minelittlepony/unicopia/block/BlockCloud.java @@ -11,7 +11,6 @@ import com.minelittlepony.unicopia.player.PlayerSpeciesList; import net.minecraft.block.Block; import net.minecraft.block.SoundType; import net.minecraft.block.material.Material; -import net.minecraft.block.properties.IProperty; import net.minecraft.block.properties.PropertyEnum; import net.minecraft.block.state.BlockStateContainer; import net.minecraft.block.state.IBlockState; @@ -182,7 +181,7 @@ public class BlockCloud extends Block implements ICloudBlock, ITillable { @Override protected BlockStateContainer createBlockState() { - return new BlockStateContainer(this, new IProperty[] {VARIANT}); + return new BlockStateContainer(this, VARIANT); } @Override diff --git a/src/main/java/com/minelittlepony/unicopia/block/ICloudBlock.java b/src/main/java/com/minelittlepony/unicopia/block/ICloudBlock.java index 2409107a..3dfbdea5 100644 --- a/src/main/java/com/minelittlepony/unicopia/block/ICloudBlock.java +++ b/src/main/java/com/minelittlepony/unicopia/block/ICloudBlock.java @@ -1,12 +1,13 @@ package com.minelittlepony.unicopia.block; import com.minelittlepony.unicopia.CloudType; +import com.minelittlepony.unicopia.UClient; +import com.minelittlepony.unicopia.forgebullshit.FUF; import net.minecraft.block.Block; import net.minecraft.block.BlockFalling; import net.minecraft.block.BlockTorch; import net.minecraft.block.state.IBlockState; -import net.minecraft.client.Minecraft; import net.minecraft.entity.Entity; import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.player.EntityPlayer; @@ -23,7 +24,7 @@ public interface ICloudBlock { default boolean handleRayTraceSpecialCases(World world, BlockPos pos, IBlockState state) { if (world.isRemote) { - EntityPlayer player = Minecraft.getMinecraft().player; + EntityPlayer player = UClient.instance().getPlayer(); if (!getCanInteract(state, player)) { return true; @@ -57,6 +58,7 @@ public interface ICloudBlock { default boolean getCanInteract(IBlockState state, Entity e) { if (getCloudMaterialType(state).canInteract(e)) { if (e instanceof EntityItem) { + // @FUF(reason = "There is no TickEvents.EntityTickEvent. Waiting on mixins...") e.setNoGravity(true); } return true; @@ -69,6 +71,15 @@ public interface ICloudBlock { return getCloudMaterialType(blockState) != CloudType.NORMAL; } + /** + * Determines whether falling sand entities should fall through this block. + * @param state Our block state + * @param world The current world + * @param pos The current position + * + * @return True to allow blocks to pass. + */ + @FUF(reason = "Hacked until we can get mixins to implement a proper hook") default boolean allowsFallingBlockToPass(IBlockState state, IBlockAccess world, BlockPos pos) { if (isDense(state)) { return false; diff --git a/src/main/java/com/minelittlepony/unicopia/entity/EntityCloud.java b/src/main/java/com/minelittlepony/unicopia/entity/EntityCloud.java index b102207b..21dccbb4 100644 --- a/src/main/java/com/minelittlepony/unicopia/entity/EntityCloud.java +++ b/src/main/java/com/minelittlepony/unicopia/entity/EntityCloud.java @@ -7,6 +7,7 @@ import com.minelittlepony.unicopia.Predicates; import com.minelittlepony.unicopia.UBlocks; import com.minelittlepony.unicopia.UItems; import com.minelittlepony.unicopia.UParticles; +import com.minelittlepony.unicopia.forgebullshit.FUF; import com.minelittlepony.unicopia.particle.Particles; import com.minelittlepony.unicopia.player.PlayerSpeciesList; @@ -517,6 +518,7 @@ public class EntityCloud extends EntityFlying implements IAnimals { clearItemFloatingState(); } + @FUF(reason = "There is no TickEvent.EntityTickEvent. Waiting on mixins...") protected void clearItemFloatingState() { AxisAlignedBB bounds = getEntityBoundingBox().grow(1 / (1 + getCloudSize())).grow(5); @@ -579,6 +581,7 @@ public class EntityCloud extends EntityFlying implements IAnimals { spawnThunderbolt(getPosition()); } + // @FUF(reason = "There is no TickEvents.EntityTickEvent. Waiting on mixins...") if (getStationary() && entity instanceof EntityItem) { entity.motionX /= 8; entity.motionZ /= 8; diff --git a/src/main/java/com/minelittlepony/unicopia/forgebullshit/BiomeBS.java b/src/main/java/com/minelittlepony/unicopia/forgebullshit/BiomeBS.java new file mode 100644 index 00000000..ff933eca --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/forgebullshit/BiomeBS.java @@ -0,0 +1,27 @@ +package com.minelittlepony.unicopia.forgebullshit; + +import java.util.Optional; + +import com.google.common.collect.Lists; + +import net.minecraft.world.biome.Biome; +import net.minecraftforge.common.BiomeManager; +import net.minecraftforge.common.BiomeManager.BiomeType; + +/** + * Provides methods and apis that forge seems to be sorely lacking. + */ +public class BiomeBS { + + /** + * Gets the biome type associated with a given biome. + */ + public static Optional getBiomeType(Biome biome) { + return Lists.newArrayList(BiomeManager.BiomeType.values()).stream().filter(type -> + BiomeManager.getBiomes(type).stream().filter(entry -> + entry.biome.equals(biome) + ).findFirst() + .isPresent() + ).findFirst(); + } +} diff --git a/src/main/java/com/minelittlepony/unicopia/forgebullshit/BuildInTexturesBakery.java b/src/main/java/com/minelittlepony/unicopia/forgebullshit/BuildInTexturesBakery.java index 436ab374..d38ecaa0 100644 --- a/src/main/java/com/minelittlepony/unicopia/forgebullshit/BuildInTexturesBakery.java +++ b/src/main/java/com/minelittlepony/unicopia/forgebullshit/BuildInTexturesBakery.java @@ -5,7 +5,13 @@ import java.util.Set; import net.minecraft.client.renderer.block.model.ModelBakery; import net.minecraft.util.ResourceLocation; - +/** + * Provides access the the built in texture locations. + * This is needed to add things like custom backgrounds for slots. + * @author Chris Albers + * + */ +@FUF(reason = "Forge doesn't provide this, for some unknown reason...") public final class BuildInTexturesBakery extends ModelBakery { private BuildInTexturesBakery() { super(null, null, null); diff --git a/src/main/java/com/minelittlepony/unicopia/forgebullshit/DefaultEntityCapabilitiesProxyContainer.java b/src/main/java/com/minelittlepony/unicopia/forgebullshit/DefaultEntityCapabilitiesProxyContainer.java index 99e9c9c1..60573fdc 100644 --- a/src/main/java/com/minelittlepony/unicopia/forgebullshit/DefaultEntityCapabilitiesProxyContainer.java +++ b/src/main/java/com/minelittlepony/unicopia/forgebullshit/DefaultEntityCapabilitiesProxyContainer.java @@ -18,6 +18,7 @@ class DefaultEntityCapabilitiesProxyContainer implements ICapa @CapabilityInject(ICapabilitiesProxyContainer.class) public static Capability> CAPABILITY = null; + @FUF(reason = "We can't guarantee {CABILITY} won't be null. Whoever thought @CapabilityInject annotations were ever a good idea?") @SuppressWarnings("unchecked") static boolean updateAndCompare(Capability capability) { if (CAPABILITY == null && capability != null) { diff --git a/src/main/java/com/minelittlepony/unicopia/forgebullshit/EntityType.java b/src/main/java/com/minelittlepony/unicopia/forgebullshit/EntityType.java new file mode 100644 index 00000000..939898c7 --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/forgebullshit/EntityType.java @@ -0,0 +1,52 @@ +package com.minelittlepony.unicopia.forgebullshit; + +import net.minecraft.entity.Entity; +import net.minecraft.entity.EntityList.EntityEggInfo; +import net.minecraft.util.ResourceLocation; +import net.minecraftforge.fml.common.registry.EntityEntry; +import net.minecraftforge.fml.common.registry.EntityEntryBuilder; + +public class EntityType { + + private final String modid; + + public EntityType(String modid) { + this.modid = modid; + } + + + public static EntityType builder(String modid) { + return new EntityType(modid); + } + + public Entry creature(Class cls, String name) { + return new Entry(cls, name); + } + + public EntityEntry projectile(Class cls, String name, int min, int max) { + return projectile(cls, name, min, max, true); + } + + @FUF(reason = "...and it's much shorter than typing out this factory mess every time.") + public EntityEntry projectile(Class cls, String name, int min, int max, boolean includeVelocity) { + return EntityEntryBuilder.create().entity(cls) + .name(name) + .id(new ResourceLocation(modid, name), 0).tracker(min, max, includeVelocity) + .build(); + } + + @FUF(reason = "This makes it easier to register an egg...") + public class Entry extends EntityEntry { + + public Entry(Class cls, String name) { + super(cls, name); + setRegistryName(modid, name); + } + + public Entry withEgg(int a, int b) { + setEgg(new EntityEggInfo(getRegistryName(), a, b)); + + return this; + } + } +} diff --git a/src/main/java/com/minelittlepony/unicopia/forgebullshit/FBS.java b/src/main/java/com/minelittlepony/unicopia/forgebullshit/FBS.java index a1c47905..7ffa5165 100644 --- a/src/main/java/com/minelittlepony/unicopia/forgebullshit/FBS.java +++ b/src/main/java/com/minelittlepony/unicopia/forgebullshit/FBS.java @@ -13,6 +13,10 @@ import net.minecraftforge.event.entity.player.PlayerEvent; import net.minecraftforge.fml.common.Mod.EventBusSubscriber; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; +/** + * Wraps the forge Capabilities API into an easier to manage, simple interface. + */ +@FUF(reason = "Capabilities API is such a mess. I'm not going to rewrite it all just to add capabilities to more stuff.") @EventBusSubscriber(modid = Unicopia.MODID) public class FBS { @SuppressWarnings({ "unchecked", "rawtypes" }) diff --git a/src/main/java/com/minelittlepony/unicopia/forgebullshit/FUF.java b/src/main/java/com/minelittlepony/unicopia/forgebullshit/FUF.java new file mode 100644 index 00000000..25295d01 --- /dev/null +++ b/src/main/java/com/minelittlepony/unicopia/forgebullshit/FUF.java @@ -0,0 +1,22 @@ +package com.minelittlepony.unicopia.forgebullshit; + +import static java.lang.annotation.ElementType.*; +import static java.lang.annotation.RetentionPolicy.SOURCE; + +import java.lang.annotation.Documented; +import java.lang.annotation.Retention; +import java.lang.annotation.Target; + +/** + * Workaround because forge freaks out at the nearest mention + * of the possibility of a client class in a server environment + * even when the logic in the code means it would never be executed. + * + * #FuckUForge + */ +@Documented +@Retention(SOURCE) +@Target({METHOD, FIELD, TYPE, CONSTRUCTOR, PACKAGE}) +public @interface FUF { + String reason() default ""; +} diff --git a/src/main/java/com/minelittlepony/unicopia/forgebullshit/NoNameSpacedResource.java b/src/main/java/com/minelittlepony/unicopia/forgebullshit/NoNameSpacedResource.java deleted file mode 100644 index 4e5ccf32..00000000 --- a/src/main/java/com/minelittlepony/unicopia/forgebullshit/NoNameSpacedResource.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.minelittlepony.unicopia.forgebullshit; - -import net.minecraft.util.ResourceLocation; - -public class NoNameSpacedResource extends ResourceLocation { - - public static ResourceLocation[] ofAll(String...strings) { - ResourceLocation[] resources = new ResourceLocation[strings.length]; - - for (int i = 0; i < strings.length; i++) { - resources[i] = new NoNameSpacedResource(strings[i]); - } - - return resources; - } - - public static ResourceLocation[] ofAllDomained(String domain, String...strings) { - ResourceLocation[] resources = new ResourceLocation[strings.length]; - - for (int i = 0; i < strings.length; i++) { - resources[i] = new ResourceLocation(domain, strings[i]); - } - - return resources; - } - - public NoNameSpacedResource(String path) { - super(path); - } - - @Override - public String toString() { - return getPath(); - } -} diff --git a/src/main/java/com/minelittlepony/unicopia/forgebullshit/Provider.java b/src/main/java/com/minelittlepony/unicopia/forgebullshit/Provider.java index 6efee5f9..b00fef3b 100644 --- a/src/main/java/com/minelittlepony/unicopia/forgebullshit/Provider.java +++ b/src/main/java/com/minelittlepony/unicopia/forgebullshit/Provider.java @@ -8,6 +8,7 @@ import net.minecraft.util.EnumFacing; import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.capabilities.ICapabilitySerializable; +@FUF(reason = "Required to provide capability containers. Why can't forge implement this themselves!?") class Provider implements ICapabilitySerializable { private final Entity entity; diff --git a/src/main/java/com/minelittlepony/unicopia/forgebullshit/RegistryLockSpinner.java b/src/main/java/com/minelittlepony/unicopia/forgebullshit/RegistryLockSpinner.java index 25eb2ac9..943696f4 100644 --- a/src/main/java/com/minelittlepony/unicopia/forgebullshit/RegistryLockSpinner.java +++ b/src/main/java/com/minelittlepony/unicopia/forgebullshit/RegistryLockSpinner.java @@ -6,6 +6,7 @@ import java.lang.reflect.Modifier; import net.minecraft.util.registry.RegistryNamespaced; import net.minecraftforge.registries.ILockableRegistry; +@FUF(reason = "Forge locks the registries. We need a way to unlock them.") public final class RegistryLockSpinner { public static void unlock(RegistryNamespaced registry) { @@ -24,28 +25,13 @@ public final class RegistryLockSpinner { public static void commit(RegistryNamespaced registry, V from, V to, Class inClass) { registry.register(registry.getIDForObject(from), registry.getNameForObject(from), to); - Field modifieres = null; - try { - modifieres = Field.class.getDeclaredField("modifiers"); - modifieres.setAccessible(true); - } catch (NoSuchFieldException | SecurityException e1) { - e1.printStackTrace(); - } + for (Field i : inClass.getDeclaredFields()) { try { if (i.get(null) == from) { i.setAccessible(true); - - if (Modifier.isFinal(i.getModifiers())) { - if (modifieres == null) { - continue; - } - - modifieres.setInt(i, i.getModifiers() & ~Modifier.FINAL); - } - - i.set(null, to); + makeNonFinal(i).set(null, to); } } catch (IllegalArgumentException | IllegalAccessException | SecurityException e) { e.printStackTrace(); @@ -53,6 +39,31 @@ public final class RegistryLockSpinner { } } + private static boolean init = false; + private static Field modifieres = null; + + protected static void initModifiersField(Field f) { + if (!init) { + init = true; + try { + modifieres = Field.class.getDeclaredField("modifiers"); + modifieres.setAccessible(true); + } catch (NoSuchFieldException | SecurityException e1) { + e1.printStackTrace(); + } + } + } + + @FUF(reason = "Not exactly forge's fault, but it was would be nice of them to not leave these as final") + protected static Field makeNonFinal(Field f) throws IllegalArgumentException, IllegalAccessException { + initModifiersField(f); + if (Modifier.isFinal(f.getModifiers()) && modifieres != null) { + modifieres.setInt(f, f.getModifiers() & ~Modifier.FINAL); + } + + return f; + } + public static void lock(RegistryNamespaced registry) { if (registry instanceof ILockableRegistry) { ((ILockableRegistry) registry).lock(); diff --git a/src/main/java/com/minelittlepony/unicopia/forgebullshit/Storage.java b/src/main/java/com/minelittlepony/unicopia/forgebullshit/Storage.java index 1444225d..e55aca68 100644 --- a/src/main/java/com/minelittlepony/unicopia/forgebullshit/Storage.java +++ b/src/main/java/com/minelittlepony/unicopia/forgebullshit/Storage.java @@ -7,6 +7,7 @@ import net.minecraft.util.EnumFacing; import net.minecraftforge.common.capabilities.Capability; import net.minecraftforge.common.capabilities.Capability.IStorage; +@FUF(reason = "Required to persist capabilities. Why can't forge implement this themselves!?") class Storage implements IStorage> { @Override diff --git a/src/main/java/com/minelittlepony/unicopia/input/Keyboard.java b/src/main/java/com/minelittlepony/unicopia/input/Keyboard.java index 5925baa2..d59403b8 100644 --- a/src/main/java/com/minelittlepony/unicopia/input/Keyboard.java +++ b/src/main/java/com/minelittlepony/unicopia/input/Keyboard.java @@ -9,10 +9,10 @@ public final class Keyboard { if (keyHandler == null) { if (UClient.isClientSide()) { + keyHandler = new UKeyHandler(); + } else { keyHandler = bind -> {}; } - - keyHandler = new UKeyHandler(); } return keyHandler; diff --git a/src/main/java/com/minelittlepony/unicopia/item/ItemOfHolding.java b/src/main/java/com/minelittlepony/unicopia/item/ItemOfHolding.java index 4e5739e9..287b9fa7 100644 --- a/src/main/java/com/minelittlepony/unicopia/item/ItemOfHolding.java +++ b/src/main/java/com/minelittlepony/unicopia/item/ItemOfHolding.java @@ -10,12 +10,10 @@ import com.minelittlepony.unicopia.Predicates; import com.minelittlepony.unicopia.UClient; import com.minelittlepony.unicopia.inventory.ContainerOfHolding; import com.minelittlepony.unicopia.inventory.InventoryOfHolding; -import com.minelittlepony.unicopia.inventory.gui.GuiOfHolding; import com.minelittlepony.util.vector.VecHelper; -import net.minecraft.client.Minecraft; -import net.minecraft.client.entity.EntityPlayerSP; import net.minecraft.client.util.ITooltipFlag; + import net.minecraft.creativetab.CreativeTabs; import net.minecraft.entity.Entity; import net.minecraft.entity.item.EntityItem; @@ -38,6 +36,8 @@ import net.minecraft.util.text.TextComponentString; import net.minecraft.util.text.TextComponentTranslation; import net.minecraft.world.IInteractionObject; import net.minecraft.world.World; +import net.minecraftforge.fml.relauncher.Side; +import net.minecraftforge.fml.relauncher.SideOnly; public class ItemOfHolding extends Item implements IMagicalItem { @@ -48,6 +48,7 @@ public class ItemOfHolding extends Item implements IMagicalItem { setMaxStackSize(1); } + @SideOnly(Side.CLIENT) @Override public void addInformation(ItemStack stack, @Nullable World worldIn, List tooltip, ITooltipFlag flagIn) { super.addInformation(stack, worldIn, tooltip, flagIn); @@ -113,14 +114,9 @@ public class ItemOfHolding extends Item implements IMagicalItem { return new ActionResult<>(EnumActionResult.FAIL, stack); } - IInteractionObject inventory = new Inventory(stack); + UClient.instance().displayGuiToPlayer(player, new Inventory(stack)); - if (UClient.isClientSide() && player instanceof EntityPlayerSP) { - Minecraft.getMinecraft().displayGuiScreen(new GuiOfHolding(inventory)); - player.playSound(SoundEvents.BLOCK_ENDERCHEST_OPEN, 0.5F, 1); - } else { - player.displayGui(inventory); - } + player.playSound(SoundEvents.BLOCK_ENDERCHEST_OPEN, 0.5F, 1); return new ActionResult<>(EnumActionResult.SUCCESS, stack); } diff --git a/src/main/java/com/minelittlepony/unicopia/network/MsgPlayerCapabilities.java b/src/main/java/com/minelittlepony/unicopia/network/MsgPlayerCapabilities.java index 3173e6f5..9f4829e9 100644 --- a/src/main/java/com/minelittlepony/unicopia/network/MsgPlayerCapabilities.java +++ b/src/main/java/com/minelittlepony/unicopia/network/MsgPlayerCapabilities.java @@ -12,6 +12,7 @@ import com.minelittlepony.jumpingcastle.api.IChannel; import com.minelittlepony.jumpingcastle.api.IMessage; import com.minelittlepony.jumpingcastle.api.IMessageHandler; import com.minelittlepony.unicopia.Race; +import com.minelittlepony.unicopia.Unicopia; import com.minelittlepony.unicopia.player.IPlayer; import com.minelittlepony.unicopia.player.PlayerSpeciesList; @@ -55,9 +56,8 @@ public class MsgPlayerCapabilities implements IMessage, IMessageHandler 0) { diff --git a/src/main/java/com/minelittlepony/unicopia/network/MsgRequestCapabilities.java b/src/main/java/com/minelittlepony/unicopia/network/MsgRequestCapabilities.java index 792f873b..16bf54d5 100644 --- a/src/main/java/com/minelittlepony/unicopia/network/MsgRequestCapabilities.java +++ b/src/main/java/com/minelittlepony/unicopia/network/MsgRequestCapabilities.java @@ -7,6 +7,7 @@ import com.minelittlepony.jumpingcastle.api.IChannel; import com.minelittlepony.jumpingcastle.api.IMessage; import com.minelittlepony.jumpingcastle.api.IMessageHandler; import com.minelittlepony.unicopia.Race; +import com.minelittlepony.unicopia.Unicopia; import com.minelittlepony.unicopia.player.IPlayer; import com.minelittlepony.unicopia.player.PlayerSpeciesList; @@ -27,7 +28,7 @@ public class MsgRequestCapabilities implements IMessage, IMessageHandler { static final int PARTICLES_ALL = 0;