mirror of
https://github.com/HbmMods/Hbm-s-Nuclear-Tech-GIT.git
synced 2026-01-25 10:32:49 +00:00
Fix stuff
This commit is contained in:
parent
b79b499b21
commit
239454e23c
@ -1,11 +1,12 @@
|
||||
package com.hbm.handler.ability;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import com.google.common.base.Functions;
|
||||
import com.hbm.main.MainRegistry;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
@ -14,7 +15,8 @@ import net.minecraft.util.EnumChatFormatting;
|
||||
|
||||
// All abilities available on a given tool
|
||||
public class AvailableAbilities {
|
||||
private HashMap<IBaseAbility, Integer> abilities = new HashMap<IBaseAbility, Integer>();
|
||||
// Insertion order matters
|
||||
private LinkedHashMap<IBaseAbility, Integer> abilities = new LinkedHashMap<IBaseAbility, Integer>();
|
||||
|
||||
public AvailableAbilities() {}
|
||||
|
||||
@ -63,15 +65,15 @@ public class AvailableAbilities {
|
||||
}
|
||||
|
||||
public Map<IBaseAbility, Integer> getToolAbilities() {
|
||||
return abilities.keySet().stream().filter(a -> a instanceof IToolAreaAbility || a instanceof IToolHarvestAbility).collect(Collectors.toMap(a -> a, a -> abilities.get(a)));
|
||||
return abilities.keySet().stream().filter(a -> a instanceof IToolAreaAbility || a instanceof IToolHarvestAbility).collect(Collectors.toMap(a -> a, a -> abilities.get(a), (x, y) -> y, LinkedHashMap::new));
|
||||
}
|
||||
|
||||
public Map<IToolAreaAbility, Integer> getToolAreaAbilities() {
|
||||
return abilities.keySet().stream().filter(a -> a instanceof IToolAreaAbility).collect(Collectors.toMap(a -> (IToolAreaAbility)a, a -> abilities.get(a)));
|
||||
return abilities.keySet().stream().filter(a -> a instanceof IToolAreaAbility).collect(Collectors.toMap(a -> (IToolAreaAbility)a, a -> abilities.get(a), (x, y) -> y, LinkedHashMap::new));
|
||||
}
|
||||
|
||||
public Map<IToolHarvestAbility, Integer> getToolHarvestAbilities() {
|
||||
return abilities.keySet().stream().filter(a -> a instanceof IToolHarvestAbility).collect(Collectors.toMap(a -> (IToolHarvestAbility)a, a -> abilities.get(a)));
|
||||
return abilities.keySet().stream().filter(a -> a instanceof IToolHarvestAbility).collect(Collectors.toMap(a -> (IToolHarvestAbility)a, a -> abilities.get(a), (x, y) -> y, LinkedHashMap::new));
|
||||
}
|
||||
|
||||
public int size() {
|
||||
@ -90,7 +92,10 @@ public class AvailableAbilities {
|
||||
list.add("Abilities: ");
|
||||
|
||||
toolAbilities.forEach((ability, level) -> {
|
||||
list.add(" " + EnumChatFormatting.GOLD + ability.getFullName(level));
|
||||
String fullName = ability.getFullName(level);
|
||||
if (!fullName.isEmpty()) {
|
||||
list.add(" " + EnumChatFormatting.GOLD + fullName);
|
||||
}
|
||||
});
|
||||
|
||||
list.add("Right click to cycle through abilities!");
|
||||
|
||||
@ -11,12 +11,12 @@ import com.hbm.handler.ability.IBaseAbility;
|
||||
import com.hbm.handler.ability.IToolAreaAbility;
|
||||
import com.hbm.handler.ability.IToolHarvestAbility;
|
||||
import com.hbm.handler.ability.ToolPreset;
|
||||
import com.hbm.inventory.RecipesCommon.ComparableStack;
|
||||
import com.hbm.items.tool.ItemToolAbility;
|
||||
import com.hbm.items.tool.ItemToolAbility.Configuration;
|
||||
import com.hbm.lib.RefStrings;
|
||||
import com.hbm.main.MainRegistry;
|
||||
import com.hbm.packet.PacketDispatcher;
|
||||
import com.hbm.packet.toclient.PlayerInformPacket;
|
||||
import com.hbm.packet.toserver.NBTItemControlPacket;
|
||||
import com.hbm.util.EnumUtil;
|
||||
import com.hbm.util.I18nUtil;
|
||||
import com.hbm.util.Tuple.Pair;
|
||||
@ -81,6 +81,7 @@ public class GUIScreenToolAbility extends GuiScreen {
|
||||
super();
|
||||
|
||||
this.availableAbilities = availableAbilities;
|
||||
|
||||
this.xSize = 186; // Note: increased dynamically
|
||||
this.ySize = 76;
|
||||
|
||||
@ -91,10 +92,12 @@ public class GUIScreenToolAbility extends GuiScreen {
|
||||
@Override
|
||||
public void initGui() {
|
||||
this.toolStack = this.mc.thePlayer.getHeldItem();
|
||||
|
||||
|
||||
if(this.toolStack == null) {
|
||||
doClose();
|
||||
}
|
||||
|
||||
this.config = ((ItemToolAbility) this.toolStack.getItem()).getConfiguration(this.toolStack);
|
||||
|
||||
guiLeft = (width - xSize) / 2;
|
||||
guiTop = (height - ySize) / 2;
|
||||
@ -239,13 +242,17 @@ public class GUIScreenToolAbility extends GuiScreen {
|
||||
return x <= mouseX && x + width > mouseX && y <= mouseY && y + height > mouseY;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateScreen() {
|
||||
EntityPlayer player = this.mc.thePlayer;
|
||||
|
||||
if(player.getHeldItem() == null || player.getHeldItem() != toolStack)
|
||||
player.closeScreen();
|
||||
}
|
||||
// Note: This spuriously trigger way too often, and I can't see why. I'll disable it altogether, I guess
|
||||
// @Override
|
||||
// public void updateScreen() {
|
||||
// EntityPlayer player = this.mc.thePlayer;
|
||||
//
|
||||
// if(player.getHeldItem() == null || player.getHeldItem().getItem() != toolStack.getItem()) {
|
||||
// // TODO: Remove
|
||||
// MainRegistry.logger.warn("GUIScreenToolAbility.updateScreen: toolStack changed!");
|
||||
// player.closeScreen();
|
||||
// }
|
||||
// }
|
||||
|
||||
@Override
|
||||
public void handleMouseInput() {
|
||||
@ -264,9 +271,16 @@ public class GUIScreenToolAbility extends GuiScreen {
|
||||
ToolPreset activePreset = config.getActivePreset();
|
||||
|
||||
// Process switches
|
||||
handleSwitchesClicked(abilitiesArea, activePreset.areaAbility, activePreset.areaAbilityLevel, hoverIdxArea, mouseX, mouseY);
|
||||
handleSwitchesClicked(abilitiesHarvest, activePreset.harvestAbility, activePreset.harvestAbilityLevel, hoverIdxHarvest, mouseX, mouseY);
|
||||
|
||||
Pair<IBaseAbility, Integer> clickResult;
|
||||
|
||||
clickResult = handleSwitchesClicked(abilitiesArea, activePreset.areaAbility, activePreset.areaAbilityLevel, hoverIdxArea, mouseX, mouseY);
|
||||
activePreset.areaAbility = (IToolAreaAbility)clickResult.key;
|
||||
activePreset.areaAbilityLevel = clickResult.value;
|
||||
|
||||
clickResult = handleSwitchesClicked(abilitiesHarvest, activePreset.harvestAbility, activePreset.harvestAbilityLevel, hoverIdxHarvest, mouseX, mouseY);
|
||||
activePreset.harvestAbility = (IToolHarvestAbility)clickResult.key;
|
||||
activePreset.harvestAbilityLevel = clickResult.value;
|
||||
|
||||
// Process extra buttons
|
||||
if (hoverIdxExtraBtn != -1) {
|
||||
switch (hoverIdxExtraBtn) {
|
||||
@ -284,6 +298,7 @@ public class GUIScreenToolAbility extends GuiScreen {
|
||||
|
||||
// Allow quick-closing
|
||||
if (!isInAABB(mouseX, mouseY, guiLeft, guiTop, xSize, ySize)) {
|
||||
MainRegistry.logger.info("GUIScreenToolAbility.mouseClicked: Clicked outside GUI, closing...");
|
||||
doClose();
|
||||
}
|
||||
}
|
||||
@ -370,6 +385,10 @@ public class GUIScreenToolAbility extends GuiScreen {
|
||||
}
|
||||
|
||||
protected void doClose() {
|
||||
// A bit messy, but I suppose it works
|
||||
((ItemToolAbility) this.toolStack.getItem()).setConfiguration(toolStack, config);
|
||||
PacketDispatcher.wrapper.sendToServer(new NBTItemControlPacket(this.toolStack.getTagCompound()));
|
||||
|
||||
this.mc.thePlayer.closeScreen();
|
||||
|
||||
MainRegistry.proxy.displayTooltip(config.getActivePreset().getMessage().getFormattedText(), MainRegistry.proxy.ID_TOOLABILITY);
|
||||
|
||||
@ -11,6 +11,7 @@ import com.google.common.collect.HashMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.google.common.collect.Sets;
|
||||
import com.hbm.inventory.gui.GUIScreenToolAbility;
|
||||
import com.hbm.items.IItemControlReceiver;
|
||||
import com.hbm.handler.HbmKeybinds;
|
||||
import com.hbm.blocks.ModBlocks;
|
||||
import com.hbm.extprop.HbmPlayerProps;
|
||||
@ -22,9 +23,11 @@ import com.hbm.handler.ability.ToolPreset;
|
||||
import com.hbm.main.MainRegistry;
|
||||
import com.hbm.packet.PacketDispatcher;
|
||||
import com.hbm.packet.toclient.PlayerInformPacket;
|
||||
import com.hbm.packet.toserver.NBTItemControlPacket;
|
||||
import com.hbm.tileentity.IGUIProvider;
|
||||
|
||||
import api.hbm.item.IDepthRockTool;
|
||||
import cpw.mods.fml.client.FMLClientHandler;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.block.Block;
|
||||
@ -54,7 +57,7 @@ import net.minecraftforge.common.ForgeHooks;
|
||||
import net.minecraftforge.common.IShearable;
|
||||
import net.minecraftforge.event.world.BlockEvent;
|
||||
|
||||
public class ItemToolAbility extends ItemTool implements IDepthRockTool, IGUIProvider {
|
||||
public class ItemToolAbility extends ItemTool implements IDepthRockTool, IGUIProvider, IItemControlReceiver {
|
||||
|
||||
protected boolean isShears = false;
|
||||
protected EnumToolType toolType;
|
||||
@ -251,13 +254,13 @@ public class ItemToolAbility extends ItemTool implements IDepthRockTool, IGUIPro
|
||||
|
||||
if(!canOperate(stack))
|
||||
return super.onItemRightClick(stack, world, player);
|
||||
|
||||
Configuration config = getConfiguration(stack);
|
||||
|
||||
if(HbmPlayerProps.getData(player).getKeyPressed(HbmKeybinds.EnumKeybind.TOOL_ALT)) {
|
||||
if(world.isRemote) player.openGui(MainRegistry.instance, 0, world, 0, 0, 0);
|
||||
return stack;
|
||||
}
|
||||
|
||||
Configuration config = getConfiguration(stack);
|
||||
|
||||
if(config.presets.size() < 2 || world.isRemote)
|
||||
return super.onItemRightClick(stack, world, player);
|
||||
@ -425,7 +428,7 @@ public class ItemToolAbility extends ItemTool implements IDepthRockTool, IGUIPro
|
||||
|
||||
presets = new ArrayList<ToolPreset>(nbtPresets.tagCount());
|
||||
|
||||
for(int i = 0; i < presets.size(); i++) {
|
||||
for(int i = 0; i < nbtPresets.tagCount(); i++) {
|
||||
NBTTagCompound nbtPreset = nbtPresets.getCompoundTagAt(i);
|
||||
ToolPreset preset = new ToolPreset();
|
||||
preset.readFromNBT(nbtPreset);
|
||||
@ -442,10 +445,14 @@ public class ItemToolAbility extends ItemTool implements IDepthRockTool, IGUIPro
|
||||
presets.add(new ToolPreset());
|
||||
|
||||
availableAbilities.getToolAreaAbilities().forEach((ability, level) -> {
|
||||
if (ability == IToolAreaAbility.NONE)
|
||||
return;
|
||||
presets.add(new ToolPreset(ability, level, IToolHarvestAbility.NONE, 0));
|
||||
});
|
||||
|
||||
availableAbilities.getToolHarvestAbilities().forEach((ability, level) -> {
|
||||
if (ability == IToolHarvestAbility.NONE)
|
||||
return;
|
||||
presets.add(new ToolPreset(IToolAreaAbility.NONE, 0, ability, level));
|
||||
});
|
||||
}
|
||||
@ -478,7 +485,15 @@ public class ItemToolAbility extends ItemTool implements IDepthRockTool, IGUIPro
|
||||
if(!stack.hasTagCompound())
|
||||
stack.stackTagCompound = new NBTTagCompound();
|
||||
|
||||
config.writeToNBT(stack.getTagCompound());
|
||||
config.writeToNBT(stack.stackTagCompound);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void receiveControl(ItemStack stack, NBTTagCompound data) {
|
||||
Configuration config = new Configuration();
|
||||
config.readFromNBT(data);
|
||||
config.restrictTo(availableAbilities);
|
||||
setConfiguration(stack, config);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user