2018-09-12 01:29:49 +02:00
|
|
|
package com.minelittlepony.unicopia;
|
|
|
|
|
2018-09-16 00:45:44 +02:00
|
|
|
import net.minecraft.block.Block;
|
2018-09-26 20:53:35 +02:00
|
|
|
import net.minecraft.block.BlockCrops;
|
2019-01-06 22:31:34 +01:00
|
|
|
import net.minecraft.block.state.IBlockState;
|
2018-09-12 22:37:06 +02:00
|
|
|
import net.minecraft.client.Minecraft;
|
2018-09-27 22:12:32 +02:00
|
|
|
import net.minecraft.entity.player.EntityPlayer;
|
2018-09-20 22:49:10 +02:00
|
|
|
import net.minecraft.init.Blocks;
|
2018-09-12 01:29:49 +02:00
|
|
|
import net.minecraft.item.EnumAction;
|
|
|
|
import net.minecraft.item.Item;
|
2018-09-20 22:49:10 +02:00
|
|
|
import net.minecraft.item.ItemStack;
|
2018-09-19 09:09:30 +02:00
|
|
|
import net.minecraft.item.crafting.IRecipe;
|
2018-09-25 00:22:04 +02:00
|
|
|
import net.minecraft.util.SoundEvent;
|
2019-01-06 22:31:34 +01:00
|
|
|
import net.minecraft.util.math.BlockPos;
|
|
|
|
import net.minecraft.world.World;
|
2018-09-20 22:49:10 +02:00
|
|
|
import net.minecraftforge.client.event.ColorHandlerEvent;
|
2018-09-27 22:12:32 +02:00
|
|
|
import net.minecraftforge.client.event.EntityViewRenderEvent;
|
2018-09-16 00:45:44 +02:00
|
|
|
import net.minecraftforge.client.event.FOVUpdateEvent;
|
2018-09-25 00:22:04 +02:00
|
|
|
import net.minecraftforge.client.event.RenderGameOverlayEvent;
|
|
|
|
import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType;
|
2018-09-12 01:29:49 +02:00
|
|
|
import net.minecraftforge.event.RegistryEvent;
|
2018-09-16 00:45:44 +02:00
|
|
|
import net.minecraftforge.event.entity.item.ItemTossEvent;
|
|
|
|
import net.minecraftforge.event.entity.player.PlayerDropsEvent;
|
2018-09-12 22:37:06 +02:00
|
|
|
import net.minecraftforge.event.entity.player.PlayerFlyableFallEvent;
|
2018-09-12 01:29:49 +02:00
|
|
|
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
|
2019-01-06 22:31:34 +01:00
|
|
|
import net.minecraftforge.event.entity.player.UseHoeEvent;
|
2018-09-20 22:49:10 +02:00
|
|
|
import net.minecraftforge.event.world.BlockEvent;
|
2018-09-12 01:29:49 +02:00
|
|
|
import net.minecraftforge.fml.common.Mod;
|
|
|
|
import net.minecraftforge.fml.common.Mod.EventBusSubscriber;
|
|
|
|
import net.minecraftforge.fml.common.Mod.EventHandler;
|
|
|
|
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
|
|
|
|
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
|
|
|
|
import net.minecraftforge.fml.common.event.FMLServerStartingEvent;
|
2019-01-06 22:31:34 +01:00
|
|
|
import net.minecraftforge.fml.common.eventhandler.Event.Result;
|
2018-09-12 01:29:49 +02:00
|
|
|
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
|
|
|
|
import net.minecraftforge.fml.common.gameevent.TickEvent;
|
|
|
|
import net.minecraftforge.fml.common.gameevent.TickEvent.Phase;
|
2018-09-16 00:45:44 +02:00
|
|
|
import net.minecraftforge.fml.common.registry.EntityEntry;
|
2018-09-12 01:29:49 +02:00
|
|
|
import net.minecraftforge.fml.relauncher.Side;
|
|
|
|
import net.minecraftforge.fml.relauncher.SideOnly;
|
|
|
|
|
|
|
|
import com.minelittlepony.jumpingcastle.api.IChannel;
|
|
|
|
import com.minelittlepony.jumpingcastle.api.JumpingCastle;
|
2018-09-12 22:37:06 +02:00
|
|
|
import com.minelittlepony.jumpingcastle.api.Target;
|
2018-09-19 09:09:30 +02:00
|
|
|
import com.minelittlepony.unicopia.advancements.UAdvancements;
|
2019-01-06 22:31:34 +01:00
|
|
|
import com.minelittlepony.unicopia.block.ITillable;
|
2018-09-12 01:29:49 +02:00
|
|
|
import com.minelittlepony.unicopia.client.particle.EntityMagicFX;
|
2018-09-16 00:45:44 +02:00
|
|
|
import com.minelittlepony.unicopia.client.particle.EntityRaindropFX;
|
2018-09-12 01:29:49 +02:00
|
|
|
import com.minelittlepony.unicopia.client.particle.Particles;
|
|
|
|
import com.minelittlepony.unicopia.command.Commands;
|
2019-01-07 09:34:58 +01:00
|
|
|
import com.minelittlepony.unicopia.forgebullshit.FBS;
|
2018-09-25 00:22:04 +02:00
|
|
|
import com.minelittlepony.unicopia.hud.UHud;
|
2018-09-12 01:29:49 +02:00
|
|
|
import com.minelittlepony.unicopia.input.Keyboard;
|
|
|
|
import com.minelittlepony.unicopia.network.MsgPlayerAbility;
|
|
|
|
import com.minelittlepony.unicopia.network.MsgPlayerCapabilities;
|
2018-09-12 22:37:06 +02:00
|
|
|
import com.minelittlepony.unicopia.network.MsgRequestCapabilities;
|
2018-09-25 00:22:04 +02:00
|
|
|
import com.minelittlepony.unicopia.player.IPlayer;
|
2018-09-12 01:29:49 +02:00
|
|
|
import com.minelittlepony.unicopia.player.PlayerSpeciesList;
|
|
|
|
import com.minelittlepony.unicopia.power.PowersRegistry;
|
2018-09-24 21:37:50 +02:00
|
|
|
import com.minelittlepony.pony.data.IPony;
|
2018-09-12 01:29:49 +02:00
|
|
|
|
|
|
|
@Mod(modid = Unicopia.MODID, name = Unicopia.NAME, version = Unicopia.VERSION)
|
|
|
|
@EventBusSubscriber
|
|
|
|
public class Unicopia {
|
|
|
|
public static final String MODID = "unicopia";
|
|
|
|
public static final String NAME = "@NAME@";
|
|
|
|
public static final String VERSION = "@VERSION@";
|
|
|
|
|
|
|
|
public static IChannel channel;
|
|
|
|
|
|
|
|
public static int MAGIC_PARTICLE;
|
2018-09-16 00:45:44 +02:00
|
|
|
public static int RAIN_PARTICLE;
|
2018-09-12 01:29:49 +02:00
|
|
|
|
2018-09-24 21:37:50 +02:00
|
|
|
/**
|
|
|
|
* 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();
|
|
|
|
|
2018-09-12 01:29:49 +02:00
|
|
|
@EventHandler
|
|
|
|
public void preInit(FMLPreInitializationEvent event) {
|
2018-09-16 00:45:44 +02:00
|
|
|
if (UClient.isClientSide()) {
|
|
|
|
UEntities.preInit();
|
|
|
|
}
|
2018-09-12 01:29:49 +02:00
|
|
|
}
|
|
|
|
|
2018-09-24 21:37:50 +02:00
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
private static Race getclientPlayerRace() {
|
|
|
|
if (Minecraft.getMinecraft().player != null && MineLP.modIsActive()) {
|
|
|
|
return Race.fromPonyRace(IPony.forPlayer(Minecraft.getMinecraft().player).getRace(false));
|
|
|
|
}
|
|
|
|
|
|
|
|
return Race.HUMAN;
|
|
|
|
}
|
|
|
|
|
2018-09-12 01:29:49 +02:00
|
|
|
@EventHandler
|
|
|
|
public void init(FMLInitializationEvent event) {
|
2018-09-25 00:22:04 +02:00
|
|
|
channel = JumpingCastle.subscribeTo(MODID, () -> {})
|
2018-09-20 22:49:10 +02:00
|
|
|
.listenFor(MsgRequestCapabilities.class)
|
|
|
|
.listenFor(MsgPlayerCapabilities.class)
|
|
|
|
.listenFor(MsgPlayerAbility.class);
|
2018-09-12 01:29:49 +02:00
|
|
|
|
|
|
|
MAGIC_PARTICLE = Particles.instance().registerParticle(new EntityMagicFX.Factory());
|
2018-09-16 00:45:44 +02:00
|
|
|
RAIN_PARTICLE = Particles.instance().registerParticle(new EntityRaindropFX.Factory());
|
2018-09-12 01:29:49 +02:00
|
|
|
|
|
|
|
PowersRegistry.instance().init();
|
|
|
|
|
2018-09-19 09:09:30 +02:00
|
|
|
UAdvancements.init();
|
|
|
|
|
2018-09-12 01:29:49 +02:00
|
|
|
FBS.init();
|
|
|
|
}
|
|
|
|
|
|
|
|
@SubscribeEvent
|
|
|
|
public static void registerItemsStatic(RegistryEvent.Register<Item> event) {
|
2018-09-16 00:45:44 +02:00
|
|
|
UItems.registerItems(event.getRegistry());
|
|
|
|
}
|
|
|
|
|
2018-09-20 22:49:10 +02:00
|
|
|
@SubscribeEvent
|
|
|
|
public static void registerItemColoursStatic(ColorHandlerEvent.Item event) {
|
|
|
|
UItems.registerColors(event.getItemColors());
|
|
|
|
}
|
|
|
|
|
2018-09-16 00:45:44 +02:00
|
|
|
@SubscribeEvent
|
|
|
|
public static void registerBlocksStatic(RegistryEvent.Register<Block> event) {
|
|
|
|
UBlocks.registerBlocks(event.getRegistry());
|
|
|
|
}
|
|
|
|
|
2018-09-19 09:09:30 +02:00
|
|
|
@SubscribeEvent
|
2018-09-25 00:22:04 +02:00
|
|
|
public static void registerSounds(RegistryEvent.Register<IRecipe> event) {
|
2018-09-19 09:09:30 +02:00
|
|
|
UItems.registerRecipes(event.getRegistry());
|
|
|
|
}
|
|
|
|
|
2018-09-25 00:22:04 +02:00
|
|
|
@SubscribeEvent
|
|
|
|
public static void registerRecipesStatic(RegistryEvent.Register<SoundEvent> event) {
|
|
|
|
USounds.init(event.getRegistry());
|
|
|
|
}
|
|
|
|
|
2018-09-16 00:45:44 +02:00
|
|
|
@SubscribeEvent
|
|
|
|
public static void registerEntitiesStatic(RegistryEvent.Register<EntityEntry> event) {
|
|
|
|
UEntities.init(event.getRegistry());
|
2018-09-12 01:29:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
@SubscribeEvent
|
|
|
|
public static void onGameTick(TickEvent.ClientTickEvent event) {
|
2018-09-24 21:37:50 +02:00
|
|
|
Race newRace = getclientPlayerRace();
|
|
|
|
|
2018-09-25 00:22:04 +02:00
|
|
|
if (newRace != clientPlayerRace && Minecraft.getMinecraft().player != null) {
|
2018-09-24 21:37:50 +02:00
|
|
|
clientPlayerRace = newRace;
|
|
|
|
|
|
|
|
channel.send(new MsgRequestCapabilities(Minecraft.getMinecraft().player, clientPlayerRace), Target.SERVER);
|
|
|
|
}
|
|
|
|
|
2018-09-12 01:29:49 +02:00
|
|
|
if (event.phase == Phase.END) {
|
|
|
|
Keyboard.getKeyHandler().onKeyInput();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-27 22:12:32 +02:00
|
|
|
@SideOnly(Side.CLIENT)
|
|
|
|
@SubscribeEvent
|
|
|
|
public static void setupPlayerCamera(EntityViewRenderEvent.CameraSetup event) {
|
|
|
|
|
|
|
|
EntityPlayer player = Minecraft.getMinecraft().player;
|
|
|
|
|
|
|
|
if (player != null) {
|
|
|
|
event.setRoll((float)PlayerSpeciesList.instance().getPlayer(player).getCamera().calculateRoll(player));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-20 22:49:10 +02:00
|
|
|
@SubscribeEvent
|
|
|
|
public static void onBlockHarvested(BlockEvent.HarvestDropsEvent event) {
|
2018-09-26 20:53:35 +02:00
|
|
|
Block block = event.getState().getBlock();
|
|
|
|
|
|
|
|
if (block == Blocks.STONE) {
|
2018-09-20 22:49:10 +02:00
|
|
|
int fortuneFactor = 1 + event.getFortuneLevel() * 15;
|
|
|
|
|
|
|
|
if (event.getWorld().rand.nextInt(500 / fortuneFactor) == 0) {
|
|
|
|
for (int i = 0; i < 1 + event.getFortuneLevel(); i++) {
|
|
|
|
if (event.getWorld().rand.nextInt(10) > 3) {
|
|
|
|
event.getDrops().add(new ItemStack(UItems.curse, 1));
|
|
|
|
} else {
|
|
|
|
event.getDrops().add(new ItemStack(UItems.spell, 1));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2018-09-26 20:53:35 +02:00
|
|
|
} else if (block instanceof BlockCrops) {
|
|
|
|
int fortuneFactor = 1 + event.getFortuneLevel() * 15;
|
|
|
|
|
|
|
|
if (event.getWorld().rand.nextInt(500 / fortuneFactor) == 0) {
|
|
|
|
for (int i = 0; i < 1 + event.getFortuneLevel(); i++) {
|
|
|
|
event.getDrops().add(new ItemStack(UItems.alfalfa_seeds, 1));
|
|
|
|
}
|
|
|
|
}
|
2018-09-20 22:49:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-06 22:31:34 +01:00
|
|
|
@SubscribeEvent
|
|
|
|
public static void onBlockTilled(UseHoeEvent event) {
|
|
|
|
BlockPos pos = event.getPos();
|
|
|
|
World world = event.getWorld();
|
|
|
|
|
|
|
|
IBlockState state = world.getBlockState(pos);
|
|
|
|
|
|
|
|
if (state.getBlock() instanceof ITillable) {
|
|
|
|
ITillable farm = ((ITillable)state.getBlock());
|
|
|
|
|
|
|
|
if (farm.canBeTilled(event.getCurrent(), event.getEntityPlayer(), world, state, pos)) {
|
|
|
|
|
|
|
|
world.setBlockState(pos, farm.getFarmlandState(event.getCurrent(), event.getEntityPlayer(), world, state, pos));
|
|
|
|
|
|
|
|
event.setResult(Result.ALLOW);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-12 01:29:49 +02:00
|
|
|
@SubscribeEvent
|
2018-09-12 22:37:06 +02:00
|
|
|
public static void onPlayerTick(TickEvent.PlayerTickEvent event) {
|
2018-09-12 01:29:49 +02:00
|
|
|
if (event.phase == Phase.END) {
|
2018-09-20 16:28:17 +02:00
|
|
|
PlayerSpeciesList.instance().getPlayer(event.player).onUpdate(event.player);
|
|
|
|
} else {
|
|
|
|
PlayerSpeciesList.instance().getPlayer(event.player).beforeUpdate(event.player);
|
2018-09-12 01:29:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-16 00:45:44 +02:00
|
|
|
@SubscribeEvent
|
|
|
|
public static void onPlayerTossItem(ItemTossEvent event) {
|
|
|
|
Race race = PlayerSpeciesList.instance().getPlayer(event.getPlayer()).getPlayerSpecies();
|
|
|
|
|
|
|
|
PlayerSpeciesList.instance().getEntity(event.getEntityItem()).setPlayerSpecies(race);
|
|
|
|
}
|
|
|
|
|
|
|
|
@SubscribeEvent
|
|
|
|
public static void onPlayerDropItems(PlayerDropsEvent event) {
|
|
|
|
|
|
|
|
Race race = PlayerSpeciesList.instance().getPlayer(event.getEntityPlayer()).getPlayerSpecies();
|
|
|
|
|
|
|
|
event.getDrops().stream().map(PlayerSpeciesList.instance()::getEntity).forEach(item -> {
|
|
|
|
item.setPlayerSpecies(race);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2018-09-12 22:37:06 +02:00
|
|
|
@SubscribeEvent
|
|
|
|
public static void onPlayerFall(PlayerFlyableFallEvent event) {
|
|
|
|
PlayerSpeciesList.instance()
|
|
|
|
.getPlayer(event.getEntityPlayer())
|
|
|
|
.onFall(event.getDistance(), event.getMultiplier());
|
|
|
|
}
|
|
|
|
|
2018-09-12 01:29:49 +02:00
|
|
|
@EventHandler
|
|
|
|
public void onServerStarted(FMLServerStartingEvent event) {
|
|
|
|
Commands.init(event);
|
|
|
|
}
|
|
|
|
|
2018-09-25 00:22:04 +02:00
|
|
|
@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());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-12 22:37:06 +02:00
|
|
|
@SubscribeEvent
|
|
|
|
public static void onPlayerRightClick(PlayerInteractEvent.RightClickItem event) {
|
2018-09-12 01:29:49 +02:00
|
|
|
// Why won't you run!?
|
2018-09-12 22:37:06 +02:00
|
|
|
if (!event.isCanceled() && event.getItemStack().getItemUseAction() == EnumAction.EAT) {
|
|
|
|
PlayerSpeciesList.instance()
|
|
|
|
.getPlayer(event.getEntityPlayer())
|
|
|
|
.onEntityEat();
|
2018-09-12 01:29:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-13 14:04:24 +02:00
|
|
|
@SubscribeEvent
|
2018-09-16 00:45:44 +02:00
|
|
|
public static void modifyFOV(FOVUpdateEvent event) {
|
|
|
|
float fov = event.getFov();
|
2018-09-13 14:04:24 +02:00
|
|
|
|
2018-09-16 00:45:44 +02:00
|
|
|
fov += PlayerSpeciesList.instance().getPlayer(event.getEntity()).getExertion() / 5;
|
2018-09-13 14:04:24 +02:00
|
|
|
|
2018-09-16 00:45:44 +02:00
|
|
|
event.setNewfov(fov);
|
2018-09-13 14:04:24 +02:00
|
|
|
}
|
2018-09-12 01:29:49 +02:00
|
|
|
}
|