Skip to content

Commit

Permalink
Cleanup Waila compatibility
Browse files Browse the repository at this point in the history
- Fixed an error where a null stack was being returned instead of an empty one.
  - Solves TehNut-Mods/HWYLA#105
- Removed redundant handling and providers.
  • Loading branch information
TehNut committed Jan 2, 2018
1 parent 2e3485d commit 213f9be
Showing 1 changed file with 4 additions and 151 deletions.
155 changes: 4 additions & 151 deletions src/main/java/com/progwml6/natura/plugin/waila/HUDHandlerNatura.java
@@ -1,15 +1,10 @@
package com.progwml6.natura.plugin.waila;

import java.lang.reflect.Method;
import java.util.List;

import javax.annotation.Nonnull;

import com.progwml6.natura.Natura;
import com.progwml6.natura.common.block.BlockNaturaDoor;
import com.progwml6.natura.nether.NaturaNether;
import com.progwml6.natura.nether.block.leaves.BlockNetherLeaves;
import com.progwml6.natura.nether.block.logs.BlockNetherLog2;
import com.progwml6.natura.overworld.NaturaOverworld;
import com.progwml6.natura.overworld.block.crops.BlockOverworldCrops;
import com.progwml6.natura.shared.NaturaCommons;
Expand All @@ -20,48 +15,10 @@
import mcp.mobius.waila.api.IWailaRegistrar;
import mcp.mobius.waila.cbcore.LangUtil;
import net.minecraft.block.Block;
import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;

public class HUDHandlerNatura implements IWailaDataProvider
{
//@formatter:off
static Method getCrop;
static Method getDoor;

//Overworld Blocks
static Block overworldLog = NaturaOverworld.overworldLog;
static Block overworldLog2 = NaturaOverworld.overworldLog2;
static Block redwoodLog = NaturaOverworld.redwoodLog;
static Block overworldLeaves = NaturaOverworld.overworldLeaves;
static Block overworldLeaves2 = NaturaOverworld.overworldLeaves2;
static Block redwoodLeaves = NaturaOverworld.redwoodLeaves;
static Block overworldSapling = NaturaOverworld.overworldSapling;
static Block overworldSapling2 = NaturaOverworld.overworldSapling2;
static Block redwoodSapling = NaturaOverworld.redwoodSapling;
static Block barley = NaturaOverworld.barleyCrop;
static Block cotton = NaturaOverworld.cottonCrop;
static Block eucalyptusDoor = NaturaOverworld.eucalyptusDoor;
static Block hopseedDoor = NaturaOverworld.hopseedDoor;
static Block sakuraDoor = NaturaOverworld.sakuraDoor;
static Block redwoodDoor = NaturaOverworld.redwoodDoor;
static Block redwoodBarkDoor = NaturaOverworld.redwoodBarkDoor;

//Nether Blocks
static Block netherLog = NaturaNether.netherLog;
static Block netherLog2 = NaturaNether.netherLog2;
static Block netherLeaves = NaturaNether.netherLeaves;
static Block netherLeaves2 = NaturaNether.netherLeaves2;
static Block netherSapling = NaturaNether.netherSapling;
static Block netherSapling2 = NaturaNether.netherSapling2;
static Block ghostwoodDoor = NaturaNether.ghostwoodDoor;
static Block bloodwoodDoor = NaturaNether.bloodwoodDoor;
//@formatter:on

@Nonnull
@Override
public ItemStack getWailaStack(IWailaDataAccessor accessor, IWailaConfigHandler config)
Expand All @@ -70,87 +27,16 @@ public ItemStack getWailaStack(IWailaDataAccessor accessor, IWailaConfigHandler

if (Natura.pulseManager.isPulseLoaded(NaturaOverworld.PulseId))
{
if (block == overworldLog || block == overworldLog2 || block == redwoodLog)
{
return new ItemStack(block, 1, accessor.getMetadata() % 4);
}

if (block == overworldLeaves || block == overworldLeaves2 || block == redwoodLeaves)
{
return new ItemStack(block, 1, accessor.getMetadata() % 4);
}

if (block == overworldSapling || block == overworldSapling2 || block == redwoodSapling)
{
return new ItemStack(block, 1, accessor.getMetadata() % 8);
}

// Barley crop should display Barley item
if (block == barley)
if (block == NaturaOverworld.barleyCrop)
return NaturaCommons.barley.copy();

// Cotton crop should display Cotton item
if (block == cotton)
if (block == NaturaOverworld.cottonCrop)
return NaturaCommons.cotton.copy();

// Eucalyptus Door should display Eucalyptus Door item
if (block == eucalyptusDoor)
return NaturaOverworld.eucalyptus_door.copy();

// Hopseed Door should display Hopseed Door item
if (block == hopseedDoor)
return NaturaOverworld.hopseed_door.copy();

// Sakura Door should display Sakura Door item
if (block == sakuraDoor)
return NaturaOverworld.sakura_door.copy();

// Redwood Door should display Redwood Door item
if (block == redwoodDoor)
return NaturaOverworld.redwood_door.copy();

// Redwood Bark Door should display Redwood Bark Door item
if (block == redwoodBarkDoor)
return NaturaOverworld.redwood_bark_door.copy();
}

if (Natura.pulseManager.isPulseLoaded(NaturaNether.PulseId))
{
if (block == netherLog)
{
return new ItemStack(block, 1, accessor.getMetadata() % 4);
}

if (block == netherLog2)
{
return new ItemStack(block, 1, accessor.getBlockState().getValue(BlockNetherLog2.META));
}

if (block == netherLeaves)
{
return new ItemStack(block, 1, accessor.getBlockState().getValue(BlockNetherLeaves.TYPE).getWailaLeavesMeta());
}

if (block == netherLeaves2)
{
return new ItemStack(block, 1, accessor.getMetadata() % 4);
}

if (block == netherSapling || block == netherSapling2)
{
return new ItemStack(block, 1, accessor.getMetadata() % 8);
}

// Ghostwood Door should display Ghostwood Door item
if (block == ghostwoodDoor)
return NaturaNether.ghostwood_door.copy();

// Bloodwood Bark Door should display Bloodwood Bark Door item
if (block == bloodwoodDoor)
return NaturaNether.bloodwood_door.copy();
}

return null;
return ItemStack.EMPTY;
}

@Nonnull
Expand Down Expand Up @@ -178,45 +64,12 @@ public List<String> getWailaBody(ItemStack itemStack, List<String> currenttip, I
return currenttip;
}

@Nonnull
@Override
public NBTTagCompound getNBTData(EntityPlayerMP player, TileEntity te, NBTTagCompound tag, World world, BlockPos pos)
{
if (te != null)
te.writeToNBT(tag);

return tag;
}

public static void register(IWailaRegistrar registrar)
{
IWailaDataProvider provider = new HUDHandlerNatura();

//Overworld
registrar.registerStackProvider(provider, overworldLog.getClass());
registrar.registerStackProvider(provider, overworldLog2.getClass());
registrar.registerStackProvider(provider, redwoodLog.getClass());
registrar.registerStackProvider(provider, overworldLeaves.getClass());
registrar.registerStackProvider(provider, overworldLeaves2.getClass());
registrar.registerStackProvider(provider, redwoodLeaves.getClass());
registrar.registerStackProvider(provider, overworldSapling.getClass());
registrar.registerStackProvider(provider, overworldSapling2.getClass());
registrar.registerStackProvider(provider, redwoodSapling.getClass());
registrar.registerStackProvider(provider, barley.getClass());
registrar.registerStackProvider(provider, cotton.getClass());
registrar.registerStackProvider(provider, eucalyptusDoor.getClass());
registrar.registerStackProvider(provider, BlockOverworldCrops.class);
registrar.registerBodyProvider(provider, BlockOverworldCrops.class);
registrar.registerBodyProvider(provider, BlockNaturaDoor.class);
registrar.registerNBTProvider(provider, cotton.getClass());
registrar.registerNBTProvider(provider, barley.getClass());
registrar.registerNBTProvider(provider, eucalyptusDoor.getClass());

//Nether
registrar.registerStackProvider(provider, netherLog.getClass());
registrar.registerStackProvider(provider, netherLog2.getClass());
registrar.registerStackProvider(provider, netherLeaves.getClass());
registrar.registerStackProvider(provider, netherLeaves2.getClass());
registrar.registerStackProvider(provider, netherSapling.getClass());
registrar.registerStackProvider(provider, netherSapling2.getClass());
}
}

0 comments on commit 213f9be

Please sign in to comment.