Cleaned up event classes and stuff

This commit is contained in:
Ellpeck 2016-07-03 20:57:00 +02:00
parent 8aa04b7652
commit 050f963940
23 changed files with 532 additions and 680 deletions

View file

@ -18,7 +18,7 @@ import de.ellpeck.actuallyadditions.mod.config.ConfigurationHandler;
import de.ellpeck.actuallyadditions.mod.crafting.CrusherCrafting; import de.ellpeck.actuallyadditions.mod.crafting.CrusherCrafting;
import de.ellpeck.actuallyadditions.mod.crafting.InitCrafting; import de.ellpeck.actuallyadditions.mod.crafting.InitCrafting;
import de.ellpeck.actuallyadditions.mod.crafting.ItemCrafting; import de.ellpeck.actuallyadditions.mod.crafting.ItemCrafting;
import de.ellpeck.actuallyadditions.mod.event.InitEvents; import de.ellpeck.actuallyadditions.mod.event.CommonEvents;
import de.ellpeck.actuallyadditions.mod.fluids.InitFluids; import de.ellpeck.actuallyadditions.mod.fluids.InitFluids;
import de.ellpeck.actuallyadditions.mod.gen.InitVillager; import de.ellpeck.actuallyadditions.mod.gen.InitVillager;
import de.ellpeck.actuallyadditions.mod.gen.OreGen; import de.ellpeck.actuallyadditions.mod.gen.OreGen;
@ -88,7 +88,7 @@ public class ActuallyAdditions{
FuelHandler.init(); FuelHandler.init();
BannerHelper.init(); BannerHelper.init();
SoundHandler.init(); SoundHandler.init();
UpdateChecker.init(); new UpdateChecker();
proxy.preInit(event); proxy.preInit(event);
ModUtil.LOGGER.info("PreInitialization Finished."); ModUtil.LOGGER.info("PreInitialization Finished.");
@ -101,9 +101,9 @@ public class ActuallyAdditions{
InitOreDict.init(); InitOreDict.init();
InitAchievements.init(); InitAchievements.init();
GuiHandler.init(); GuiHandler.init();
OreGen.init(); new OreGen();
TileEntityBase.init(); TileEntityBase.init();
InitEvents.init(); new CommonEvents();
InitCrafting.init(); InitCrafting.init();
DungeonLoot.init(); DungeonLoot.init();

View file

@ -12,6 +12,7 @@ package de.ellpeck.actuallyadditions.mod.config;
import de.ellpeck.actuallyadditions.mod.util.ModUtil; import de.ellpeck.actuallyadditions.mod.util.ModUtil;
import de.ellpeck.actuallyadditions.mod.util.Util; import de.ellpeck.actuallyadditions.mod.util.Util;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.config.Configuration; import net.minecraftforge.common.config.Configuration;
import net.minecraftforge.fml.client.event.ConfigChangedEvent; import net.minecraftforge.fml.client.event.ConfigChangedEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
@ -25,7 +26,7 @@ public class ConfigurationHandler{
public ConfigurationHandler(File configFile){ public ConfigurationHandler(File configFile){
ModUtil.LOGGER.info("Grabbing Configurations..."); ModUtil.LOGGER.info("Grabbing Configurations...");
Util.registerEvent(this); MinecraftForge.EVENT_BUS.register(this);
config = new Configuration(configFile); config = new Configuration(configFile);
config.load(); config.load();

View file

@ -1,31 +0,0 @@
/*
* This file ("BreakEvent.java") is part of the Actually Additions mod for Minecraft.
* It is created and owned by Ellpeck and distributed
* under the Actually Additions License to be found at
* http://ellpeck.de/actaddlicense
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
* © 2015-2016 Ellpeck
*/
package de.ellpeck.actuallyadditions.mod.event;
import de.ellpeck.actuallyadditions.mod.items.InitItems;
import de.ellpeck.actuallyadditions.mod.items.metalists.TheMiscItems;
import net.minecraft.block.state.IBlockState;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraftforge.event.world.BlockEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
public class BreakEvent{
@SubscribeEvent
public void onBlockBreakEvent(BlockEvent.HarvestDropsEvent event){
IBlockState state = event.getState();
if(state != null && state.getBlock() == Blocks.MOB_SPAWNER){
event.getDrops().add(new ItemStack(InitItems.itemMisc, 1, TheMiscItems.SPAWNER_SHARD.ordinal()));
}
}
}

View file

@ -1,5 +1,5 @@
/* /*
* This file ("TooltipEvent.java") is part of the Actually Additions mod for Minecraft. * This file ("ClientEvents.java") is part of the Actually Additions mod for Minecraft.
* It is created and owned by Ellpeck and distributed * It is created and owned by Ellpeck and distributed
* under the Actually Additions License to be found at * under the Actually Additions License to be found at
* http://ellpeck.de/actaddlicense * http://ellpeck.de/actaddlicense
@ -10,21 +10,37 @@
package de.ellpeck.actuallyadditions.mod.event; package de.ellpeck.actuallyadditions.mod.event;
import de.ellpeck.actuallyadditions.mod.blocks.IHudDisplay;
import de.ellpeck.actuallyadditions.mod.config.values.ConfigBoolValues; import de.ellpeck.actuallyadditions.mod.config.values.ConfigBoolValues;
import de.ellpeck.actuallyadditions.mod.tile.IEnergyDisplay;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityBase;
import de.ellpeck.actuallyadditions.mod.util.ModUtil; import de.ellpeck.actuallyadditions.mod.util.ModUtil;
import de.ellpeck.actuallyadditions.mod.util.PosUtil;
import de.ellpeck.actuallyadditions.mod.util.StringUtil; import de.ellpeck.actuallyadditions.mod.util.StringUtil;
import net.minecraft.block.Block;
import net.minecraft.block.BlockRedstoneTorch;
import net.minecraft.client.Minecraft; import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.gui.GuiScreen;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.Item; import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.profiler.Profiler;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.text.TextFormatting; import net.minecraft.util.text.TextFormatting;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.event.entity.player.ItemTooltipEvent; import net.minecraftforge.event.entity.player.ItemTooltipEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
import net.minecraftforge.oredict.OreDictionary; import net.minecraftforge.oredict.OreDictionary;
import java.util.List; import java.util.List;
public class TooltipEvent{ @SideOnly(Side.CLIENT)
public class ClientEvents{
private static final String ADVANCED_INFO_TEXT_PRE = TextFormatting.DARK_GRAY+" "; private static final String ADVANCED_INFO_TEXT_PRE = TextFormatting.DARK_GRAY+" ";
private static final String ADVANCED_INFO_HEADER_PRE = TextFormatting.GRAY+" -"; private static final String ADVANCED_INFO_HEADER_PRE = TextFormatting.GRAY+" -";
@ -100,4 +116,67 @@ public class TooltipEvent{
} }
} }
} }
@SubscribeEvent
public void onGameOverlay(RenderGameOverlayEvent.Post event){
if(event.getType() == RenderGameOverlayEvent.ElementType.ALL && Minecraft.getMinecraft().currentScreen == null){
Minecraft minecraft = Minecraft.getMinecraft();
Profiler profiler = minecraft.mcProfiler;
EntityPlayer player = minecraft.thePlayer;
RayTraceResult posHit = minecraft.objectMouseOver;
FontRenderer font = minecraft.fontRendererObj;
ItemStack stack = player.getHeldItemMainhand();
profiler.startSection(ModUtil.MOD_ID+"Hud");
if(stack != null){
if(stack.getItem() instanceof IHudDisplay){
profiler.startSection("ItemHudDisplay");
((IHudDisplay)stack.getItem()).displayHud(minecraft, player, stack, posHit, profiler, event.getResolution());
profiler.endSection();
}
}
if(posHit != null && posHit.getBlockPos() != null){
Block blockHit = PosUtil.getBlock(posHit.getBlockPos(), minecraft.theWorld);
TileEntity tileHit = minecraft.theWorld.getTileEntity(posHit.getBlockPos());
if(blockHit instanceof IHudDisplay){
profiler.startSection("BlockHudDisplay");
((IHudDisplay)blockHit).displayHud(minecraft, player, stack, posHit, profiler, event.getResolution());
profiler.endSection();
}
if(tileHit instanceof TileEntityBase){
TileEntityBase base = (TileEntityBase)tileHit;
if(base.isRedstoneToggle()){
profiler.startSection("RedstoneToggleHudDisplay");
String strg = "Redstone Mode: "+TextFormatting.DARK_RED+(base.isPulseMode ? "Pulse" : "Deactivation")+TextFormatting.RESET;
font.drawStringWithShadow(strg, event.getResolution().getScaledWidth()/2+5, event.getResolution().getScaledHeight()/2+5, StringUtil.DECIMAL_COLOR_WHITE);
if(stack != null && Block.getBlockFromItem(stack.getItem()) instanceof BlockRedstoneTorch){
String expl = TextFormatting.GREEN+"Right-Click to toggle!";
font.drawStringWithShadow(expl, event.getResolution().getScaledWidth()/2+5, event.getResolution().getScaledHeight()/2+15, StringUtil.DECIMAL_COLOR_WHITE);
}
profiler.endSection();
}
}
if(tileHit instanceof IEnergyDisplay){
IEnergyDisplay display = (IEnergyDisplay)tileHit;
if(!display.needsHoldShift() || player.isSneaking()){
profiler.startSection("EnergyDisplay");
String strg = display.getEnergy()+"/"+display.getMaxEnergy()+" RF";
font.drawStringWithShadow(TextFormatting.GOLD+strg, event.getResolution().getScaledWidth()/2+5, event.getResolution().getScaledHeight()/2-10, StringUtil.DECIMAL_COLOR_WHITE);
profiler.endSection();
}
}
}
profiler.endSection();
}
}
} }

View file

@ -0,0 +1,146 @@
/*
* This file ("CommonEvents.java") is part of the Actually Additions mod for Minecraft.
* It is created and owned by Ellpeck and distributed
* under the Actually Additions License to be found at
* http://ellpeck.de/actaddlicense
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
* © 2015-2016 Ellpeck
*/
package de.ellpeck.actuallyadditions.mod.event;
import de.ellpeck.actuallyadditions.mod.achievement.InitAchievements;
import de.ellpeck.actuallyadditions.mod.achievement.TheAchievements;
import de.ellpeck.actuallyadditions.mod.config.values.ConfigBoolValues;
import de.ellpeck.actuallyadditions.mod.data.PlayerData;
import de.ellpeck.actuallyadditions.mod.data.WorldData;
import de.ellpeck.actuallyadditions.mod.items.InitItems;
import de.ellpeck.actuallyadditions.mod.network.PacketHandler;
import de.ellpeck.actuallyadditions.mod.network.PacketServerToClient;
import de.ellpeck.actuallyadditions.mod.util.ModUtil;
import de.ellpeck.actuallyadditions.mod.util.Util;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.monster.EntitySpider;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraftforge.event.entity.EntityJoinWorldEvent;
import net.minecraftforge.event.entity.living.LivingDeathEvent;
import net.minecraftforge.event.entity.living.LivingDropsEvent;
import net.minecraftforge.event.world.WorldEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.PlayerEvent;
import java.util.Locale;
public class CommonEvents{
@SubscribeEvent
public void livingDeathEvent(LivingDeathEvent event){
if(event.getEntityLiving().worldObj != null && !event.getEntityLiving().worldObj.isRemote && event.getEntityLiving() instanceof EntityPlayer){
EntityPlayer player = (EntityPlayer)event.getEntityLiving();
PlayerData.PlayerSave data = PlayerData.getDataFromPlayer(player);
NBTTagList deaths = data.theCompound.getTagList("Deaths", 10);
while(deaths.tagCount() >= 5){
deaths.removeTag(0);
}
NBTTagCompound death = new NBTTagCompound();
death.setDouble("X", player.posX);
death.setDouble("Y", player.posY);
death.setDouble("Z", player.posZ);
deaths.appendTag(death);
data.theCompound.setTag("Deaths", deaths);
//player.addChatComponentMessage(new TextComponentTranslation("info."+ModUtil.MOD_ID+".deathRecorded"));
}
}
@SubscribeEvent
public void onEntityDropEvent(LivingDropsEvent event){
if(event.getEntityLiving().worldObj != null && !event.getEntityLiving().worldObj.isRemote && event.getSource().getEntity() instanceof EntityPlayer){
//Drop Cobwebs from Spiders
if(ConfigBoolValues.DO_SPIDER_DROPS.isEnabled() && event.getEntityLiving() instanceof EntitySpider){
if(Util.RANDOM.nextInt(20) <= event.getLootingLevel()*2){
event.getEntityLiving().entityDropItem(new ItemStack(Blocks.WEB, Util.RANDOM.nextInt(2+event.getLootingLevel())+1), 0);
}
}
}
}
@SubscribeEvent
public void onLogInEvent(EntityJoinWorldEvent event){
if(!event.getEntity().worldObj.isRemote && event.getEntity() instanceof EntityPlayerMP){
EntityPlayerMP player = (EntityPlayerMP)event.getEntity();
PlayerData.PlayerSave data = PlayerData.getDataFromPlayer(player);
if(!data.theCompound.hasNoTags()){
PacketHandler.theNetwork.sendTo(new PacketServerToClient(data.theCompound, PacketHandler.PLAYER_DATA_TO_CLIENT_HANDLER), player);
}
}
}
public static void checkAchievements(ItemStack gotten, EntityPlayer player, InitAchievements.Type type){
for(TheAchievements ach : TheAchievements.values()){
if(ach.type == type){
if(gotten != null && ach.chieve.theItemStack != null && gotten.getItem() == ach.chieve.theItemStack.getItem()){
if(gotten.getItemDamage() == ach.chieve.theItemStack.getItemDamage()){
player.addStat(ach.chieve, 1);
}
}
}
}
}
@SubscribeEvent
public void onCraftedEvent(PlayerEvent.ItemCraftedEvent event){
checkAchievements(event.crafting, event.player, InitAchievements.Type.CRAFTING);
if(ConfigBoolValues.GIVE_BOOKLET_ON_FIRST_CRAFT.isEnabled()){
if(!event.player.worldObj.isRemote && event.crafting != null && event.crafting.getItem() != null && event.crafting.getItem() != InitItems.itemBooklet){
String name = event.crafting.getItem().getRegistryName().toString();
if(name != null && name.toLowerCase(Locale.ROOT).contains(ModUtil.MOD_ID)){
PlayerData.PlayerSave compound = PlayerData.getDataFromPlayer(event.player);
if(compound != null && !compound.theCompound.getBoolean("BookGottenAlready")){
compound.theCompound.setBoolean("BookGottenAlready", true);
EntityItem entityItem = new EntityItem(event.player.worldObj, event.player.posX, event.player.posY, event.player.posZ, new ItemStack(InitItems.itemBooklet));
entityItem.setPickupDelay(0);
event.player.worldObj.spawnEntityInWorld(entityItem);
}
}
}
}
}
@SubscribeEvent
public void onSmeltedEvent(PlayerEvent.ItemSmeltedEvent event){
checkAchievements(event.smelting, event.player, InitAchievements.Type.SMELTING);
}
@SubscribeEvent
public void onPickupEvent(PlayerEvent.ItemPickupEvent event){
checkAchievements(event.pickedUp.getEntityItem(), event.player, InitAchievements.Type.PICK_UP);
}
@SubscribeEvent
public void onLoad(WorldEvent.Load event){
WorldData.load(event.getWorld());
}
@SubscribeEvent
public void onUnload(WorldEvent.Unload event){
WorldData.unload(event.getWorld());
}
@SubscribeEvent
public void onSave(WorldEvent.Save event){
WorldData.save(event.getWorld());
}
}

View file

@ -1,188 +0,0 @@
/*
* This file ("EntityLivingEvent.java") is part of the Actually Additions mod for Minecraft.
* It is created and owned by Ellpeck and distributed
* under the Actually Additions License to be found at
* http://ellpeck.de/actaddlicense
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
* © 2015-2016 Ellpeck
*/
package de.ellpeck.actuallyadditions.mod.event;
import de.ellpeck.actuallyadditions.mod.config.values.ConfigBoolValues;
import de.ellpeck.actuallyadditions.mod.data.PlayerData;
import de.ellpeck.actuallyadditions.mod.items.InitItems;
import de.ellpeck.actuallyadditions.mod.items.ItemWingsOfTheBats;
import de.ellpeck.actuallyadditions.mod.items.metalists.TheMiscItems;
import de.ellpeck.actuallyadditions.mod.util.Util;
import de.ellpeck.actuallyadditions.mod.util.WorldUtil;
import net.minecraft.block.BlockLiquid;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityCreature;
import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.monster.EntitySpider;
import net.minecraft.entity.passive.EntityBat;
import net.minecraft.entity.passive.EntityOcelot;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.init.SoundEvents;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.util.ActionResult;
import net.minecraft.util.math.RayTraceResult;
import net.minecraftforge.event.ForgeEventFactory;
import net.minecraftforge.event.entity.living.LivingDeathEvent;
import net.minecraftforge.event.entity.living.LivingDropsEvent;
import net.minecraftforge.event.entity.living.LivingEvent.LivingUpdateEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import java.util.UUID;
public class EntityLivingEvents{
@SubscribeEvent
public void livingUpdateEvent(LivingUpdateEvent event){
//Ocelots dropping Hair Balls
if(event.getEntityLiving() != null){
if(event.getEntityLiving().worldObj != null && !event.getEntityLiving().worldObj.isRemote){
if((event.getEntityLiving() instanceof EntityOcelot && ((EntityOcelot)event.getEntityLiving()).isTamed()) || (event.getEntityLiving() instanceof EntityPlayer && event.getEntityLiving().getUniqueID().equals(/*KittyVanCat*/ UUID.fromString("681d4e20-10ef-40c9-a0a5-ba2f1995ef44")))){
if(ConfigBoolValues.DO_CAT_DROPS.isEnabled()){
if(Util.RANDOM.nextInt(5000)+1 == 1){
EntityItem item = new EntityItem(event.getEntityLiving().worldObj, event.getEntityLiving().posX+0.5, event.getEntityLiving().posY+0.5, event.getEntityLiving().posZ+0.5, new ItemStack(InitItems.itemHairyBall));
event.getEntityLiving().worldObj.spawnEntityInWorld(item);
}
}
}
}
//Wings allowing Flight
this.doWingStuff(event.getEntityLiving());
}
}
@SubscribeEvent
public void livingDeathEvent(LivingDeathEvent event){
if(event.getEntityLiving().worldObj != null && !event.getEntityLiving().worldObj.isRemote && event.getEntityLiving() instanceof EntityPlayer){
EntityPlayer player = (EntityPlayer)event.getEntityLiving();
PlayerData.PlayerSave data = PlayerData.getDataFromPlayer(player);
NBTTagList deaths = data.theCompound.getTagList("Deaths", 10);
while(deaths.tagCount() >= 5){
deaths.removeTag(0);
}
NBTTagCompound death = new NBTTagCompound();
death.setDouble("X", player.posX);
death.setDouble("Y", player.posY);
death.setDouble("Z", player.posZ);
deaths.appendTag(death);
data.theCompound.setTag("Deaths", deaths);
//player.addChatComponentMessage(new TextComponentTranslation("info."+ModUtil.MOD_ID+".deathRecorded"));
}
}
@SubscribeEvent
public void onPlayerInteractEvent(PlayerInteractEvent event){
if(event.getWorld() != null){
if(ConfigBoolValues.WATER_BOWL.isEnabled()){
if(event.getItemStack() != null && event.getItemStack().getItem() == Items.BOWL){
RayTraceResult trace = WorldUtil.getNearestBlockWithDefaultReachDistance(event.getWorld(), event.getEntityPlayer(), true, false, false);
ActionResult<ItemStack> result = ForgeEventFactory.onBucketUse(event.getEntityPlayer(), event.getWorld(), event.getItemStack(), trace);
if(result == null && trace != null && trace.getBlockPos() != null){
if(event.getEntityPlayer().canPlayerEdit(trace.getBlockPos().offset(trace.sideHit), trace.sideHit, event.getItemStack())){
IBlockState state = event.getWorld().getBlockState(trace.getBlockPos());
Material material = state.getMaterial();
if(material == Material.WATER && state.getValue(BlockLiquid.LEVEL) == 0){
event.getEntityPlayer().playSound(SoundEvents.ITEM_BUCKET_FILL, 1.0F, 1.0F);
if(!event.getWorld().isRemote){
event.getWorld().setBlockState(trace.getBlockPos(), Blocks.AIR.getDefaultState(), 11);
event.getItemStack().stackSize--;
ItemStack bowl = new ItemStack(InitItems.itemWaterBowl);
if(!event.getEntityPlayer().inventory.addItemStackToInventory(bowl.copy())){
EntityItem entityItem = new EntityItem(event.getWorld(), event.getEntityPlayer().posX, event.getEntityPlayer().posY, event.getEntityPlayer().posZ, bowl.copy());
entityItem.setPickupDelay(0);
event.getWorld().spawnEntityInWorld(entityItem);
}
}
}
}
}
}
}
}
}
@SubscribeEvent
public void onEntityDropEvent(LivingDropsEvent event){
if(event.getEntityLiving().worldObj != null && !event.getEntityLiving().worldObj.isRemote && event.getSource().getEntity() instanceof EntityPlayer){
//Drop Solidified XP
if(event.getEntityLiving() instanceof EntityCreature){
if(Util.RANDOM.nextInt(10) <= event.getLootingLevel()*2){
event.getEntityLiving().entityDropItem(new ItemStack(InitItems.itemSolidifiedExperience, Util.RANDOM.nextInt(2+event.getLootingLevel())+1), 0);
}
}
//Drop Cobwebs from Spiders
if(ConfigBoolValues.DO_SPIDER_DROPS.isEnabled() && event.getEntityLiving() instanceof EntitySpider){
if(Util.RANDOM.nextInt(20) <= event.getLootingLevel()*2){
event.getEntityLiving().entityDropItem(new ItemStack(Blocks.WEB, Util.RANDOM.nextInt(2+event.getLootingLevel())+1), 0);
}
}
//Drop Wings from Bats
if(ConfigBoolValues.DO_BAT_DROPS.isEnabled() && event.getEntityLiving() instanceof EntityBat){
if(Util.RANDOM.nextInt(15) <= event.getLootingLevel()*2){
event.getEntityLiving().entityDropItem(new ItemStack(InitItems.itemMisc, Util.RANDOM.nextInt(2+event.getLootingLevel())+1, TheMiscItems.BAT_WING.ordinal()), 0);
}
}
}
}
/**
* Makes players be able to fly if they have Wings Of The Bats equipped
* (Partially excerpted from Botania's Wing System by Vazkii (as I had fiddled around with the system and couldn't make it work) with permission, thanks!)
*/
private void doWingStuff(EntityLivingBase living){
if(living instanceof EntityPlayer){
EntityPlayer player = (EntityPlayer)living;
boolean wingsEquipped = ItemWingsOfTheBats.getWingItem(player) != null;
//If Player isn't (really) winged
if(!ItemWingsOfTheBats.isPlayerWinged(player)){
if(wingsEquipped){
//Make the Player actually winged
ItemWingsOfTheBats.addWingsToPlayer(player);
}
}
//If Player is (or should be) winged
else{
if(wingsEquipped){
//Allow the Player to fly when he has Wings equipped
player.capabilities.allowFlying = true;
}
else{
//Make the Player not winged
ItemWingsOfTheBats.removeWingsFromPlayer(player);
//Reset Player's Values
if(!player.capabilities.isCreativeMode){
player.capabilities.allowFlying = false;
player.capabilities.isFlying = false;
//Enables Fall Damage again (Automatically gets disabled for some reason)
player.capabilities.disableDamage = false;
}
}
}
}
}
}

View file

@ -1,96 +0,0 @@
/*
* This file ("HudEvent.java") is part of the Actually Additions mod for Minecraft.
* It is created and owned by Ellpeck and distributed
* under the Actually Additions License to be found at
* http://ellpeck.de/actaddlicense
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
* © 2015-2016 Ellpeck
*/
package de.ellpeck.actuallyadditions.mod.event;
import de.ellpeck.actuallyadditions.mod.blocks.IHudDisplay;
import de.ellpeck.actuallyadditions.mod.tile.IEnergyDisplay;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityBase;
import de.ellpeck.actuallyadditions.mod.util.ModUtil;
import de.ellpeck.actuallyadditions.mod.util.PosUtil;
import de.ellpeck.actuallyadditions.mod.util.StringUtil;
import net.minecraft.block.Block;
import net.minecraft.block.BlockRedstoneTorch;
import net.minecraft.client.Minecraft;
import net.minecraft.client.gui.FontRenderer;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.profiler.Profiler;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.RayTraceResult;
import net.minecraft.util.text.TextFormatting;
import net.minecraftforge.client.event.RenderGameOverlayEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
public class HudEvent{
@SubscribeEvent
public void onGameOverlay(RenderGameOverlayEvent.Post event){
if(event.getType() == RenderGameOverlayEvent.ElementType.ALL && Minecraft.getMinecraft().currentScreen == null){
Minecraft minecraft = Minecraft.getMinecraft();
Profiler profiler = minecraft.mcProfiler;
EntityPlayer player = minecraft.thePlayer;
RayTraceResult posHit = minecraft.objectMouseOver;
FontRenderer font = minecraft.fontRendererObj;
ItemStack stack = player.getHeldItemMainhand();
profiler.startSection(ModUtil.MOD_ID+"Hud");
if(stack != null){
if(stack.getItem() instanceof IHudDisplay){
profiler.startSection("ItemHudDisplay");
((IHudDisplay)stack.getItem()).displayHud(minecraft, player, stack, posHit, profiler, event.getResolution());
profiler.endSection();
}
}
if(posHit != null && posHit.getBlockPos() != null){
Block blockHit = PosUtil.getBlock(posHit.getBlockPos(), minecraft.theWorld);
TileEntity tileHit = minecraft.theWorld.getTileEntity(posHit.getBlockPos());
if(blockHit instanceof IHudDisplay){
profiler.startSection("BlockHudDisplay");
((IHudDisplay)blockHit).displayHud(minecraft, player, stack, posHit, profiler, event.getResolution());
profiler.endSection();
}
if(tileHit instanceof TileEntityBase){
TileEntityBase base = (TileEntityBase)tileHit;
if(base.isRedstoneToggle()){
profiler.startSection("RedstoneToggleHudDisplay");
String strg = "Redstone Mode: "+TextFormatting.DARK_RED+(base.isPulseMode ? "Pulse" : "Deactivation")+TextFormatting.RESET;
font.drawStringWithShadow(strg, event.getResolution().getScaledWidth()/2+5, event.getResolution().getScaledHeight()/2+5, StringUtil.DECIMAL_COLOR_WHITE);
if(stack != null && Block.getBlockFromItem(stack.getItem()) instanceof BlockRedstoneTorch){
String expl = TextFormatting.GREEN+"Right-Click to toggle!";
font.drawStringWithShadow(expl, event.getResolution().getScaledWidth()/2+5, event.getResolution().getScaledHeight()/2+15, StringUtil.DECIMAL_COLOR_WHITE);
}
profiler.endSection();
}
}
if(tileHit instanceof IEnergyDisplay){
IEnergyDisplay display = (IEnergyDisplay)tileHit;
if(!display.needsHoldShift() || player.isSneaking()){
profiler.startSection("EnergyDisplay");
String strg = display.getEnergy()+"/"+display.getMaxEnergy()+" RF";
font.drawStringWithShadow(TextFormatting.GOLD+strg, event.getResolution().getScaledWidth()/2+5, event.getResolution().getScaledHeight()/2-10, StringUtil.DECIMAL_COLOR_WHITE);
profiler.endSection();
}
}
}
profiler.endSection();
}
}
}

View file

@ -1,48 +0,0 @@
/*
* This file ("InitEvents.java") is part of the Actually Additions mod for Minecraft.
* It is created and owned by Ellpeck and distributed
* under the Actually Additions License to be found at
* http://ellpeck.de/actaddlicense
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
* © 2015-2016 Ellpeck
*/
package de.ellpeck.actuallyadditions.mod.event;
import de.ellpeck.actuallyadditions.mod.config.values.ConfigBoolValues;
import de.ellpeck.actuallyadditions.mod.nei.NEIScreenEvents;
import de.ellpeck.actuallyadditions.mod.update.UpdateCheckerClientNotificationEvent;
import de.ellpeck.actuallyadditions.mod.util.ModUtil;
import de.ellpeck.actuallyadditions.mod.util.Util;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.Loader;
public final class InitEvents{
public static void init(){
ModUtil.LOGGER.info("Initializing Events...");
Util.registerEvent(new PlayerObtainEvents());
Util.registerEvent(new EntityLivingEvents());
Util.registerEvent(new PlayerConnectionEvents());
Util.registerEvent(new WorldLoadingEvents());
Util.registerEvent(new BreakEvent());
MinecraftForge.TERRAIN_GEN_BUS.register(new WorldDecorationEvent());
}
public static void initClient(){
Util.registerEvent(new TooltipEvent());
Util.registerEvent(new HudEvent());
if(Loader.isModLoaded("NotEnoughItems")){
Util.registerEvent(new NEIScreenEvents());
}
if(ConfigBoolValues.DO_UPDATE_CHECK.isEnabled() && !Util.isDevVersion()){
Util.registerEvent(new UpdateCheckerClientNotificationEvent());
}
}
}

View file

@ -1,42 +0,0 @@
/*
* This file ("LogoutEvent.java") is part of the Actually Additions mod for Minecraft.
* It is created and owned by Ellpeck and distributed
* under the Actually Additions License to be found at
* http://ellpeck.de/actaddlicense
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
* © 2015-2016 Ellpeck
*/
package de.ellpeck.actuallyadditions.mod.event;
import de.ellpeck.actuallyadditions.mod.data.PlayerData;
import de.ellpeck.actuallyadditions.mod.items.ItemWingsOfTheBats;
import de.ellpeck.actuallyadditions.mod.network.PacketHandler;
import de.ellpeck.actuallyadditions.mod.network.PacketServerToClient;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraftforge.event.entity.EntityJoinWorldEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.PlayerEvent;
public class PlayerConnectionEvents{
@SubscribeEvent
public void onLogOutEvent(PlayerEvent.PlayerLoggedOutEvent event){
//Remove Player from Wings' Fly Permission List
ItemWingsOfTheBats.removeWingsFromPlayer(event.player, true);
ItemWingsOfTheBats.removeWingsFromPlayer(event.player, false);
}
@SubscribeEvent
public void onLogInEvent(EntityJoinWorldEvent event){
if(!event.getEntity().worldObj.isRemote && event.getEntity() instanceof EntityPlayerMP){
EntityPlayerMP player = (EntityPlayerMP)event.getEntity();
PlayerData.PlayerSave data = PlayerData.getDataFromPlayer(player);
if(!data.theCompound.hasNoTags()){
PacketHandler.theNetwork.sendTo(new PacketServerToClient(data.theCompound, PacketHandler.PLAYER_DATA_TO_CLIENT_HANDLER), player);
}
}
}
}

View file

@ -1,72 +0,0 @@
/*
* This file ("PlayerObtainEvents.java") is part of the Actually Additions mod for Minecraft.
* It is created and owned by Ellpeck and distributed
* under the Actually Additions License to be found at
* http://ellpeck.de/actaddlicense
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
* © 2015-2016 Ellpeck
*/
package de.ellpeck.actuallyadditions.mod.event;
import de.ellpeck.actuallyadditions.mod.achievement.InitAchievements;
import de.ellpeck.actuallyadditions.mod.achievement.TheAchievements;
import de.ellpeck.actuallyadditions.mod.config.values.ConfigBoolValues;
import de.ellpeck.actuallyadditions.mod.data.PlayerData;
import de.ellpeck.actuallyadditions.mod.items.InitItems;
import de.ellpeck.actuallyadditions.mod.util.ModUtil;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.PlayerEvent;
import java.util.Locale;
public class PlayerObtainEvents{
public static void checkAchievements(ItemStack gotten, EntityPlayer player, InitAchievements.Type type){
for(TheAchievements ach : TheAchievements.values()){
if(ach.type == type){
if(gotten != null && ach.chieve.theItemStack != null && gotten.getItem() == ach.chieve.theItemStack.getItem()){
if(gotten.getItemDamage() == ach.chieve.theItemStack.getItemDamage()){
player.addStat(ach.chieve, 1);
}
}
}
}
}
@SubscribeEvent
public void onCraftedEvent(PlayerEvent.ItemCraftedEvent event){
checkAchievements(event.crafting, event.player, InitAchievements.Type.CRAFTING);
if(ConfigBoolValues.GIVE_BOOKLET_ON_FIRST_CRAFT.isEnabled()){
if(!event.player.worldObj.isRemote && event.crafting != null && event.crafting.getItem() != null && event.crafting.getItem() != InitItems.itemBooklet){
String name = event.crafting.getItem().getRegistryName().toString();
if(name != null && name.toLowerCase(Locale.ROOT).contains(ModUtil.MOD_ID)){
PlayerData.PlayerSave compound = PlayerData.getDataFromPlayer(event.player);
if(compound != null && !compound.theCompound.getBoolean("BookGottenAlready")){
compound.theCompound.setBoolean("BookGottenAlready", true);
EntityItem entityItem = new EntityItem(event.player.worldObj, event.player.posX, event.player.posY, event.player.posZ, new ItemStack(InitItems.itemBooklet));
entityItem.setPickupDelay(0);
event.player.worldObj.spawnEntityInWorld(entityItem);
}
}
}
}
}
@SubscribeEvent
public void onSmeltedEvent(PlayerEvent.ItemSmeltedEvent event){
checkAchievements(event.smelting, event.player, InitAchievements.Type.SMELTING);
}
@SubscribeEvent
public void onPickupEvent(PlayerEvent.ItemPickupEvent event){
checkAchievements(event.pickedUp.getEntityItem(), event.player, InitAchievements.Type.PICK_UP);
}
}

View file

@ -1,102 +0,0 @@
/*
* This file ("WorldDecorationEvent.java") is part of the Actually Additions mod for Minecraft.
* It is created and owned by Ellpeck and distributed
* under the Actually Additions License to be found at
* http://ellpeck.de/actaddlicense
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
* © 2015-2016 Ellpeck
*/
package de.ellpeck.actuallyadditions.mod.event;
import de.ellpeck.actuallyadditions.mod.blocks.InitBlocks;
import de.ellpeck.actuallyadditions.mod.blocks.metalists.TheWildPlants;
import de.ellpeck.actuallyadditions.mod.config.values.ConfigBoolValues;
import de.ellpeck.actuallyadditions.mod.config.values.ConfigIntListValues;
import de.ellpeck.actuallyadditions.mod.config.values.ConfigIntValues;
import de.ellpeck.actuallyadditions.mod.util.PosUtil;
import de.ellpeck.actuallyadditions.mod.util.Util;
import de.ellpeck.actuallyadditions.mod.util.WorldUtil;
import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.biome.BiomeOcean;
import net.minecraftforge.event.terraingen.DecorateBiomeEvent;
import net.minecraftforge.fml.common.eventhandler.Event;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import java.util.ArrayList;
public class WorldDecorationEvent{
@SubscribeEvent
public void onWorldDecoration(DecorateBiomeEvent.Decorate event){
if((event.getResult() == Event.Result.ALLOW || event.getResult() == Event.Result.DEFAULT)){
if(Util.arrayContains(ConfigIntListValues.PLANT_DIMENSION_BLACKLIST.getValue(), event.getWorld().provider.getDimension()) < 0){
this.generateRice(event);
this.genPlantNormally(InitBlocks.blockWildPlant, TheWildPlants.CANOLA.ordinal(), ConfigIntValues.CANOLA_AMOUNT.getValue(), ConfigBoolValues.DO_CANOLA_GEN.isEnabled(), Material.GRASS, event);
this.genPlantNormally(InitBlocks.blockWildPlant, TheWildPlants.FLAX.ordinal(), ConfigIntValues.FLAX_AMOUNT.getValue(), ConfigBoolValues.DO_FLAX_GEN.isEnabled(), Material.GRASS, event);
this.genPlantNormally(InitBlocks.blockWildPlant, TheWildPlants.COFFEE.ordinal(), ConfigIntValues.COFFEE_AMOUNT.getValue(), ConfigBoolValues.DO_COFFEE_GEN.isEnabled(), Material.GRASS, event);
this.genPlantNormally(InitBlocks.blockBlackLotus, 0, ConfigIntValues.BLACK_LOTUS_AMOUNT.getValue(), ConfigBoolValues.DO_LOTUS_GEN.isEnabled(), Material.GRASS, event);
}
//Generate Treasure Chests
if(ConfigBoolValues.DO_TREASURE_CHEST_GEN.isEnabled()){
if(event.getRand().nextInt(300) == 0){
BlockPos randomPos = new BlockPos(event.getPos().getX()+event.getRand().nextInt(16)+8, 0, event.getPos().getZ()+event.getRand().nextInt(16)+8);
randomPos = event.getWorld().getTopSolidOrLiquidBlock(randomPos);
if(event.getWorld().getBiomeGenForCoords(randomPos) instanceof BiomeOcean){
if(randomPos.getY() >= 25 && randomPos.getY() <= 45){
if(event.getWorld().getBlockState(randomPos).getMaterial() == Material.WATER){
if(PosUtil.getMaterial(PosUtil.offset(randomPos, 0, -1, 0), event.getWorld()).isSolid()){
PosUtil.setBlock(randomPos, event.getWorld(), InitBlocks.blockTreasureChest, event.getRand().nextInt(4), 2);
}
}
}
}
}
}
}
}
private void generateRice(DecorateBiomeEvent event){
if(ConfigBoolValues.DO_RICE_GEN.isEnabled()){
for(int i = 0; i < ConfigIntValues.RICE_AMOUNT.getValue(); i++){
if(event.getRand().nextInt(50) == 0){
BlockPos randomPos = new BlockPos(event.getPos().getX()+event.getRand().nextInt(16)+8, 0, event.getPos().getZ()+event.getRand().nextInt(16)+8);
randomPos = event.getWorld().getTopSolidOrLiquidBlock(randomPos);
if(PosUtil.getMaterial(randomPos, event.getWorld()) == Material.WATER){
ArrayList<Material> blocksAroundBottom = WorldUtil.getMaterialsAround(event.getWorld(), randomPos);
BlockPos posToGenAt = PosUtil.offset(randomPos, 0, 1, 0);
ArrayList<Material> blocksAroundTop = WorldUtil.getMaterialsAround(event.getWorld(), posToGenAt);
if(blocksAroundBottom.contains(Material.GRASS) || blocksAroundBottom.contains(Material.GROUND) || blocksAroundBottom.contains(Material.ROCK) || blocksAroundBottom.contains(Material.SAND)){
if(!blocksAroundTop.contains(Material.WATER) && PosUtil.getMaterial(posToGenAt, event.getWorld()) == Material.AIR){
PosUtil.setBlock(posToGenAt, event.getWorld(), InitBlocks.blockWildPlant, TheWildPlants.RICE.ordinal(), 2);
}
}
}
}
}
}
}
private void genPlantNormally(Block plant, int meta, int amount, boolean doIt, Material blockBelow, DecorateBiomeEvent event){
if(doIt){
for(int i = 0; i < amount; i++){
if(event.getRand().nextInt(400) == 0){
BlockPos randomPos = new BlockPos(event.getPos().getX()+event.getRand().nextInt(16)+8, 0, event.getPos().getZ()+event.getRand().nextInt(16)+8);
randomPos = event.getWorld().getTopSolidOrLiquidBlock(randomPos);
if(PosUtil.getMaterial(PosUtil.offset(randomPos, 0, -1, 0), event.getWorld()) == blockBelow){
if(plant.canPlaceBlockAt(event.getWorld(), randomPos) && event.getWorld().isAirBlock(randomPos)){
PosUtil.setBlock(randomPos, event.getWorld(), plant, meta, 2);
}
}
}
}
}
}
}

View file

@ -1,34 +0,0 @@
/*
* This file ("WorldLoadingEvents.java") is part of the Actually Additions mod for Minecraft.
* It is created and owned by Ellpeck and distributed
* under the Actually Additions License to be found at
* http://ellpeck.de/actaddlicense
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
* © 2015-2016 Ellpeck
*/
package de.ellpeck.actuallyadditions.mod.event;
import de.ellpeck.actuallyadditions.mod.data.WorldData;
import net.minecraftforge.event.world.WorldEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
public class WorldLoadingEvents{
@SubscribeEvent
public void onLoad(WorldEvent.Load event){
WorldData.load(event.getWorld());
}
@SubscribeEvent
public void onUnload(WorldEvent.Unload event){
WorldData.unload(event.getWorld());
}
@SubscribeEvent
public void onSave(WorldEvent.Save event){
WorldData.save(event.getWorld());
}
}

View file

@ -12,24 +12,34 @@ package de.ellpeck.actuallyadditions.mod.gen;
import de.ellpeck.actuallyadditions.mod.blocks.InitBlocks; import de.ellpeck.actuallyadditions.mod.blocks.InitBlocks;
import de.ellpeck.actuallyadditions.mod.blocks.metalists.TheMiscBlocks; import de.ellpeck.actuallyadditions.mod.blocks.metalists.TheMiscBlocks;
import de.ellpeck.actuallyadditions.mod.blocks.metalists.TheWildPlants;
import de.ellpeck.actuallyadditions.mod.config.values.ConfigBoolValues; import de.ellpeck.actuallyadditions.mod.config.values.ConfigBoolValues;
import de.ellpeck.actuallyadditions.mod.config.values.ConfigIntListValues; import de.ellpeck.actuallyadditions.mod.config.values.ConfigIntListValues;
import de.ellpeck.actuallyadditions.mod.config.values.ConfigIntValues; import de.ellpeck.actuallyadditions.mod.config.values.ConfigIntValues;
import de.ellpeck.actuallyadditions.mod.util.ModUtil; import de.ellpeck.actuallyadditions.mod.util.ModUtil;
import de.ellpeck.actuallyadditions.mod.util.PosUtil;
import de.ellpeck.actuallyadditions.mod.util.Util; import de.ellpeck.actuallyadditions.mod.util.Util;
import de.ellpeck.actuallyadditions.mod.util.WorldUtil;
import net.minecraft.block.Block; import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.block.state.pattern.BlockMatcher; import net.minecraft.block.state.pattern.BlockMatcher;
import net.minecraft.init.Blocks; import net.minecraft.init.Blocks;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.MathHelper; import net.minecraft.util.math.MathHelper;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraft.world.WorldType; import net.minecraft.world.WorldType;
import net.minecraft.world.biome.BiomeOcean;
import net.minecraft.world.chunk.IChunkGenerator; import net.minecraft.world.chunk.IChunkGenerator;
import net.minecraft.world.chunk.IChunkProvider; import net.minecraft.world.chunk.IChunkProvider;
import net.minecraft.world.gen.feature.WorldGenMinable; import net.minecraft.world.gen.feature.WorldGenMinable;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.terraingen.DecorateBiomeEvent;
import net.minecraftforge.fml.common.IWorldGenerator; import net.minecraftforge.fml.common.IWorldGenerator;
import net.minecraftforge.fml.common.eventhandler.Event;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.registry.GameRegistry; import net.minecraftforge.fml.common.registry.GameRegistry;
import java.util.ArrayList;
import java.util.Random; import java.util.Random;
public class OreGen implements IWorldGenerator{ public class OreGen implements IWorldGenerator{
@ -39,9 +49,10 @@ public class OreGen implements IWorldGenerator{
private final WorldGenLushCaves caveGen = new WorldGenLushCaves(); private final WorldGenLushCaves caveGen = new WorldGenLushCaves();
public static void init(){ public OreGen(){
ModUtil.LOGGER.info("Registering World Generator..."); ModUtil.LOGGER.info("Registering World Generator...");
GameRegistry.registerWorldGenerator(new OreGen(), 10); GameRegistry.registerWorldGenerator(this, 10);
MinecraftForge.EVENT_BUS.register(this);
} }
@Override @Override
@ -79,4 +90,73 @@ public class OreGen implements IWorldGenerator{
ModUtil.LOGGER.fatal("Couldn't generate '"+block.getUnlocalizedName()+"' into the world because the Min Y coordinate is bigger than the Max! This is definitely a Config Error! Check the Files!"); ModUtil.LOGGER.fatal("Couldn't generate '"+block.getUnlocalizedName()+"' into the world because the Min Y coordinate is bigger than the Max! This is definitely a Config Error! Check the Files!");
} }
} }
@SubscribeEvent
public void onWorldDecoration(DecorateBiomeEvent.Decorate event){
if((event.getResult() == Event.Result.ALLOW || event.getResult() == Event.Result.DEFAULT)){
if(Util.arrayContains(ConfigIntListValues.PLANT_DIMENSION_BLACKLIST.getValue(), event.getWorld().provider.getDimension()) < 0){
this.generateRice(event);
this.genPlantNormally(InitBlocks.blockWildPlant, TheWildPlants.CANOLA.ordinal(), ConfigIntValues.CANOLA_AMOUNT.getValue(), ConfigBoolValues.DO_CANOLA_GEN.isEnabled(), Material.GRASS, event);
this.genPlantNormally(InitBlocks.blockWildPlant, TheWildPlants.FLAX.ordinal(), ConfigIntValues.FLAX_AMOUNT.getValue(), ConfigBoolValues.DO_FLAX_GEN.isEnabled(), Material.GRASS, event);
this.genPlantNormally(InitBlocks.blockWildPlant, TheWildPlants.COFFEE.ordinal(), ConfigIntValues.COFFEE_AMOUNT.getValue(), ConfigBoolValues.DO_COFFEE_GEN.isEnabled(), Material.GRASS, event);
this.genPlantNormally(InitBlocks.blockBlackLotus, 0, ConfigIntValues.BLACK_LOTUS_AMOUNT.getValue(), ConfigBoolValues.DO_LOTUS_GEN.isEnabled(), Material.GRASS, event);
}
//Generate Treasure Chests
if(ConfigBoolValues.DO_TREASURE_CHEST_GEN.isEnabled()){
if(event.getRand().nextInt(300) == 0){
BlockPos randomPos = new BlockPos(event.getPos().getX()+event.getRand().nextInt(16)+8, 0, event.getPos().getZ()+event.getRand().nextInt(16)+8);
randomPos = event.getWorld().getTopSolidOrLiquidBlock(randomPos);
if(event.getWorld().getBiomeGenForCoords(randomPos) instanceof BiomeOcean){
if(randomPos.getY() >= 25 && randomPos.getY() <= 45){
if(event.getWorld().getBlockState(randomPos).getMaterial() == Material.WATER){
if(PosUtil.getMaterial(PosUtil.offset(randomPos, 0, -1, 0), event.getWorld()).isSolid()){
PosUtil.setBlock(randomPos, event.getWorld(), InitBlocks.blockTreasureChest, event.getRand().nextInt(4), 2);
}
}
}
}
}
}
}
}
private void generateRice(DecorateBiomeEvent event){
if(ConfigBoolValues.DO_RICE_GEN.isEnabled()){
for(int i = 0; i < ConfigIntValues.RICE_AMOUNT.getValue(); i++){
if(event.getRand().nextInt(50) == 0){
BlockPos randomPos = new BlockPos(event.getPos().getX()+event.getRand().nextInt(16)+8, 0, event.getPos().getZ()+event.getRand().nextInt(16)+8);
randomPos = event.getWorld().getTopSolidOrLiquidBlock(randomPos);
if(PosUtil.getMaterial(randomPos, event.getWorld()) == Material.WATER){
ArrayList<Material> blocksAroundBottom = WorldUtil.getMaterialsAround(event.getWorld(), randomPos);
BlockPos posToGenAt = PosUtil.offset(randomPos, 0, 1, 0);
ArrayList<Material> blocksAroundTop = WorldUtil.getMaterialsAround(event.getWorld(), posToGenAt);
if(blocksAroundBottom.contains(Material.GRASS) || blocksAroundBottom.contains(Material.GROUND) || blocksAroundBottom.contains(Material.ROCK) || blocksAroundBottom.contains(Material.SAND)){
if(!blocksAroundTop.contains(Material.WATER) && PosUtil.getMaterial(posToGenAt, event.getWorld()) == Material.AIR){
PosUtil.setBlock(posToGenAt, event.getWorld(), InitBlocks.blockWildPlant, TheWildPlants.RICE.ordinal(), 2);
}
}
}
}
}
}
}
private void genPlantNormally(Block plant, int meta, int amount, boolean doIt, Material blockBelow, DecorateBiomeEvent event){
if(doIt){
for(int i = 0; i < amount; i++){
if(event.getRand().nextInt(400) == 0){
BlockPos randomPos = new BlockPos(event.getPos().getX()+event.getRand().nextInt(16)+8, 0, event.getPos().getZ()+event.getRand().nextInt(16)+8);
randomPos = event.getWorld().getTopSolidOrLiquidBlock(randomPos);
if(PosUtil.getMaterial(PosUtil.offset(randomPos, 0, -1, 0), event.getWorld()) == blockBelow){
if(plant.canPlaceBlockAt(event.getWorld(), randomPos) && event.getWorld().isAirBlock(randomPos)){
PosUtil.setBlock(randomPos, event.getWorld(), plant, meta, 2);
}
}
}
}
}
}
} }

View file

@ -11,22 +11,47 @@
package de.ellpeck.actuallyadditions.mod.items; package de.ellpeck.actuallyadditions.mod.items;
import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI; import de.ellpeck.actuallyadditions.api.ActuallyAdditionsAPI;
import de.ellpeck.actuallyadditions.mod.config.values.ConfigBoolValues;
import de.ellpeck.actuallyadditions.mod.items.base.ItemBase; import de.ellpeck.actuallyadditions.mod.items.base.ItemBase;
import de.ellpeck.actuallyadditions.mod.util.Util; import de.ellpeck.actuallyadditions.mod.util.Util;
import net.minecraft.entity.item.EntityItem; import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.passive.EntityOcelot;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.SoundEvents; import net.minecraft.init.SoundEvents;
import net.minecraft.item.EnumRarity; import net.minecraft.item.EnumRarity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.*; import net.minecraft.util.*;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.living.LivingEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import java.util.UUID;
public class ItemHairyBall extends ItemBase{ public class ItemHairyBall extends ItemBase{
public ItemHairyBall(String name){ public ItemHairyBall(String name){
super(name); super(name);
MinecraftForge.EVENT_BUS.register(this);
} }
@SubscribeEvent
public void livingUpdateEvent(LivingEvent.LivingUpdateEvent event){
//Ocelots dropping Hair Balls
if(event.getEntityLiving() != null){
if(event.getEntityLiving().worldObj != null && !event.getEntityLiving().worldObj.isRemote){
if((event.getEntityLiving() instanceof EntityOcelot && ((EntityOcelot)event.getEntityLiving()).isTamed()) || (event.getEntityLiving() instanceof EntityPlayer && event.getEntityLiving().getUniqueID().equals(/*KittyVanCat*/ UUID.fromString("681d4e20-10ef-40c9-a0a5-ba2f1995ef44")))){
if(ConfigBoolValues.DO_CAT_DROPS.isEnabled()){
if(Util.RANDOM.nextInt(5000)+1 == 1){
EntityItem item = new EntityItem(event.getEntityLiving().worldObj, event.getEntityLiving().posX+0.5, event.getEntityLiving().posY+0.5, event.getEntityLiving().posZ+0.5, new ItemStack(InitItems.itemHairyBall));
event.getEntityLiving().worldObj.spawnEntityInWorld(item);
}
}
}
}
}
}
@Override @Override
public ActionResult<ItemStack> onItemRightClick(ItemStack stack, World world, EntityPlayer player, EnumHand hand){ public ActionResult<ItemStack> onItemRightClick(ItemStack stack, World world, EntityPlayer player, EnumHand hand){

View file

@ -10,15 +10,23 @@
package de.ellpeck.actuallyadditions.mod.items; package de.ellpeck.actuallyadditions.mod.items;
import de.ellpeck.actuallyadditions.mod.config.values.ConfigBoolValues;
import de.ellpeck.actuallyadditions.mod.items.base.ItemBase; import de.ellpeck.actuallyadditions.mod.items.base.ItemBase;
import de.ellpeck.actuallyadditions.mod.util.Util;
import net.minecraft.entity.EntityCreature;
import net.minecraft.entity.item.EntityXPOrb; import net.minecraft.entity.item.EntityXPOrb;
import net.minecraft.entity.monster.EntitySpider;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.EnumRarity; import net.minecraft.item.EnumRarity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.ActionResult; import net.minecraft.util.ActionResult;
import net.minecraft.util.EnumActionResult; import net.minecraft.util.EnumActionResult;
import net.minecraft.util.EnumHand; import net.minecraft.util.EnumHand;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.living.LivingDropsEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
public class ItemSolidifiedExperience extends ItemBase{ public class ItemSolidifiedExperience extends ItemBase{
@ -26,8 +34,21 @@ public class ItemSolidifiedExperience extends ItemBase{
public ItemSolidifiedExperience(String name){ public ItemSolidifiedExperience(String name){
super(name); super(name);
MinecraftForge.EVENT_BUS.register(this);
} }
@SubscribeEvent
public void onEntityDropEvent(LivingDropsEvent event){
if(event.getEntityLiving().worldObj != null && !event.getEntityLiving().worldObj.isRemote && event.getSource().getEntity() instanceof EntityPlayer){
//Drop Solidified XP
if(event.getEntityLiving() instanceof EntityCreature){
if(Util.RANDOM.nextInt(10) <= event.getLootingLevel()*2){
event.getEntityLiving().entityDropItem(new ItemStack(InitItems.itemSolidifiedExperience, Util.RANDOM.nextInt(2+event.getLootingLevel())+1), 0);
}
}
}
}
@Override @Override
public ActionResult<ItemStack> onItemRightClick(ItemStack stack, World world, EntityPlayer player, EnumHand hand){ public ActionResult<ItemStack> onItemRightClick(ItemStack stack, World world, EntityPlayer player, EnumHand hand){

View file

@ -12,12 +12,15 @@ package de.ellpeck.actuallyadditions.mod.items;
import de.ellpeck.actuallyadditions.mod.config.values.ConfigStringListValues; import de.ellpeck.actuallyadditions.mod.config.values.ConfigStringListValues;
import de.ellpeck.actuallyadditions.mod.items.base.ItemBase; import de.ellpeck.actuallyadditions.mod.items.base.ItemBase;
import de.ellpeck.actuallyadditions.mod.items.metalists.TheMiscItems;
import de.ellpeck.actuallyadditions.mod.util.ModUtil; import de.ellpeck.actuallyadditions.mod.util.ModUtil;
import de.ellpeck.actuallyadditions.mod.util.StringUtil; import de.ellpeck.actuallyadditions.mod.util.StringUtil;
import de.ellpeck.actuallyadditions.mod.util.Util;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.EntityList; import net.minecraft.entity.EntityList;
import net.minecraft.entity.EntityLivingBase; import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.MobSpawnerBaseLogic; import net.minecraft.tileentity.MobSpawnerBaseLogic;
@ -29,6 +32,9 @@ import net.minecraft.util.EnumHand;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.text.TextFormatting; import net.minecraft.util.text.TextFormatting;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.world.BlockEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.relauncher.Side; import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly; import net.minecraftforge.fml.relauncher.SideOnly;
@ -39,8 +45,17 @@ public class ItemSpawnerChanger extends ItemBase{
public ItemSpawnerChanger(String name){ public ItemSpawnerChanger(String name){
super(name); super(name);
this.setMaxStackSize(1); this.setMaxStackSize(1);
MinecraftForge.EVENT_BUS.register(this);
} }
@SubscribeEvent
public void onBlockBreakEvent(BlockEvent.HarvestDropsEvent event){
IBlockState state = event.getState();
if(state != null && state.getBlock() == Blocks.MOB_SPAWNER){
event.getDrops().add(new ItemStack(InitItems.itemMisc, 1, TheMiscItems.SPAWNER_SHARD.ordinal()));
}
}
@Override @Override
public EnumActionResult onItemUse(ItemStack aStack, EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ){ public EnumActionResult onItemUse(ItemStack aStack, EntityPlayer player, World world, BlockPos pos, EnumHand hand, EnumFacing facing, float hitX, float hitY, float hitZ){

View file

@ -10,11 +10,15 @@
package de.ellpeck.actuallyadditions.mod.items; package de.ellpeck.actuallyadditions.mod.items;
import de.ellpeck.actuallyadditions.mod.config.values.ConfigBoolValues;
import de.ellpeck.actuallyadditions.mod.items.base.ItemBase; import de.ellpeck.actuallyadditions.mod.items.base.ItemBase;
import de.ellpeck.actuallyadditions.mod.util.PosUtil; import de.ellpeck.actuallyadditions.mod.util.PosUtil;
import de.ellpeck.actuallyadditions.mod.util.Util;
import de.ellpeck.actuallyadditions.mod.util.WorldUtil; import de.ellpeck.actuallyadditions.mod.util.WorldUtil;
import net.minecraft.block.BlockLiquid;
import net.minecraft.block.material.Material; import net.minecraft.block.material.Material;
import net.minecraft.block.state.IBlockState; import net.minecraft.block.state.IBlockState;
import net.minecraft.entity.item.EntityItem;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks; import net.minecraft.init.Blocks;
import net.minecraft.init.Items; import net.minecraft.init.Items;
@ -24,13 +28,52 @@ import net.minecraft.util.*;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.RayTraceResult; import net.minecraft.util.math.RayTraceResult;
import net.minecraft.world.World; import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.ForgeEventFactory; import net.minecraftforge.event.ForgeEventFactory;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
public class ItemWaterBowl extends ItemBase{ public class ItemWaterBowl extends ItemBase{
public ItemWaterBowl(String name){ public ItemWaterBowl(String name){
super(name); super(name);
this.setMaxStackSize(1); this.setMaxStackSize(1);
MinecraftForge.EVENT_BUS.register(this);
}
@SubscribeEvent
public void onPlayerInteractEvent(PlayerInteractEvent event){
if(event.getWorld() != null){
if(ConfigBoolValues.WATER_BOWL.isEnabled()){
if(event.getItemStack() != null && event.getItemStack().getItem() == Items.BOWL){
RayTraceResult trace = WorldUtil.getNearestBlockWithDefaultReachDistance(event.getWorld(), event.getEntityPlayer(), true, false, false);
ActionResult<ItemStack> result = ForgeEventFactory.onBucketUse(event.getEntityPlayer(), event.getWorld(), event.getItemStack(), trace);
if(result == null && trace != null && trace.getBlockPos() != null){
if(event.getEntityPlayer().canPlayerEdit(trace.getBlockPos().offset(trace.sideHit), trace.sideHit, event.getItemStack())){
IBlockState state = event.getWorld().getBlockState(trace.getBlockPos());
Material material = state.getMaterial();
if(material == Material.WATER && state.getValue(BlockLiquid.LEVEL) == 0){
event.getEntityPlayer().playSound(SoundEvents.ITEM_BUCKET_FILL, 1.0F, 1.0F);
if(!event.getWorld().isRemote){
event.getWorld().setBlockState(trace.getBlockPos(), Blocks.AIR.getDefaultState(), 11);
event.getItemStack().stackSize--;
ItemStack bowl = new ItemStack(InitItems.itemWaterBowl);
if(!event.getEntityPlayer().inventory.addItemStackToInventory(bowl.copy())){
EntityItem entityItem = new EntityItem(event.getWorld(), event.getEntityPlayer().posX, event.getEntityPlayer().posY, event.getEntityPlayer().posZ, bowl.copy());
entityItem.setPickupDelay(0);
event.getWorld().spawnEntityInWorld(entityItem);
}
}
}
}
}
}
}
}
} }
@Override @Override

View file

@ -10,10 +10,22 @@
package de.ellpeck.actuallyadditions.mod.items; package de.ellpeck.actuallyadditions.mod.items;
import de.ellpeck.actuallyadditions.mod.config.values.ConfigBoolValues;
import de.ellpeck.actuallyadditions.mod.items.base.ItemBase; import de.ellpeck.actuallyadditions.mod.items.base.ItemBase;
import de.ellpeck.actuallyadditions.mod.items.metalists.TheMiscItems;
import de.ellpeck.actuallyadditions.mod.util.Util;
import net.minecraft.entity.EntityCreature;
import net.minecraft.entity.monster.EntitySpider;
import net.minecraft.entity.passive.EntityBat;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Blocks;
import net.minecraft.item.EnumRarity; import net.minecraft.item.EnumRarity;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.living.LivingDropsEvent;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.PlayerEvent;
import java.util.ArrayList; import java.util.ArrayList;
@ -34,6 +46,61 @@ public class ItemWingsOfTheBats extends ItemBase{
public ItemWingsOfTheBats(String name){ public ItemWingsOfTheBats(String name){
super(name); super(name);
this.setMaxStackSize(1); this.setMaxStackSize(1);
MinecraftForge.EVENT_BUS.register(this);
}
@SubscribeEvent
public void onLogOutEvent(PlayerEvent.PlayerLoggedOutEvent event){
//Remove Player from Wings' Fly Permission List
ItemWingsOfTheBats.removeWingsFromPlayer(event.player, true);
ItemWingsOfTheBats.removeWingsFromPlayer(event.player, false);
}
@SubscribeEvent
public void onEntityDropEvent(LivingDropsEvent event){
if(event.getEntityLiving().worldObj != null && !event.getEntityLiving().worldObj.isRemote && event.getSource().getEntity() instanceof EntityPlayer){
//Drop Wings from Bats
if(ConfigBoolValues.DO_BAT_DROPS.isEnabled() && event.getEntityLiving() instanceof EntityBat){
if(Util.RANDOM.nextInt(15) <= event.getLootingLevel()*2){
event.getEntityLiving().entityDropItem(new ItemStack(InitItems.itemMisc, Util.RANDOM.nextInt(2+event.getLootingLevel())+1, TheMiscItems.BAT_WING.ordinal()), 0);
}
}
}
}
@SubscribeEvent
public void onPlayerInteractEvent(PlayerInteractEvent event){
if(event.getEntityLiving() instanceof EntityPlayer){
EntityPlayer player = (EntityPlayer)event.getEntityLiving();
boolean wingsEquipped = ItemWingsOfTheBats.getWingItem(player) != null;
//If Player isn't (really) winged
if(!ItemWingsOfTheBats.isPlayerWinged(player)){
if(wingsEquipped){
//Make the Player actually winged
ItemWingsOfTheBats.addWingsToPlayer(player);
}
}
//If Player is (or should be) winged
else{
if(wingsEquipped){
//Allow the Player to fly when he has Wings equipped
player.capabilities.allowFlying = true;
}
else{
//Make the Player not winged
ItemWingsOfTheBats.removeWingsFromPlayer(player);
//Reset Player's Values
if(!player.capabilities.isCreativeMode){
player.capabilities.allowFlying = false;
player.capabilities.isFlying = false;
//Enables Fall Damage again (Automatically gets disabled for some reason)
player.capabilities.disableDamage = false;
}
}
}
}
} }
/** /**

View file

@ -16,6 +16,7 @@ import net.minecraft.item.Item;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.util.ResourceLocation; import net.minecraft.util.ResourceLocation;
import net.minecraftforge.client.event.RenderPlayerEvent; import net.minecraftforge.client.event.RenderPlayerEvent;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.eventhandler.EventPriority; import net.minecraftforge.fml.common.eventhandler.EventPriority;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent; import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
@ -27,9 +28,9 @@ public class SpecialRenderInit{
public static final HashMap<String, RenderSpecial> SPECIAL_LIST = new HashMap<String, RenderSpecial>(); public static final HashMap<String, RenderSpecial> SPECIAL_LIST = new HashMap<String, RenderSpecial>();
public static void init(){ public SpecialRenderInit(){
new ThreadSpecialFetcher(); new ThreadSpecialFetcher();
Util.registerEvent(new SpecialRenderInit()); MinecraftForge.EVENT_BUS.register(this);
} }
public static void parse(Properties properties){ public static void parse(Properties properties){

View file

@ -20,7 +20,7 @@ import de.ellpeck.actuallyadditions.mod.blocks.render.RenderDisplayStand;
import de.ellpeck.actuallyadditions.mod.blocks.render.RenderReconstructorLens; import de.ellpeck.actuallyadditions.mod.blocks.render.RenderReconstructorLens;
import de.ellpeck.actuallyadditions.mod.blocks.render.RenderSmileyCloud; import de.ellpeck.actuallyadditions.mod.blocks.render.RenderSmileyCloud;
import de.ellpeck.actuallyadditions.mod.config.values.ConfigBoolValues; import de.ellpeck.actuallyadditions.mod.config.values.ConfigBoolValues;
import de.ellpeck.actuallyadditions.mod.event.InitEvents; import de.ellpeck.actuallyadditions.mod.event.ClientEvents;
import de.ellpeck.actuallyadditions.mod.fluids.InitFluids; import de.ellpeck.actuallyadditions.mod.fluids.InitFluids;
import de.ellpeck.actuallyadditions.mod.misc.special.SpecialRenderInit; import de.ellpeck.actuallyadditions.mod.misc.special.SpecialRenderInit;
import de.ellpeck.actuallyadditions.mod.tile.TileEntityAtomicReconstructor; import de.ellpeck.actuallyadditions.mod.tile.TileEntityAtomicReconstructor;
@ -155,7 +155,7 @@ public class ClientProxy implements IProxy{
public void init(FMLInitializationEvent event){ public void init(FMLInitializationEvent event){
ModUtil.LOGGER.info("Initializing ClientProxy..."); ModUtil.LOGGER.info("Initializing ClientProxy...");
InitEvents.initClient(); new ClientEvents();
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityCompost.class, new RenderCompost()); ClientRegistry.bindTileEntitySpecialRenderer(TileEntityCompost.class, new RenderCompost());
ClientRegistry.bindTileEntitySpecialRenderer(TileEntityAtomicReconstructor.class, new RenderReconstructorLens()); ClientRegistry.bindTileEntitySpecialRenderer(TileEntityAtomicReconstructor.class, new RenderReconstructorLens());
@ -175,7 +175,7 @@ public class ClientProxy implements IProxy{
public void postInit(FMLPostInitializationEvent event){ public void postInit(FMLPostInitializationEvent event){
ModUtil.LOGGER.info("PostInitializing ClientProxy..."); ModUtil.LOGGER.info("PostInitializing ClientProxy...");
SpecialRenderInit.init(); new SpecialRenderInit();
} }
@Override @Override

View file

@ -10,11 +10,21 @@
package de.ellpeck.actuallyadditions.mod.update; package de.ellpeck.actuallyadditions.mod.update;
import com.sun.deploy.util.UpdateCheck;
import de.ellpeck.actuallyadditions.mod.config.values.ConfigBoolValues; import de.ellpeck.actuallyadditions.mod.config.values.ConfigBoolValues;
import de.ellpeck.actuallyadditions.mod.util.ModUtil; import de.ellpeck.actuallyadditions.mod.util.ModUtil;
import de.ellpeck.actuallyadditions.mod.util.StringUtil;
import de.ellpeck.actuallyadditions.mod.util.Util; import de.ellpeck.actuallyadditions.mod.util.Util;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.text.ITextComponent;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
public final class UpdateChecker{ public class UpdateChecker{
public static final String DOWNLOAD_LINK = "http://ellpeck.de/actadddownload"; public static final String DOWNLOAD_LINK = "http://ellpeck.de/actadddownload";
public static final String CHANGELOG_LINK = "http://ellpeck.de/actaddchangelog"; public static final String CHANGELOG_LINK = "http://ellpeck.de/actaddchangelog";
@ -23,10 +33,38 @@ public final class UpdateChecker{
public static int updateVersionInt; public static int updateVersionInt;
public static String updateVersionString; public static String updateVersionString;
public static void init(){ private static boolean notified = false;
private static int ticksElapsedBeforeInfo;
public UpdateChecker(){
if(ConfigBoolValues.DO_UPDATE_CHECK.isEnabled() && !Util.isDevVersion()){ if(ConfigBoolValues.DO_UPDATE_CHECK.isEnabled() && !Util.isDevVersion()){
ModUtil.LOGGER.info("Initializing Update Checker..."); ModUtil.LOGGER.info("Initializing Update Checker...");
new ThreadUpdateChecker(); new ThreadUpdateChecker();
MinecraftForge.EVENT_BUS.register(this);
}
}
@SideOnly(Side.CLIENT)
@SubscribeEvent(receiveCanceled = true)
public void onTick(TickEvent.ClientTickEvent event){
//Don't notify directly to prevent the Message getting lost in Spam on World Joining
if(!notified && Minecraft.getMinecraft().thePlayer != null){
ticksElapsedBeforeInfo++;
if(ticksElapsedBeforeInfo >= 800){
EntityPlayer player = Minecraft.getMinecraft().thePlayer;
if(UpdateChecker.checkFailed){
player.addChatComponentMessage(ITextComponent.Serializer.jsonToComponent(StringUtil.localize("info."+ModUtil.MOD_ID+".update.failed")));
notified = true;
}
else if(UpdateChecker.needsUpdateNotify){
player.addChatComponentMessage(ITextComponent.Serializer.jsonToComponent(StringUtil.localize("info."+ModUtil.MOD_ID+".update.generic")));
player.addChatComponentMessage(ITextComponent.Serializer.jsonToComponent(StringUtil.localizeFormatted("info."+ModUtil.MOD_ID+".update.versionCompare", ModUtil.VERSION, UpdateChecker.updateVersionString)));
player.addChatComponentMessage(ITextComponent.Serializer.jsonToComponent(StringUtil.localizeFormatted("info."+ModUtil.MOD_ID+".update.buttons", UpdateChecker.CHANGELOG_LINK, UpdateChecker.DOWNLOAD_LINK)));
notified = true;
}
ticksElapsedBeforeInfo = 0;
}
} }
} }
} }

View file

@ -1,47 +0,0 @@
/*
* This file ("UpdateCheckerClientNotificationEvent.java") is part of the Actually Additions mod for Minecraft.
* It is created and owned by Ellpeck and distributed
* under the Actually Additions License to be found at
* http://ellpeck.de/actaddlicense
* View the source code at https://github.com/Ellpeck/ActuallyAdditions
*
* © 2015-2016 Ellpeck
*/
package de.ellpeck.actuallyadditions.mod.update;
import de.ellpeck.actuallyadditions.mod.util.ModUtil;
import de.ellpeck.actuallyadditions.mod.util.StringUtil;
import net.minecraft.client.Minecraft;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.util.text.ITextComponent;
import net.minecraftforge.fml.common.eventhandler.SubscribeEvent;
import net.minecraftforge.fml.common.gameevent.TickEvent;
public class UpdateCheckerClientNotificationEvent{
private static boolean notified = false;
private static int ticksElapsedBeforeInfo;
@SubscribeEvent(receiveCanceled = true)
public void onTick(TickEvent.ClientTickEvent event){
//Don't notify directly to prevent the Message getting lost in Spam on World Joining
if(!notified && Minecraft.getMinecraft().thePlayer != null){
ticksElapsedBeforeInfo++;
if(ticksElapsedBeforeInfo >= 800){
EntityPlayer player = Minecraft.getMinecraft().thePlayer;
if(UpdateChecker.checkFailed){
player.addChatComponentMessage(ITextComponent.Serializer.jsonToComponent(StringUtil.localize("info."+ModUtil.MOD_ID+".update.failed")));
notified = true;
}
else if(UpdateChecker.needsUpdateNotify){
player.addChatComponentMessage(ITextComponent.Serializer.jsonToComponent(StringUtil.localize("info."+ModUtil.MOD_ID+".update.generic")));
player.addChatComponentMessage(ITextComponent.Serializer.jsonToComponent(StringUtil.localizeFormatted("info."+ModUtil.MOD_ID+".update.versionCompare", ModUtil.VERSION, UpdateChecker.updateVersionString)));
player.addChatComponentMessage(ITextComponent.Serializer.jsonToComponent(StringUtil.localizeFormatted("info."+ModUtil.MOD_ID+".update.buttons", UpdateChecker.CHANGELOG_LINK, UpdateChecker.DOWNLOAD_LINK)));
notified = true;
}
ticksElapsedBeforeInfo = 0;
}
}
}
}

View file

@ -35,10 +35,6 @@ public final class Util{
public static final EnumRarity FALLBACK_RARITY = addRarity("fallback", TextFormatting.STRIKETHROUGH, ModUtil.NAME+" Fallback"); public static final EnumRarity FALLBACK_RARITY = addRarity("fallback", TextFormatting.STRIKETHROUGH, ModUtil.NAME+" Fallback");
public static void registerEvent(Object o){
MinecraftForge.EVENT_BUS.register(o);
}
private static EnumRarity addRarity(String name, TextFormatting color, String displayName){ private static EnumRarity addRarity(String name, TextFormatting color, String displayName){
return EnumHelper.addRarity((ModUtil.MOD_ID+"_"+name).toUpperCase(Locale.ROOT), color, displayName); return EnumHelper.addRarity((ModUtil.MOD_ID+"_"+name).toUpperCase(Locale.ROOT), color, displayName);
} }