Skip to content

Commit

Permalink
Knapsack/extended slots tick updates
Browse files Browse the repository at this point in the history
- Fixed a null pointer exception
- Clean up imports in GlassBlock(accidental)
- Made the extended armor slots tick and armor tick items
- Made the knapsack tick items
  • Loading branch information
fuj1n committed Dec 14, 2013
1 parent 22c99c8 commit f8450e4
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/main/java/tconstruct/TConstruct.java
Expand Up @@ -89,6 +89,7 @@ public void preInit (FMLPreInitializationEvent event)
basinCasting = new LiquidCasting();
chiselDetailing = new Detailing();

recipes = new TRecipes();
content = new TContent();

MinecraftForge.EVENT_BUS.register(new TEventHandlerAchievement());
Expand Down
6 changes: 2 additions & 4 deletions src/main/java/tconstruct/blocks/GlassBlock.java
@@ -1,13 +1,11 @@
package tconstruct.blocks;

import cpw.mods.fml.relauncher.*;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IconRegister;
import net.minecraft.entity.Entity;
import net.minecraft.util.Icon;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.world.*;

public class GlassBlock extends TConstructBlock
{
Expand Down
21 changes: 21 additions & 0 deletions src/main/java/tconstruct/items/armor/Knapsack.java
@@ -1,5 +1,11 @@
package tconstruct.items.armor;

import tconstruct.TConstruct;
import tconstruct.util.player.*;

import net.minecraft.entity.Entity;
import net.minecraft.world.World;

import java.util.List;

import tconstruct.items.CraftingItem;
Expand Down Expand Up @@ -29,5 +35,20 @@ public void addInformation (ItemStack stack, EntityPlayer player, List list, boo
break;
}
}

@Override
public void onArmorTickUpdate(World world, EntityPlayer player, ItemStack itemStack)
{
TPlayerStats stats = TConstruct.playerTracker.getPlayerStats(player.username);
KnapsackInventory inv = stats.knapsack;

if (stats != null && inv != null) {
for(int i = 0; i < inv.getSizeInventory(); i++){
if(inv.getStackInSlot(i) != null){
inv.getStackInSlot(i).getItem().onUpdate(inv.getStackInSlot(i), player.worldObj, player, i, false);
}
}
}
}

}
23 changes: 23 additions & 0 deletions src/main/java/tconstruct/util/TEventHandler.java
@@ -1,5 +1,9 @@
package tconstruct.util;

import tconstruct.util.player.ArmorExtended;

import net.minecraftforge.event.entity.living.LivingEvent.LivingUpdateEvent;

import java.util.Random;

import net.minecraft.block.Block;
Expand Down Expand Up @@ -620,6 +624,25 @@ public void bucketFill (FillBucketEvent evt)
}
}

@ForgeSubscribe
public void livingUpdate (LivingUpdateEvent event)
{
if(event.entityLiving instanceof EntityPlayer){
EntityPlayer player = (EntityPlayer) event.entityLiving;
TPlayerStats stats = TConstruct.playerTracker.getPlayerStats(player.username);

if(stats != null){
ArmorExtended armor = stats.armor;
for(int i = 0; i < armor.getSizeInventory(); i++){
if(armor.getStackInSlot(i) != null){
armor.getStackInSlot(i).getItem().onUpdate(armor.getStackInSlot(i), player.worldObj, player, i, false);
armor.getStackInSlot(i).getItem().onArmorTickUpdate(player.worldObj, player, armor.getStackInSlot(i));
}
}
}
}
}

//Player interact event - prevent breaking of tank air blocks in creative
@ForgeSubscribe
public void playerInteract (PlayerInteractEvent event)
Expand Down

0 comments on commit f8450e4

Please sign in to comment.