Remove lots of legacy handling code

This commit is contained in:
mezz committed 2016-02-26 21:49:04 -08:00
1 parent 75bbf7e6a7
commit a8270ef365
20 files changed
+61 -235

No files matched your search

@@ -10,13 +10,13 @@
******************************************************************************/
package forestry.apiculture.gui.widgets;
import javax.annotation.Nonnull;
import java.util.Collection;
import java.util.Collections;
import java.util.Locale;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraftforge.common.BiomeDictionary;
import net.minecraftforge.fml.relauncher.Side;
@@ -24,18 +24,22 @@ import net.minecraftforge.fml.relauncher.SideOnly;
import org.lwjgl.opengl.GL11;
import forestry.core.gui.tooltips.ToolTip;
import forestry.core.gui.widgets.Widget;
import forestry.core.gui.widgets.WidgetManager;
import forestry.core.proxy.Proxies;
import forestry.core.render.TextureManager;
public class HabitatSlot extends Widget {
@Nonnull
private final Collection<BiomeDictionary.Type> biomes;
@Nonnull
private final String name;
@Nonnull
private final String iconIndex;
public boolean isActive = false;
public HabitatSlot(WidgetManager widgetManager, int xPos, int yPos, String name, Collection<BiomeDictionary.Type> biomes) {
public HabitatSlot(@Nonnull WidgetManager widgetManager, int xPos, int yPos, @Nonnull String name, @Nonnull Collection<BiomeDictionary.Type> biomes) {
super(widgetManager, xPos, yPos);
this.biomes = biomes;
this.name = name;
@@ -43,8 +47,10 @@ public class HabitatSlot extends Widget {
}
@Override
public String getLegacyTooltip(EntityPlayer player) {
return name;
public ToolTip getToolTip(int mouseX, int mouseY) {
ToolTip tooltip = new ToolTip();
tooltip.add(name);
return tooltip;
}
@SideOnly(Side.CLIENT)
@@ -10,56 +10,11 @@
******************************************************************************/
package forestry.apiculture.tiles;
import net.minecraft.block.Block;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import forestry.api.apiculture.BeeManager;
import forestry.core.config.Constants;
import forestry.core.inventory.InventoryPlain;
import forestry.core.tiles.TileNaturalistChest;
import forestry.core.tiles.TileUtil;
import forestry.core.utils.BlockUtil;
import forestry.plugins.PluginApiculture;
public class TileApiaristChest extends TileNaturalistChest {
private boolean checkedForLegacyBlock = false;
public TileApiaristChest() {
super(BeeManager.beeRoot);
}
@Override
protected void updateServerSide() {
if (worldObj != null && !checkedForLegacyBlock) {
Block block = BlockUtil.getBlock(worldObj, getPos());
if (PluginApiculture.blocks.apiculture == block) {
migrateFromLegacyBlock();
}
checkedForLegacyBlock = true;
}
super.updateServerSide();
}
private void migrateFromLegacyBlock() {
IInventory inventoryCopy = new InventoryPlain(getInternalInventory());
// clear the inventory so it isn't dropped when the block is replaced
for (int i = 0; i < getSizeInventory(); i++) {
setInventorySlotContents(i, null);
}
worldObj.setBlockToAir(getPos());
worldObj.setBlockState(getPos(), PluginApiculture.blocks.apicultureChest.getStateFromMeta(0), Constants.FLAG_BLOCK_SYNCH_AND_UPDATE);
TileApiaristChest tile = TileUtil.getTile(worldObj, getPos(), TileApiaristChest.class);
for (int i = 0; i < getSizeInventory(); i++) {
ItemStack stack = inventoryCopy.getStackInSlot(i);
tile.setInventorySlotContents(i, stack);
}
tile.markDirty();
}
}
@@ -18,10 +18,8 @@ import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.renderer.ItemMeshDefinition;
import net.minecraft.client.resources.model.ModelResourceLocation;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.BlockPos;
import net.minecraft.util.EnumFacing;
@@ -41,8 +39,6 @@ import forestry.core.utils.BlockUtil;
import forestry.core.utils.StringUtil;
public class ItemBlockWood extends ItemBlockForestry {
private static final String LEGACY_WOOD_TYPE_KEY = "WoodType";
public ItemBlockWood(Block block) {
super(block);
}
@@ -84,42 +80,8 @@ public class ItemBlockWood extends ItemBlockForestry {
}
public static EnumWoodType getWoodType(ItemStack stack) {
EnumWoodType woodType = convertLegacyWood(stack);
if (woodType == null) {
int typeOrdinal = stack.getItemDamage();
woodType = getFromOrdinal(typeOrdinal);
}
return woodType;
}
// legacy handling of wood that has wood type saved to NBT
private static EnumWoodType convertLegacyWood(ItemStack itemStack) {
if (!itemStack.hasTagCompound()) {
return null;
}
NBTTagCompound compound = itemStack.getTagCompound();
if (!compound.hasKey(LEGACY_WOOD_TYPE_KEY)) {
return null;
}
int typeOrdinal = compound.getInteger(LEGACY_WOOD_TYPE_KEY);
EnumWoodType woodType = getFromOrdinal(typeOrdinal);
if (woodType != null) {
compound.removeTag(LEGACY_WOOD_TYPE_KEY);
if (compound.hasNoTags()) {
itemStack.setTagCompound(null);
}
saveToItemStack(woodType, itemStack);
}
return woodType;
}
@Override
public void onUpdate(ItemStack stack, World world, Entity player, int p_77663_4_, boolean p_77663_5_) {
super.onUpdate(stack, world, player, p_77663_4_, p_77663_5_);
convertLegacyWood(stack);
int typeOrdinal = stack.getItemDamage();
return getFromOrdinal(typeOrdinal);
}
private static EnumWoodType getFromOrdinal(int ordinal) {
@@ -116,12 +116,6 @@ public class TileLeaves extends TileTreeContainer implements IPollinatable, IFru
caterpillar = ButterflyManager.butterflyRoot.getMember(nbttagcompound.getCompoundTag("CATER"));
}
if (nbttagcompound.hasKey("Decorative")) { //legacy
isDecorative = nbttagcompound.getBoolean("Decorative");
} else { //legacy
isDecorative = nbttagcompound.getBoolean("DEC");
}
if (nbttagcompound.hasKey("ContainedTree")) {
setTree(new Tree(nbttagcompound.getCompoundTag("ContainedTree")));
}
@@ -215,10 +215,6 @@ public class Config {
enableBackpackResupply = configCommon.getBooleanLocalized("performance", "backpacks.resupply", enableBackpackResupply);
// move legacy mail property
configCommon.moveProperty("tweaks.gui", "mail.alert", "tweaks.gui.mail.alert");
configCommon.renameProperty("tweaks.gui.mail.alert", "mail.alert", "enabled");
mailAlertEnabled = configCommon.getBooleanLocalized("tweaks.gui.mail.alert", "enabled", mailAlertEnabled);
mailAlertXPosition = configCommon.getEnumLocalized("tweaks.gui.mail.alert", "xPosition", mailAlertXPosition, GuiMailboxInfo.XPosition.values());
mailAlertYPosition = configCommon.getEnumLocalized("tweaks.gui.mail.alert", "yPosition", mailAlertYPosition, GuiMailboxInfo.YPosition.values());
@@ -123,12 +123,6 @@ public enum Fluids {
}
}
},
LEGACY_HONEY(new Color(255, 196, 35)) {
@Override
public String getTag() {
return "honey";
}
},
ICE(new Color(175, 242, 255), 920, 1000) {
@Override
public int getTemperature() {
@@ -265,7 +259,7 @@ public enum Fluids {
CREOSOTE(new Color(0x635c03)),
STEAM(new Color(0x91938F));
public static final Fluids[] forestryFluids = {ETHANOL, BIOMASS, GLASS, HONEY, LEGACY_HONEY, ICE, JUICE, MILK, SEEDOIL, SHORT_MEAD};
public static final Fluids[] forestryFluids = {ETHANOL, BIOMASS, GLASS, HONEY, ICE, JUICE, MILK, SEEDOIL, SHORT_MEAD};
private static final Map<String, Fluids> tagToFluid = new HashMap<>();
@@ -10,11 +10,13 @@
******************************************************************************/
package forestry.core.gui.tooltips;
import javax.annotation.Nullable;
/**
* @author CovertJaguar <http://www.railcraft.info/>
*/
public interface IToolTipProvider {
@Nullable
ToolTip getToolTip(int mouseX, int mouseY);
boolean isToolTipVisible();
@@ -12,6 +12,7 @@ package forestry.core.gui.tooltips;
import com.google.common.collect.ForwardingList;
import javax.annotation.Nonnull;
import java.util.ArrayList;
import java.util.List;
@@ -37,7 +38,7 @@ public class ToolTip extends ForwardingList<ToolTipLine> {
return delegate;
}
public boolean add(String line) {
public boolean add(@Nonnull String line) {
return add(new ToolTipLine(line));
}
@@ -10,35 +10,35 @@
******************************************************************************/
package forestry.core.gui.tooltips;
import javax.annotation.Nonnull;
import net.minecraft.util.EnumChatFormatting;
/**
* @author CovertJaguar <http://www.railcraft.info>
*/
public class ToolTipLine {
@Nonnull
private final String text;
@Nonnull
private final EnumChatFormatting color;
private final int spacing;
public ToolTipLine(String text, EnumChatFormatting color, int spacing) {
public ToolTipLine(@Nonnull String text, @Nonnull EnumChatFormatting color, int spacing) {
this.text = text;
this.color = color;
this.spacing = spacing;
}
public ToolTipLine(String text) {
public ToolTipLine(@Nonnull String text) {
this(text, null, 0);
}
public ToolTipLine() {
this("", null, 0);
}
public int getSpacing() {
return spacing;
}
@Nonnull
@Override
public String toString() {
if (color == null) {
@@ -13,13 +13,13 @@ package forestry.core.gui.widgets;
import net.minecraft.client.renderer.RenderHelper;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import org.lwjgl.opengl.GL11;
import forestry.core.gui.GuiUtil;
import forestry.core.gui.tooltips.ToolTip;
import forestry.core.network.packets.PacketGuiSelectRequest;
import forestry.core.proxy.Proxies;
import forestry.core.render.TextureManager;
@@ -81,13 +81,15 @@ public class GameTokenWidget extends Widget {
}
@Override
protected String getLegacyTooltip(EntityPlayer player) {
public ToolTip getToolTip(int mouseX, int mouseY) {
EscritoireGameToken token = getToken();
if (token == null || !token.isVisible()) {
return null;
}
return token.getTooltip();
ToolTip tooltip = new ToolTip();
tooltip.add(token.getTooltip());
return tooltip;
}
@Override
@@ -10,11 +10,10 @@
******************************************************************************/
package forestry.core.gui.widgets;
import net.minecraft.entity.player.EntityPlayer;
import org.lwjgl.opengl.GL11;
import forestry.core.gui.GuiEscritoire;
import forestry.core.gui.tooltips.ToolTip;
import forestry.core.network.packets.PacketGuiSelectRequest;
import forestry.core.proxy.Proxies;
import forestry.core.utils.StringUtil;
@@ -39,8 +38,10 @@ public class ProbeButton extends Widget {
}
@Override
protected String getLegacyTooltip(EntityPlayer player) {
return StringUtil.localize("gui.escritoire.probe");
public ToolTip getToolTip(int mouseX, int mouseY) {
ToolTip tooltip = new ToolTip();
tooltip.add(StringUtil.localize("gui.escritoire.probe"));
return tooltip;
}
@Override
@@ -10,23 +10,24 @@
******************************************************************************/
package forestry.core.gui.widgets;
import net.minecraft.entity.player.EntityPlayer;
import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import forestry.core.gui.tooltips.IToolTipProvider;
import forestry.core.gui.tooltips.ToolTip;
import forestry.core.proxy.Proxies;
/**
* Basic non-ItemStack slot
*/
public abstract class Widget implements IToolTipProvider {
@Nonnull
protected final WidgetManager manager;
protected final int xPos;
protected final int yPos;
protected int width = 16;
protected int height = 16;
public Widget(WidgetManager manager, int xPos, int yPos) {
public Widget(@Nonnull WidgetManager manager, int xPos, int yPos) {
this.manager = manager;
this.xPos = xPos;
this.yPos = yPos;
@@ -42,18 +43,9 @@ public abstract class Widget implements IToolTipProvider {
public abstract void draw(int startX, int startY);
@Nullable
@Override
public ToolTip getToolTip(int mouseX, int mouseY) {
String line = getLegacyTooltip(Proxies.common.getClientInstance().thePlayer);
if (line != null && !line.isEmpty()) {
ToolTip tip = new ToolTip();
tip.add(line);
return tip;
}
return null;
}
protected String getLegacyTooltip(EntityPlayer player) {
return null;
}
@@ -16,14 +16,12 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.IInventory;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.IChatComponent;
import forestry.core.tiles.IFilterSlotDelegate;
public abstract class ItemInventory implements IInventory, IFilterSlotDelegate {
private static final String KEY_ITEMS = "Items"; // legacy
private static final String KEY_SLOTS = "Slots";
private static final String KEY_UID = "UID";
private static final Random rand = new Random();
@@ -37,7 +35,7 @@ public abstract class ItemInventory implements IInventory, IFilterSlotDelegate {
this.parent = parent;
this.inventoryStacks = new ItemStack[size];
setUID(); // Set a uid to identify the itemstack on SMP
setUID(); // Set a uid to identify the itemStack on SMP
readFromNBT(parent.getTagCompound());
}
@@ -48,24 +46,8 @@ public abstract class ItemInventory implements IInventory, IFilterSlotDelegate {
return 0;
}
if (nbt.hasKey(KEY_SLOTS)) {
NBTTagCompound slotNbt = nbt.getCompoundTag(KEY_SLOTS);
return slotNbt.getKeySet().size();
}
int count = 0;
if (nbt.hasKey(KEY_ITEMS)) { // legacy since Forestry 3.6
NBTTagList nbttaglist = nbt.getTagList(KEY_ITEMS, 10);
for (int i = 0; i < nbttaglist.tagCount(); i++) {
NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i);
ItemStack itemStack1 = ItemStack.loadItemStackFromNBT(nbttagcompound1);
if (itemStack1 != null && itemStack1.stackSize > 0) {
count++;
}
}
}
return count;
NBTTagCompound slotNbt = nbt.getCompoundTag(KEY_SLOTS);
return slotNbt.getKeySet().size();
}
private void setUID() {
@@ -118,37 +100,15 @@ public abstract class ItemInventory implements IInventory, IFilterSlotDelegate {
return;
}
if (nbt.hasKey(KEY_SLOTS)) {
NBTTagCompound nbtSlots = nbt.getCompoundTag(KEY_SLOTS);
for (int i = 0; i < inventoryStacks.length; i++) {
String slotKey = getSlotNBTKey(i);
if (nbtSlots.hasKey(slotKey)) {
NBTTagCompound itemNbt = nbtSlots.getCompoundTag(slotKey);
ItemStack itemStack = ItemStack.loadItemStackFromNBT(itemNbt);
inventoryStacks[i] = itemStack;
} else {
inventoryStacks[i] = null;
}
}
} else {
// legacy since Forestry 3.6
if (nbt.hasKey(KEY_ITEMS)) {
for (int i = 0; i < inventoryStacks.length; i++) {
inventoryStacks[i] = null;
}
NBTTagList nbttaglist = nbt.getTagList(KEY_ITEMS, 10);
for (int i = 0; i < nbttaglist.tagCount(); i++) {
NBTTagCompound nbttagcompound1 = nbttaglist.getCompoundTagAt(i);
byte byte0 = nbttagcompound1.getByte("Slot");
if (byte0 >= 0 && byte0 < inventoryStacks.length) {
ItemStack itemStack = ItemStack.loadItemStackFromNBT(nbttagcompound1);
inventoryStacks[byte0] = itemStack;
}
}
writeToParentNBT();
NBTTagCompound nbtSlots = nbt.getCompoundTag(KEY_SLOTS);
for (int i = 0; i < inventoryStacks.length; i++) {
String slotKey = getSlotNBTKey(i);
if (nbtSlots.hasKey(slotKey)) {
NBTTagCompound itemNbt = nbtSlots.getCompoundTag(slotKey);
ItemStack itemStack = ItemStack.loadItemStackFromNBT(itemNbt);
inventoryStacks[i] = itemStack;
} else {
inventoryStacks[i] = null;
}
}
}
@@ -172,7 +132,6 @@ public abstract class ItemInventory implements IInventory, IFilterSlotDelegate {
}
nbt.setTag(KEY_SLOTS, slotsNbt);
nbt.removeTag(KEY_ITEMS);
}
private static String getSlotNBTKey(int i) {
@@ -122,6 +122,7 @@ public class EscritoireGameToken implements INbtWritable, IStreamable {
}
}
@Nonnull
public String getTooltip() {
return tokenStack != null ? tokenStack.getDisplayName() : StringUtil.localize("gui.unknown");
}
@@ -236,19 +236,6 @@ public class TileEngineBiogas extends TileEngine implements ISidedInventory, ILi
public void readFromNBT(NBTTagCompound nbt) {
super.readFromNBT(nbt);
//legacy
{
if (nbt.hasKey("currentFluid")) {
Fluid fluid = FluidRegistry.getFluid(nbt.getString("currentFluid"));
if (fluid != null) {
int burnTime = nbt.getInteger("EngineBurnTime");
int totalTime = nbt.getInteger("EngineTotalTime");
burnTank.setCapacity(totalTime);
burnTank.setFluid(new FluidStack(fluid, burnTime));
}
}
}
if (nbt.hasKey("shutdown")) {
shutdown = nbt.getBoolean("shutdown");
}
@@ -23,13 +23,9 @@ public class InventoryFabricator extends InventoryAdapterTile<TileFabricator> {
public static final short SLOT_METAL = 0;
public static final short SLOT_PLAN = 1;
public static final short SLOT_RESULT = 2;
// FIXME 1.8: change indexes and use correct SLOT_COUNT of 21
// left this way for now to avoid losing items in existing fabricators
public static final short SLOT_CRAFTING_LEGACY_1 = 3;
public static final short SLOT_CRAFTING_LEGACY_COUNT = 9;
public static final short SLOT_INVENTORY_1 = 12;
public static final short SLOT_INVENTORY_1 = 3;
public static final short SLOT_INVENTORY_COUNT = 18;
public static final short SLOT_COUNT = 30;
public static final short SLOT_COUNT = 21;
public InventoryFabricator(TileFabricator fabricator) {
super(fabricator, SLOT_COUNT, "Items");
@@ -16,7 +16,6 @@ import net.minecraftforge.fluids.Fluid;
import net.minecraftforge.fluids.FluidStack;
import forestry.api.recipes.IFermenterRecipe;
import forestry.core.fluids.Fluids;
public class FermenterRecipe implements IFermenterRecipe {
@@ -27,11 +26,6 @@ public class FermenterRecipe implements IFermenterRecipe {
private final FluidStack fluidResource;
public FermenterRecipe(ItemStack resource, int fermentationValue, float modifier, Fluid output, FluidStack fluidResource) {
// assume that fermenter recipes want to use Forestry's honey and not the legacy "fluid.honey"
if (Fluids.LEGACY_HONEY.is(fluidResource)) {
fluidResource = Fluids.HONEY.getFluid(fluidResource.amount);
}
if (resource == null) {
throw new NullPointerException("Fermenter Resource cannot be null!");
}
@@ -90,19 +90,6 @@ public class TileFabricator extends TilePowered implements ISlotPickupWatcher, I
heat = nbttagcompound.getInteger("Heat");
tankManager.readFromNBT(nbttagcompound);
craftingInventory.readFromNBT(nbttagcompound);
// FIXME 1.8: wont need this
// move items from legacy crafting area to the new one
IInventory inventory = getInternalInventory();
for (int slot = InventoryFabricator.SLOT_CRAFTING_LEGACY_1; slot < InventoryFabricator.SLOT_CRAFTING_LEGACY_1 + InventoryFabricator.SLOT_CRAFTING_LEGACY_COUNT; slot++) {
ItemStack stack = inventory.getStackInSlot(slot);
if (stack != null) {
inventory.setInventorySlotContents(slot, null);
int newSlot = slot - InventoryFabricator.SLOT_CRAFTING_LEGACY_1;
craftingInventory.setInventorySlotContents(newSlot, stack);
}
}
}
@Override
@@ -11,12 +11,12 @@
package forestry.mail.gui.widgets;
import net.minecraft.client.renderer.texture.TextureMap;
import net.minecraft.entity.player.EntityPlayer;
import org.lwjgl.opengl.GL11;
import forestry.api.mail.IPostalCarrier;
import forestry.api.mail.PostManager;
import forestry.core.gui.tooltips.ToolTip;
import forestry.core.gui.widgets.Widget;
import forestry.core.gui.widgets.WidgetManager;
import forestry.core.proxy.Proxies;
@@ -45,8 +45,11 @@ public class AddresseeSlot extends Widget {
}
@Override
protected String getLegacyTooltip(EntityPlayer player) {
return StringUtil.localize("gui.addressee." + containerLetter.getCarrierType());
public ToolTip getToolTip(int mouseX, int mouseY) {
String tooltipString = StringUtil.localize("gui.addressee." + containerLetter.getCarrierType());
ToolTip tooltip = new ToolTip();
tooltip.add(tooltipString);
return tooltip;
}
@Override
@@ -14,7 +14,6 @@ import net.minecraft.init.Blocks;
import net.minecraft.init.Items;
import net.minecraft.item.ItemStack;
import net.minecraftforge.fluids.FluidRegistry;
import net.minecraftforge.fluids.FluidStack;
import forestry.api.circuits.ChipsetManager;
@@ -260,11 +259,6 @@ public class PluginFactory extends BlankForestryPlugin {
RecipeManagers.stillManager.addRecipe(Constants.STILL_DESTILLATION_DURATION, Fluids.BIOMASS.getFluid(Constants.STILL_DESTILLATION_INPUT),
Fluids.ETHANOL.getFluid(Constants.STILL_DESTILLATION_OUTPUT));
// convert old honey to new honey
if (FluidRegistry.isFluidRegistered(Fluids.LEGACY_HONEY.name())) {
RecipeManagers.stillManager.addRecipe(1, Fluids.LEGACY_HONEY.getFluid(1000), Fluids.HONEY.getFluid(1000));
}
// MOISTENER
RecipeManagers.moistenerManager.addRecipe(new ItemStack(Items.wheat_seeds), new ItemStack(Blocks.mycelium), 5000);
RecipeManagers.moistenerManager.addRecipe(new ItemStack(Blocks.cobblestone), new ItemStack(Blocks.mossy_cobblestone), 20000);