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;
|
2019-01-29 09:30:20 +01:00
|
|
|
import net.minecraft.block.BlockTallGrass;
|
2019-01-06 22:31:34 +01:00
|
|
|
import net.minecraft.block.state.IBlockState;
|
2019-01-29 12:54:17 +01:00
|
|
|
import net.minecraft.entity.Entity;
|
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.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;
|
2019-01-31 14:57:50 +01:00
|
|
|
import net.minecraft.potion.Potion;
|
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;
|
2019-01-29 14:22:36 +01:00
|
|
|
import net.minecraft.world.biome.Biome;
|
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;
|
2019-01-29 12:54:17 +01:00
|
|
|
import net.minecraftforge.event.entity.living.LivingEntityUseItemEvent;
|
2018-09-16 00:45:44 +02:00
|
|
|
import net.minecraftforge.event.entity.player.PlayerDropsEvent;
|
2018-09-12 22:37:06 +02:00
|
|
|
import net.minecraftforge.event.entity.player.PlayerFlyableFallEvent;
|
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;
|
2019-01-10 18:46:40 +01:00
|
|
|
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
|
2018-09-12 01:29:49 +02:00
|
|
|
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;
|
2019-01-10 18:46:40 +01:00
|
|
|
import net.minecraftforge.fml.common.network.IGuiHandler;
|
|
|
|
import net.minecraftforge.fml.common.network.NetworkRegistry;
|
2018-09-16 00:45:44 +02:00
|
|
|
import net.minecraftforge.fml.common.registry.EntityEntry;
|
2019-01-10 18:46:40 +01:00
|
|
|
import java.util.Map;
|
|
|
|
import java.util.function.Function;
|
|
|
|
|
2019-01-30 11:26:00 +01:00
|
|
|
import org.apache.logging.log4j.LogManager;
|
|
|
|
import org.apache.logging.log4j.Logger;
|
|
|
|
|
2019-01-10 18:46:40 +01:00
|
|
|
import com.google.gson.JsonObject;
|
2018-09-12 01:29:49 +02:00
|
|
|
import com.minelittlepony.jumpingcastle.api.IChannel;
|
|
|
|
import com.minelittlepony.jumpingcastle.api.JumpingCastle;
|
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.command.Commands;
|
2019-02-08 16:56:28 +01:00
|
|
|
import com.minelittlepony.unicopia.enchanting.Pages;
|
2019-01-10 18:46:40 +01:00
|
|
|
import com.minelittlepony.unicopia.enchanting.SpellRecipe;
|
2019-01-07 09:34:58 +01:00
|
|
|
import com.minelittlepony.unicopia.forgebullshit.FBS;
|
2019-01-10 18:46:40 +01:00
|
|
|
import com.minelittlepony.unicopia.inventory.gui.ContainerSpellBook;
|
|
|
|
import com.minelittlepony.unicopia.inventory.gui.GuiSpellBook;
|
2018-09-12 01:29:49 +02:00
|
|
|
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;
|
2019-02-05 10:20:55 +01:00
|
|
|
import com.minelittlepony.unicopia.spell.SpellRegistry;
|
2019-01-10 18:46:40 +01:00
|
|
|
import com.minelittlepony.unicopia.util.crafting.CraftingManager;
|
2019-02-09 19:50:01 +01:00
|
|
|
import com.minelittlepony.unicopia.world.UWorld;
|
2018-09-12 01:29:49 +02:00
|
|
|
|
2019-01-08 09:33:46 +01:00
|
|
|
@Mod(
|
|
|
|
modid = Unicopia.MODID,
|
|
|
|
name = Unicopia.NAME,
|
|
|
|
version = Unicopia.VERSION,
|
|
|
|
dependencies = "required-after:jumpingcastle"
|
|
|
|
)
|
2018-09-12 01:29:49 +02:00
|
|
|
@EventBusSubscriber
|
2019-01-10 18:46:40 +01:00
|
|
|
public class Unicopia implements IGuiHandler {
|
2018-09-12 01:29:49 +02:00
|
|
|
public static final String MODID = "unicopia";
|
|
|
|
public static final String NAME = "@NAME@";
|
|
|
|
public static final String VERSION = "@VERSION@";
|
|
|
|
|
2019-01-30 11:26:00 +01:00
|
|
|
public static final Logger log = LogManager.getLogger();
|
2018-09-12 01:29:49 +02:00
|
|
|
|
2019-01-30 11:26:00 +01:00
|
|
|
public static IChannel channel;
|
2018-09-24 21:37:50 +02:00
|
|
|
|
2019-01-10 18:46:40 +01:00
|
|
|
private static CraftingManager craftingManager;
|
|
|
|
|
2018-09-12 01:29:49 +02:00
|
|
|
@EventHandler
|
|
|
|
public void preInit(FMLPreInitializationEvent event) {
|
2019-01-13 21:07:44 +01:00
|
|
|
UConfig.init(event.getModConfigurationDirectory());
|
2019-01-30 11:26:00 +01:00
|
|
|
UClient.instance().preInit(event);
|
2018-09-24 21:37:50 +02:00
|
|
|
}
|
|
|
|
|
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
|
|
|
|
|
|
|
PowersRegistry.instance().init();
|
|
|
|
|
2018-09-19 09:09:30 +02:00
|
|
|
UAdvancements.init();
|
|
|
|
|
2018-09-12 01:29:49 +02:00
|
|
|
FBS.init();
|
2019-01-10 18:46:40 +01:00
|
|
|
|
|
|
|
NetworkRegistry.INSTANCE.registerGuiHandler(this, this);
|
2019-01-30 11:26:00 +01:00
|
|
|
|
|
|
|
UClient.instance().init(event);
|
2019-01-10 18:46:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
@EventHandler
|
|
|
|
public void posInit(FMLPostInitializationEvent event) {
|
|
|
|
craftingManager = new CraftingManager(MODID, "enchanting") {
|
|
|
|
@Override
|
|
|
|
protected void registerRecipeTypes(Map<String, Function<JsonObject, IRecipe>> types) {
|
|
|
|
super.registerRecipeTypes(types);
|
|
|
|
|
|
|
|
types.put("unicopia:crafting_spell", SpellRecipe::deserialize);
|
|
|
|
}
|
|
|
|
};
|
2019-01-29 14:22:36 +01:00
|
|
|
|
2019-02-08 16:56:28 +01:00
|
|
|
Pages.instance().load();
|
|
|
|
|
2019-01-29 14:22:36 +01:00
|
|
|
Biome.REGISTRY.forEach(UEntities::registerSpawnEntries);
|
2019-01-30 11:26:00 +01:00
|
|
|
UClient.instance().posInit(event);
|
2019-02-01 17:29:58 +01:00
|
|
|
|
|
|
|
UItems.fixRecipes();
|
2019-01-10 18:46:40 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
public static CraftingManager getCraftingManager() {
|
|
|
|
return craftingManager;
|
2018-09-12 01:29:49 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@SubscribeEvent
|
2019-01-29 14:22:36 +01:00
|
|
|
public static void registerItems(RegistryEvent.Register<Item> event) {
|
2019-01-31 14:57:50 +01:00
|
|
|
UItems.init(event.getRegistry());
|
2018-09-16 00:45:44 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
@SubscribeEvent
|
2019-01-29 14:22:36 +01:00
|
|
|
public static void registerBlocks(RegistryEvent.Register<Block> event) {
|
2019-01-31 14:57:50 +01:00
|
|
|
UBlocks.init(event.getRegistry());
|
2018-09-16 00:45:44 +02:00
|
|
|
}
|
|
|
|
|
2019-01-31 14:57:50 +01:00
|
|
|
@SubscribeEvent
|
|
|
|
public static void registerPotions(RegistryEvent.Register<Potion> event) {
|
|
|
|
UEffects.init(event.getRegistry());
|
2018-09-19 09:09:30 +02:00
|
|
|
}
|
|
|
|
|
2018-09-25 00:22:04 +02:00
|
|
|
@SubscribeEvent
|
2019-01-29 14:22:36 +01:00
|
|
|
public static void registerSounds(RegistryEvent.Register<SoundEvent> event) {
|
2018-09-25 00:22:04 +02:00
|
|
|
USounds.init(event.getRegistry());
|
|
|
|
}
|
|
|
|
|
2018-09-16 00:45:44 +02:00
|
|
|
@SubscribeEvent
|
2019-01-29 14:22:36 +01:00
|
|
|
public static void registerEntities(RegistryEvent.Register<EntityEntry> event) {
|
2018-09-16 00:45:44 +02:00
|
|
|
UEntities.init(event.getRegistry());
|
2018-09-12 01:29:49 +02:00
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
|
2019-01-29 09:30:20 +01:00
|
|
|
int fortuneFactor = 1 + event.getFortuneLevel() * 15;
|
2018-09-20 22:49:10 +02:00
|
|
|
|
2019-01-29 09:30:20 +01:00
|
|
|
if (block == Blocks.STONE) {
|
2018-09-20 22:49:10 +02:00
|
|
|
if (event.getWorld().rand.nextInt(500 / fortuneFactor) == 0) {
|
|
|
|
for (int i = 0; i < 1 + event.getFortuneLevel(); i++) {
|
|
|
|
if (event.getWorld().rand.nextInt(10) > 3) {
|
2019-02-05 10:20:55 +01:00
|
|
|
event.getDrops().add(new ItemStack(UItems.curse));
|
2018-09-20 22:49:10 +02:00
|
|
|
} else {
|
2019-02-05 10:20:55 +01:00
|
|
|
event.getDrops().add(new ItemStack(UItems.spell));
|
2018-09-20 22:49:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-02-05 10:20:55 +01:00
|
|
|
|
|
|
|
if (event.getWorld().rand.nextInt(5000) == 0) {
|
|
|
|
event.getDrops().add(SpellRegistry.instance().enchantStack(new ItemStack(UItems.spell), "awkward"));
|
|
|
|
}
|
2019-01-29 09:30:20 +01:00
|
|
|
} else if (block instanceof BlockTallGrass) {
|
|
|
|
if (event.getWorld().rand.nextInt(25 / fortuneFactor) == 0) {
|
2018-09-26 20:53:35 +02:00
|
|
|
for (int i = 0; i < 1 + event.getFortuneLevel(); i++) {
|
2019-01-29 09:30:20 +01:00
|
|
|
int chance = event.getWorld().rand.nextInt(3);
|
|
|
|
if (chance == 0) {
|
2019-02-05 10:20:55 +01:00
|
|
|
event.getDrops().add(new ItemStack(UItems.alfalfa_seeds));
|
2019-01-29 09:30:20 +01:00
|
|
|
} else if (chance == 1) {
|
2019-02-05 10:20:55 +01:00
|
|
|
event.getDrops().add(new ItemStack(UItems.apple_seeds));
|
2019-01-29 09:30:20 +01:00
|
|
|
} else {
|
2019-02-05 10:20:55 +01:00
|
|
|
event.getDrops().add(new ItemStack(UItems.tomato_seeds));
|
2019-01-29 09:30:20 +01:00
|
|
|
}
|
2018-09-26 20:53:35 +02:00
|
|
|
}
|
|
|
|
}
|
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);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-02-09 19:50:01 +01:00
|
|
|
@SubscribeEvent
|
|
|
|
public static void onWorldTick(TickEvent.WorldTickEvent event) {
|
|
|
|
if (event.phase == Phase.START) {
|
|
|
|
UWorld.tick(event.world);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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();
|
|
|
|
|
2019-01-27 16:35:01 +01:00
|
|
|
event.getDrops().stream()
|
|
|
|
.map(PlayerSpeciesList.instance()::getEntity)
|
|
|
|
.forEach(item -> item.setPlayerSpecies(race));
|
2018-09-16 00:45:44 +02:00
|
|
|
}
|
|
|
|
|
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
|
2019-01-30 11:26:00 +01:00
|
|
|
public void onServerStart(FMLServerStartingEvent event) {
|
2018-09-12 01:29:49 +02:00
|
|
|
Commands.init(event);
|
|
|
|
}
|
|
|
|
|
2019-02-01 09:38:45 +01:00
|
|
|
@SubscribeEvent
|
|
|
|
public static void onItemUseBegin(LivingEntityUseItemEvent.Start event) {
|
|
|
|
Entity e = event.getEntity();
|
|
|
|
|
|
|
|
if (!event.isCanceled() && e instanceof EntityPlayer) {
|
|
|
|
PlayerSpeciesList.instance().getPlayer((EntityPlayer)e).getFood().begin(event.getItem());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@SubscribeEvent
|
|
|
|
public static void onItemUseCancel(LivingEntityUseItemEvent.Stop event) {
|
|
|
|
Entity e = event.getEntity();
|
|
|
|
|
|
|
|
if (!event.isCanceled() && e instanceof EntityPlayer) {
|
|
|
|
PlayerSpeciesList.instance().getPlayer((EntityPlayer)e).getFood().end();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2018-09-12 22:37:06 +02:00
|
|
|
@SubscribeEvent
|
2019-01-29 12:54:17 +01:00
|
|
|
public static void onItemUseFinish(LivingEntityUseItemEvent.Finish event) {
|
|
|
|
Entity e = event.getEntity();
|
|
|
|
|
2019-02-01 09:38:45 +01:00
|
|
|
if (!event.isCanceled() && e instanceof EntityPlayer) {
|
|
|
|
PlayerSpeciesList.instance().getPlayer((EntityPlayer)e).getFood().finish();
|
2018-09-12 01:29:49 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2019-01-10 18:46:40 +01:00
|
|
|
@Override
|
|
|
|
public Object getServerGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
|
|
|
|
switch (ID) {
|
|
|
|
case 0: return new ContainerSpellBook(player.inventory, world, new BlockPos(x, y, z));
|
|
|
|
default: return null;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Object getClientGuiElement(int ID, EntityPlayer player, World world, int x, int y, int z) {
|
|
|
|
switch (ID) {
|
|
|
|
case 0: return new GuiSpellBook(player);
|
|
|
|
default: return null;
|
|
|
|
}
|
|
|
|
}
|
2018-09-12 01:29:49 +02:00
|
|
|
}
|