Skip to content

Commit

Permalink
v2.3
Browse files Browse the repository at this point in the history
  • Loading branch information
Furgl committed Nov 10, 2016
1 parent 885d463 commit 09d5b42
Show file tree
Hide file tree
Showing 8 changed files with 228 additions and 138 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ plugins {
id "net.minecraftforge.gradle.forge" version "2.0.2"
}
*/
version = "1.10.2-2.2"
version = "1.10.2-2.3"
group= "furgl.autoPickup" // http://maven.apache.org/guides/mini/guide-naming-conventions.html
archivesBaseName = "AutoPickup"

Expand Down
10 changes: 6 additions & 4 deletions src/main/java/furgl/autoPickup/AutoPickup.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@
import furgl.autoPickup.event.DelayedPickupEvent;
import furgl.autoPickup.event.EntityItemPickupEvents;
import furgl.autoPickup.event.ItemTossEvents;
import furgl.autoPickup.event.PlaySoundAtEntityEvents;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.SoundEvents;
import net.minecraft.item.ItemStack;
import net.minecraft.util.SoundCategory;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.common.Mod.EventHandler;
Expand All @@ -22,7 +23,7 @@ public class AutoPickup
{
public static final String MODID = "autopickup";
public static final String MODNAME = "AutoPickup";
public static final String VERSION = "2.2";
public static final String VERSION = "2.3";

public static SimpleNetworkWrapper network;
@SidedProxy(clientSide = "furgl.autoPickup.ClientProxy", serverSide = "furgl.autoPickup.CommonProxy")
Expand Down Expand Up @@ -52,7 +53,6 @@ public void serverLoad(FMLServerStartingEvent event)
public void registerEventListeners()
{
MinecraftForge.EVENT_BUS.register(new DelayedPickupEvent());
MinecraftForge.EVENT_BUS.register(new PlaySoundAtEntityEvents());
MinecraftForge.EVENT_BUS.register(new EntityItemPickupEvents());
MinecraftForge.EVENT_BUS.register(new ItemTossEvents());
MinecraftForge.EVENT_BUS.register(new IgnoreKey());
Expand All @@ -67,8 +67,10 @@ public static boolean addItem(EntityPlayer player, ItemStack itemStack, boolean
if (itemStack != null && (!Config.blacklistNames.contains(itemStack.getItem().getItemStackDisplayName(itemStack).replace(" ", "_")) || IgnoreKey.isPressed))
{
boolean value = player.inventory.addItemStackToInventory(itemStack);
if (value)
if (value) {
player.inventoryContainer.detectAndSendChanges();
player.worldObj.playSound((EntityPlayer)null, player.posX, player.posY, player.posZ, SoundEvents.ENTITY_ITEM_PICKUP, SoundCategory.PLAYERS, 0.2F, ((player.getRNG().nextFloat() - player.getRNG().nextFloat()) * 0.7F + 1.0F) * 2.0F);
}
return value;
}
else
Expand Down
292 changes: 207 additions & 85 deletions src/main/java/furgl/autoPickup/CommandBlacklist.java

Large diffs are not rendered by default.

9 changes: 3 additions & 6 deletions src/main/java/furgl/autoPickup/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,36 +10,33 @@ public class Config
{
public static Configuration config;
public static ArrayList<String> blacklistNames;
public static boolean autoAdd = true;
public static boolean autoAdd;
/**Resets every session*/
public static boolean firstAutoAdd = true;

public static void init(final File file)
{
Config.config = new Configuration(file);
Config.config.load();
Config.config.save();
}

/**Update blacklistNames and blacklistItems from config file*/
public static void syncFromConfig(String playerName)
{
Property autoAddProp = Config.config.get(playerName, "AutoAdd", true);
Property autoAddProp = Config.config.get(playerName, "AutoAdd", false);
autoAdd = autoAddProp.getBoolean();
Property itemsProp = Config.config.get(playerName, "Blacklisted Items", new String[0]);
blacklistNames = new ArrayList<String>();
String[] names = itemsProp.getStringList();
for (int i=0; i<names.length; i++)
{
blacklistNames.add(names[i]);
}
Config.config.save();
}

/**Update config file from blacklistNames*/
public static void syncToConfig(String playerName)
{
Property autoAddProp = Config.config.get(playerName, "AutoAdd", true);
Property autoAddProp = Config.config.get(playerName, "AutoAdd", false);
autoAddProp.set(autoAdd);
Property itemsProp = Config.config.get(playerName, "Blacklisted Items", new String[0]);
String[] names = new String[blacklistNames.size()];
Expand Down
13 changes: 8 additions & 5 deletions src/main/java/furgl/autoPickup/event/DelayedPickupEvent.java
Original file line number Diff line number Diff line change
Expand Up @@ -41,28 +41,31 @@ public void onEvent(TickEvent.WorldTickEvent event)
List<EntityItem> items = event.world.getEntitiesWithinAABB(EntityItem.class, aabb.get(0));
for (EntityItem item : items)
AutoPickup.addItem(players.get(0), item.getEntityItem(), true);
List<EntityXPOrb> xpOrbs = event.world.getEntitiesWithinAABB(EntityXPOrb.class, aabb.get(0));
for (EntityXPOrb xp : xpOrbs)
xp.setPosition(players.get(0).posX, players.get(0).posY, players.get(0).posZ);
players.remove(0);
aabb.remove(0);
delays.remove(0);
}
}

/** Detect when mob killed and give drops to player.*/
@SubscribeEvent(priority=EventPriority.NORMAL, receiveCanceled=true)
public void onEvent(LivingDropsEvent event)
{
if (!event.getEntity().worldObj.isRemote && event.getSource().getEntity() instanceof EntityPlayer)
DelayedPickupEvent.setDelayedPickup((EntityPlayer) event.getSource().getEntity(), event.getEntity().posX, event.getEntity().posY, event.getEntity().posZ);
}

/** Detect when player clicks jukebox and gives record to player.*/
@SubscribeEvent(priority=EventPriority.NORMAL, receiveCanceled=true)
public void onEvent(RightClickBlock event)
{
if (!event.getEntityPlayer().worldObj.isRemote)
DelayedPickupEvent.setDelayedPickup(event.getEntityPlayer(), event.getPos().getX(), event.getPos().getY(), event.getPos().getZ());
}

/** Detect when mob sheared.*/
@SubscribeEvent(priority=EventPriority.NORMAL, receiveCanceled=true)
public void onEvent(EntityInteractSpecific event)
Expand All @@ -78,15 +81,15 @@ public void onEvent(BlockEvent.BreakEvent event)
if (!event.getWorld().isRemote)
DelayedPickupEvent.setDelayedPickup(event.getPlayer(), event.getPos().getX(), event.getPos().getY(), event.getPos().getZ());
}

/** Detect when minecart container/item frame/painting/armor stand/boat destroyed and give contents to player.*/
@SubscribeEvent(priority=EventPriority.NORMAL, receiveCanceled=true)
public void onEvent(AttackEntityEvent event)
{
if (!event.getEntityPlayer().worldObj.isRemote)
DelayedPickupEvent.setDelayedPickup(event.getEntityPlayer(), event.getTarget().posX, event.getTarget().posY, event.getTarget().posZ);
}

/** Detect when experience is dropped and give to player.*/
@SubscribeEvent(priority=EventPriority.NORMAL, receiveCanceled=true)
public void onEvent(LivingExperienceDropEvent event)
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/furgl/autoPickup/event/ItemTossEvents.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ public class ItemTossEvents
{
@SubscribeEvent(priority=EventPriority.NORMAL, receiveCanceled=true)
public void onEvent(ItemTossEvent event)
{ //can only be called on client side
if (Config.autoAdd && !event.getPlayer().worldObj.isRemote /* && Minecraft.getMinecraft().currentScreen instanceof GuiInventory*/)
{
if (Config.autoAdd && !event.getPlayer().worldObj.isRemote)
{
Config.syncFromConfig(event.getPlayer().getName());
ItemStack stack = event.getEntityItem().getEntityItem();
Expand Down
34 changes: 0 additions & 34 deletions src/main/java/furgl/autoPickup/event/PlaySoundAtEntityEvents.java

This file was deleted.

2 changes: 1 addition & 1 deletion src/main/resources/mcmod.info
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"modid": "autopickup",
"name": "AutoPickup",
"description": "Allows items to be picked up automatically or blacklisted and never picked up.",
"version": "2.2",
"version": "2.3",
"mcversion": "1.10.2",
"url": "https://sites.google.com/site/furglsmods/auto-pickup",
"updateUrl": "",
Expand Down

0 comments on commit 09d5b42

Please sign in to comment.