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-12 22:37:06 +02:00
|
|
|
import net.minecraft.client.Minecraft;
|
2018-09-12 01:29:49 +02:00
|
|
|
import net.minecraft.entity.Entity;
|
|
|
|
import net.minecraft.item.EnumAction;
|
|
|
|
import net.minecraft.item.Item;
|
2018-09-16 00:45:44 +02:00
|
|
|
import net.minecraftforge.client.event.FOVUpdateEvent;
|
2018-09-12 01:29:49 +02:00
|
|
|
import net.minecraftforge.event.AttachCapabilitiesEvent;
|
|
|
|
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 01:29:49 +02:00
|
|
|
import net.minecraftforge.event.entity.player.PlayerEvent;
|
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;
|
|
|
|
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;
|
|
|
|
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-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;
|
|
|
|
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-12 01:29:49 +02:00
|
|
|
import com.minelittlepony.unicopia.player.PlayerSpeciesList;
|
|
|
|
import com.minelittlepony.unicopia.power.PowersRegistry;
|
|
|
|
|
|
|
|
import come.minelittlepony.unicopia.forgebullshit.FBS;
|
|
|
|
|
|
|
|
@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
|
|
|
|
|
|
|
@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
|
|
|
}
|
|
|
|
|
|
|
|
@EventHandler
|
|
|
|
public void init(FMLInitializationEvent event) {
|
2018-09-12 22:37:06 +02:00
|
|
|
channel = JumpingCastle.listen(MODID, () -> {
|
|
|
|
channel.send(new MsgRequestCapabilities(Minecraft.getMinecraft().player), Target.SERVER);
|
2018-09-12 01:29:49 +02:00
|
|
|
})
|
2018-09-12 22:37:06 +02:00
|
|
|
// client ------> server
|
|
|
|
.consume(MsgRequestCapabilities.class)
|
|
|
|
|
|
|
|
// client <------ server
|
|
|
|
.consume(MsgPlayerCapabilities.class)
|
|
|
|
|
|
|
|
// client ------> server
|
|
|
|
.consume(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();
|
|
|
|
|
|
|
|
FBS.init();
|
|
|
|
}
|
|
|
|
|
|
|
|
@SubscribeEvent
|
|
|
|
public static void registerItemsStatic(RegistryEvent.Register<Item> event) {
|
2018-09-16 00:45:44 +02:00
|
|
|
UItems.registerItems(event.getRegistry());
|
|
|
|
}
|
|
|
|
|
|
|
|
@SubscribeEvent
|
|
|
|
public static void registerBlocksStatic(RegistryEvent.Register<Block> event) {
|
|
|
|
UBlocks.registerBlocks(event.getRegistry());
|
|
|
|
}
|
|
|
|
|
|
|
|
@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) {
|
|
|
|
if (event.phase == Phase.END) {
|
|
|
|
Keyboard.getKeyHandler().onKeyInput();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@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-12 22:37:06 +02:00
|
|
|
PlayerSpeciesList.instance()
|
|
|
|
.getPlayer(event.player)
|
|
|
|
.onUpdate(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-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
|
|
|
@SubscribeEvent
|
|
|
|
public static void attachCapabilities(AttachCapabilitiesEvent<Entity> event) {
|
|
|
|
FBS.attach(event);
|
|
|
|
}
|
|
|
|
|
|
|
|
@SubscribeEvent
|
|
|
|
public static void clonePlayer(PlayerEvent.Clone event) {
|
|
|
|
FBS.clone(event);
|
|
|
|
}
|
|
|
|
}
|