mirror of
https://github.com/HbmMods/Hbm-s-Nuclear-Tech-GIT.git
synced 2026-01-25 10:32:49 +00:00
Switch weapon abilities to the new system
This commit is contained in:
parent
f1184f8731
commit
634836c549
@ -1,14 +1,21 @@
|
||||
package com.hbm.handler.ability;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
|
||||
// All abilities available on a given tool
|
||||
public class AvailableAbilities {
|
||||
private HashMap<IBaseAbility, Integer> abilities = new HashMap<IBaseAbility, Integer>();
|
||||
|
||||
AvailableAbilities() {}
|
||||
public AvailableAbilities() {}
|
||||
|
||||
AvailableAbilities addAbility(IBaseAbility ability, int level) {
|
||||
public AvailableAbilities addAbility(IBaseAbility ability, int level) {
|
||||
if (level < 0 || level >= ability.levels()) {
|
||||
throw new IllegalArgumentException("Illegal level " + level + " for ability " + ability.getName());
|
||||
}
|
||||
@ -17,16 +24,61 @@ public class AvailableAbilities {
|
||||
return this;
|
||||
}
|
||||
|
||||
AvailableAbilities removeAbility(IBaseAbility ability) {
|
||||
public AvailableAbilities addToolAbilities() {
|
||||
addAbility(IToolAreaAbility.NONE, 0);
|
||||
addAbility(IToolHarvestAbility.NONE, 0);
|
||||
return this;
|
||||
}
|
||||
|
||||
public AvailableAbilities removeAbility(IBaseAbility ability) {
|
||||
abilities.remove(ability);
|
||||
return this;
|
||||
}
|
||||
|
||||
boolean supportsAbility(IBaseAbility ability) {
|
||||
public boolean supportsAbility(IBaseAbility ability) {
|
||||
return abilities.containsKey(ability);
|
||||
}
|
||||
|
||||
int maxLevel(IBaseAbility ability) {
|
||||
public int maxLevel(IBaseAbility ability) {
|
||||
return abilities.getOrDefault(ability, -1);
|
||||
}
|
||||
|
||||
public Map<IBaseAbility, Integer> get() {
|
||||
return Collections.unmodifiableMap(abilities);
|
||||
}
|
||||
|
||||
public int size() {
|
||||
return abilities.size();
|
||||
}
|
||||
|
||||
public boolean isEmpty() {
|
||||
return abilities.isEmpty();
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void addInformation(List list) {
|
||||
boolean hasToolAbilities = abilities.keySet().stream().anyMatch(a -> a instanceof IToolAreaAbility || a instanceof IToolHarvestAbility);
|
||||
|
||||
if (hasToolAbilities) {
|
||||
list.add("Abilities: ");
|
||||
|
||||
abilities.forEach((ability, level) -> {
|
||||
list.add(" " + EnumChatFormatting.GOLD + ability.getFullName(level));
|
||||
});
|
||||
|
||||
list.add("Right click to cycle through abilities!");
|
||||
list.add("Sneak-click to turn ability off!");
|
||||
list.add("Alt-click to open ability selection GUI!");
|
||||
}
|
||||
|
||||
boolean hasWeaponModifiers = abilities.keySet().stream().anyMatch(a -> a instanceof IWeaponAbility);
|
||||
|
||||
if (hasWeaponModifiers) {
|
||||
list.add("Weapon modifiers: ");
|
||||
|
||||
abilities.forEach((ability, level) -> {
|
||||
list.add(" " + EnumChatFormatting.RED + ability.getFullName(level));
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -4,7 +4,6 @@ import com.hbm.blocks.ModBlocks;
|
||||
import com.hbm.blocks.generic.BlockBobble.BobbleType;
|
||||
import com.hbm.handler.threading.PacketThreading;
|
||||
import com.hbm.items.ModItems;
|
||||
import com.hbm.items.tool.IItemWithAbility;
|
||||
import com.hbm.lib.ModDamageSource;
|
||||
import com.hbm.packet.toclient.AuxParticlePacketNT;
|
||||
import com.hbm.potion.HbmPotion;
|
||||
@ -26,6 +25,7 @@ import net.minecraft.entity.monster.EntityZombie;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.init.Blocks;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.init.Items;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.nbt.NBTTagCompound;
|
||||
@ -35,7 +35,8 @@ import net.minecraft.util.DamageSource;
|
||||
import net.minecraft.world.World;
|
||||
|
||||
public interface IWeaponAbility extends IBaseAbility {
|
||||
public void onHit(int level, World world, EntityPlayer player, Entity victim, IItemWithAbility tool);
|
||||
// Note: tool is currently unused in weapon abilities
|
||||
public void onHit(int level, World world, EntityPlayer player, Entity victim, Item tool);
|
||||
|
||||
// region handlers
|
||||
public static final IWeaponAbility NONE = new IWeaponAbility() {
|
||||
@ -46,7 +47,7 @@ public interface IWeaponAbility extends IBaseAbility {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onHit(int level, World world, EntityPlayer player, Entity victim, IItemWithAbility tool) {}
|
||||
public void onHit(int level, World world, EntityPlayer player, Entity victim, Item tool) {}
|
||||
};
|
||||
|
||||
public static final IWeaponAbility RADIATION = new IWeaponAbility() {
|
||||
@ -68,7 +69,7 @@ public interface IWeaponAbility extends IBaseAbility {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onHit(int level, World world, EntityPlayer player, Entity victim, IItemWithAbility tool) {
|
||||
public void onHit(int level, World world, EntityPlayer player, Entity victim, Item tool) {
|
||||
if(victim instanceof EntityLivingBase)
|
||||
ContaminationUtil.contaminate((EntityLivingBase)victim, HazardType.RADIATION, ContaminationType.CREATIVE, radAtLevel[level]);
|
||||
}
|
||||
@ -93,7 +94,7 @@ public interface IWeaponAbility extends IBaseAbility {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onHit(int level, World world, EntityPlayer player, Entity victim, IItemWithAbility tool) {
|
||||
public void onHit(int level, World world, EntityPlayer player, Entity victim, Item tool) {
|
||||
float amount = amountAtLevel[level];
|
||||
|
||||
if(victim instanceof EntityLivingBase) {
|
||||
@ -125,7 +126,7 @@ public interface IWeaponAbility extends IBaseAbility {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onHit(int level, World world, EntityPlayer player, Entity victim, IItemWithAbility tool) {
|
||||
public void onHit(int level, World world, EntityPlayer player, Entity victim, Item tool) {
|
||||
int duration = durationAtLevel[level];
|
||||
|
||||
if(victim instanceof EntityLivingBase) {
|
||||
@ -156,7 +157,7 @@ public interface IWeaponAbility extends IBaseAbility {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onHit(int level, World world, EntityPlayer player, Entity victim, IItemWithAbility tool) {
|
||||
public void onHit(int level, World world, EntityPlayer player, Entity victim, Item tool) {
|
||||
int divider = dividerAtLevel[level];
|
||||
|
||||
if(victim instanceof EntityLivingBase) {
|
||||
@ -198,7 +199,7 @@ public interface IWeaponAbility extends IBaseAbility {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onHit(int level, World world, EntityPlayer player, Entity victim, IItemWithAbility tool) {
|
||||
public void onHit(int level, World world, EntityPlayer player, Entity victim, Item tool) {
|
||||
int duration = durationAtLevel[level];
|
||||
|
||||
if(victim instanceof EntityLivingBase) {
|
||||
@ -228,7 +229,7 @@ public interface IWeaponAbility extends IBaseAbility {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onHit(int level, World world, EntityPlayer player, Entity victim, IItemWithAbility tool) {
|
||||
public void onHit(int level, World world, EntityPlayer player, Entity victim, Item tool) {
|
||||
if(victim instanceof EntityLivingBase) {
|
||||
victim.setFire(durationAtLevel[level]);
|
||||
}
|
||||
@ -241,7 +242,7 @@ public interface IWeaponAbility extends IBaseAbility {
|
||||
return "weapon.ability.chainsaw";
|
||||
}
|
||||
|
||||
public final int[] dividerAtLevel = {10, 15};
|
||||
public final int[] dividerAtLevel = {15, 10};
|
||||
|
||||
@Override
|
||||
public int levels() {
|
||||
@ -254,7 +255,7 @@ public interface IWeaponAbility extends IBaseAbility {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onHit(int level, World world, EntityPlayer player, Entity victim, IItemWithAbility tool) {
|
||||
public void onHit(int level, World world, EntityPlayer player, Entity victim, Item tool) {
|
||||
int divider = dividerAtLevel[level];
|
||||
|
||||
if(victim instanceof EntityLivingBase) {
|
||||
@ -291,7 +292,7 @@ public interface IWeaponAbility extends IBaseAbility {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onHit(int level, World world, EntityPlayer player, Entity victim, IItemWithAbility tool) {
|
||||
public void onHit(int level, World world, EntityPlayer player, Entity victim, Item tool) {
|
||||
if(victim instanceof EntityLivingBase && ((EntityLivingBase) victim).getHealth() <= 0.0F) {
|
||||
EntityLivingBase living = (EntityLivingBase) victim;
|
||||
|
||||
@ -332,7 +333,7 @@ public interface IWeaponAbility extends IBaseAbility {
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onHit(int level, World world, EntityPlayer player, Entity victim, IItemWithAbility tool) {
|
||||
public void onHit(int level, World world, EntityPlayer player, Entity victim, Item tool) {
|
||||
if(victim instanceof EntityMob && ((EntityMob) victim).getHealth() <= 0.0F) {
|
||||
EntityMob mob = (EntityMob) victim;
|
||||
|
||||
|
||||
@ -6,6 +6,10 @@ import java.util.List;
|
||||
import org.lwjgl.input.Mouse;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
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.items.tool.ItemToolAbility;
|
||||
import com.hbm.lib.RefStrings;
|
||||
import com.hbm.util.EnumUtil;
|
||||
@ -20,337 +24,373 @@ import net.minecraft.util.ResourceLocation;
|
||||
|
||||
public class GUIScreenToolAbility extends GuiScreen {
|
||||
|
||||
public static ResourceLocation texture = new ResourceLocation(RefStrings.MODID + ":textures/gui/tool/gui_tool_ability.png");
|
||||
|
||||
protected int guiLeft;
|
||||
protected int guiTop;
|
||||
protected int xSize;
|
||||
protected int ySize;
|
||||
protected int insetWidth;
|
||||
public static ResourceLocation texture = new ResourceLocation(RefStrings.MODID + ":textures/gui/tool/gui_tool_ability.png");
|
||||
|
||||
protected int guiLeft;
|
||||
protected int guiTop;
|
||||
protected int xSize;
|
||||
protected int ySize;
|
||||
protected int insetWidth;
|
||||
|
||||
protected ItemToolAbility toolDef;
|
||||
protected ItemStack toolStack;
|
||||
protected ItemToolAbility toolDef;
|
||||
protected ItemStack toolStack;
|
||||
|
||||
// TODO: Move elsewhere?
|
||||
public static class AbilityInfo {
|
||||
String name;
|
||||
int textureU, textureV;
|
||||
boolean hasLevels;
|
||||
public static class AbilityInfo {
|
||||
public IBaseAbility ability;
|
||||
public int textureU, textureV;
|
||||
|
||||
public AbilityInfo(String name, int textureU, int textureV, boolean hasLevels) {
|
||||
this.name = name;
|
||||
this.textureU = textureU;
|
||||
this.textureV = textureV;
|
||||
this.hasLevels = hasLevels;
|
||||
}
|
||||
}
|
||||
public AbilityInfo(IBaseAbility ability, int textureU, int textureV) {
|
||||
this.ability = ability;
|
||||
this.textureU = textureU;
|
||||
this.textureV = textureV;
|
||||
}
|
||||
}
|
||||
|
||||
public static final List<AbilityInfo> abilitiesArea = new ArrayList<>();
|
||||
public static final List<AbilityInfo> abilitiesHarvest = new ArrayList<>();
|
||||
public static final List<AbilityInfo> abilitiesArea = new ArrayList<>();
|
||||
public static final List<AbilityInfo> abilitiesHarvest = new ArrayList<>();
|
||||
|
||||
static {
|
||||
abilitiesArea.add(new AbilityInfo(null, 0, 91, false));
|
||||
abilitiesArea.add(new AbilityInfo("tool.ability.recursion", 32, 91, true));
|
||||
abilitiesArea.add(new AbilityInfo("tool.ability.hammer", 64, 91, true));
|
||||
abilitiesArea.add(new AbilityInfo("tool.ability.explosion", 96, 91, true));
|
||||
|
||||
abilitiesHarvest.add(new AbilityInfo(null, 0, 107, false));
|
||||
abilitiesHarvest.add(new AbilityInfo("tool.ability.silktouch", 32, 107, false));
|
||||
abilitiesHarvest.add(new AbilityInfo("tool.ability.luck", 64, 107, true));
|
||||
abilitiesHarvest.add(new AbilityInfo("tool.ability.smelter", 96, 107, false));
|
||||
abilitiesHarvest.add(new AbilityInfo("tool.ability.shredder", 128, 107, false));
|
||||
abilitiesHarvest.add(new AbilityInfo("tool.ability.centrifuge", 160, 107, false));
|
||||
abilitiesHarvest.add(new AbilityInfo("tool.ability.crystallizer", 192, 107, false));
|
||||
abilitiesHarvest.add(new AbilityInfo("tool.ability.mercury", 224, 107, false));
|
||||
}
|
||||
static {
|
||||
abilitiesArea.add(new AbilityInfo(IToolAreaAbility.NONE, 0, 91));
|
||||
abilitiesArea.add(new AbilityInfo(IToolAreaAbility.RECURSION, 32, 91));
|
||||
abilitiesArea.add(new AbilityInfo(IToolAreaAbility.HAMMER, 64, 91));
|
||||
abilitiesArea.add(new AbilityInfo(IToolAreaAbility.EXPLOSION, 96, 91));
|
||||
|
||||
abilitiesHarvest.add(new AbilityInfo(IToolHarvestAbility.NONE, 0, 107));
|
||||
abilitiesHarvest.add(new AbilityInfo(IToolHarvestAbility.SILK, 32, 107));
|
||||
abilitiesHarvest.add(new AbilityInfo(IToolHarvestAbility.LUCK, 64, 107));
|
||||
abilitiesHarvest.add(new AbilityInfo(IToolHarvestAbility.SMELTER, 96, 107));
|
||||
abilitiesHarvest.add(new AbilityInfo(IToolHarvestAbility.SHREDDER, 128, 107));
|
||||
abilitiesHarvest.add(new AbilityInfo(IToolHarvestAbility.CENTRIFUGE, 160, 107));
|
||||
abilitiesHarvest.add(new AbilityInfo(IToolHarvestAbility.CRYSTALLIZER, 192, 107));
|
||||
abilitiesHarvest.add(new AbilityInfo(IToolHarvestAbility.MERCURY, 224, 107));
|
||||
}
|
||||
|
||||
// TODO: availability status for abilities; list of presets; selected preset index;
|
||||
// TODO: Remove this in favor of current preset
|
||||
int selectionIdxArea = 0;
|
||||
int selectedLevelArea = 0;
|
||||
int selectionIdxHarvest = 0;
|
||||
int selectedLevelHarvest = 0;
|
||||
int selectedPreset = 0;
|
||||
int totalPresets = 1;
|
||||
String selectedPresetName = "lorem ipsum";
|
||||
|
||||
public GUIScreenToolAbility(ItemToolAbility toolDef) {
|
||||
super();
|
||||
|
||||
this.toolDef = toolDef;
|
||||
this.xSize = 186; // Note: increased dynamically
|
||||
this.ySize = 76;
|
||||
// TODO: availability status for abilities; list of presets; selected preset index;
|
||||
// TODO: Remove this in favor of current preset
|
||||
int selectionIdxArea = 0;
|
||||
int selectedLevelArea = 0;
|
||||
int selectionIdxHarvest = 0;
|
||||
int selectedLevelHarvest = 0;
|
||||
int selectedPreset = 0;
|
||||
int totalPresets = 1;
|
||||
|
||||
int hoverIdxArea = -1;
|
||||
int hoverIdxHarvest = -1;
|
||||
int hoverIdxExtraBtn = -1;
|
||||
|
||||
public GUIScreenToolAbility(ItemToolAbility toolDef) {
|
||||
super();
|
||||
|
||||
this.toolDef = toolDef;
|
||||
this.xSize = 186; // Note: increased dynamically
|
||||
this.ySize = 76;
|
||||
|
||||
this.insetWidth = 20 * Math.max(abilitiesArea.size() - 4, abilitiesHarvest.size() - 8);
|
||||
this.xSize += insetWidth;
|
||||
}
|
||||
this.insetWidth = 20 * Math.max(abilitiesArea.size() - 4, abilitiesHarvest.size() - 8);
|
||||
this.xSize += insetWidth;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
this.toolStack = this.mc.thePlayer.getHeldItem();
|
||||
|
||||
if(this.toolStack == null) {
|
||||
doClose();
|
||||
}
|
||||
|
||||
guiLeft = (width - xSize) / 2;
|
||||
guiTop = (height - ySize) / 2;
|
||||
}
|
||||
@Override
|
||||
public void initGui() {
|
||||
this.toolStack = this.mc.thePlayer.getHeldItem();
|
||||
|
||||
if(this.toolStack == null) {
|
||||
doClose();
|
||||
}
|
||||
|
||||
guiLeft = (width - xSize) / 2;
|
||||
guiTop = (height - ySize) / 2;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawScreen(int mouseX, int mouseY, float f) {
|
||||
this.drawDefaultBackground();
|
||||
@Override
|
||||
public void drawScreen(int mouseX, int mouseY, float f) {
|
||||
this.drawDefaultBackground();
|
||||
|
||||
drawGuiContainerBackgroundLayer(mouseX, mouseY);
|
||||
}
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
Minecraft.getMinecraft().getTextureManager().bindTexture(texture);
|
||||
|
||||
protected void drawGuiContainerBackgroundLayer(int mouseX, int mouseY) {
|
||||
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F);
|
||||
Minecraft.getMinecraft().getTextureManager().bindTexture(texture);
|
||||
// Draw window background
|
||||
drawStretchedRect(guiLeft, guiTop, 0, 0, xSize, xSize - insetWidth, ySize, 74, 76);
|
||||
|
||||
// Draw the switches
|
||||
hoverIdxArea = drawSwitches(abilitiesArea, selectionIdxArea, selectedLevelArea, guiLeft + 15, guiTop + 25, mouseX, mouseY);
|
||||
hoverIdxHarvest = drawSwitches(abilitiesHarvest, selectionIdxHarvest, selectedLevelHarvest, guiLeft + 15, guiTop + 45, mouseX, mouseY);
|
||||
|
||||
// Draw window background
|
||||
drawStretchedRect(guiLeft, guiTop, 0, 0, xSize, xSize - insetWidth, ySize, 74, 76);
|
||||
|
||||
// Draw the switches
|
||||
drawSwitches(abilitiesArea, selectionIdxArea, selectedLevelArea, guiLeft + 15, guiTop + 25, mouseX, mouseY);
|
||||
drawSwitches(abilitiesHarvest, selectionIdxHarvest, selectedLevelHarvest, guiLeft + 15, guiTop + 45, mouseX, mouseY);
|
||||
// Draw preset indicator
|
||||
drawNumber(selectedPreset + 1, guiLeft + insetWidth + 115, guiTop + 25);
|
||||
drawNumber(totalPresets, guiLeft + insetWidth + 149, guiTop + 25);
|
||||
|
||||
// Draw preset indicator
|
||||
drawNumber(selectedPreset + 1, guiLeft + insetWidth + 115, guiTop + 25);
|
||||
drawNumber(totalPresets, guiLeft + insetWidth + 149, guiTop + 25);
|
||||
// Draw extra buttons hover highlights
|
||||
int extraBtnsX = guiLeft + xSize - 86;
|
||||
|
||||
hoverIdxExtraBtn = -1;
|
||||
for (int i = 0; i < 7; ++i) {
|
||||
if (isInAABB(mouseX, mouseY, extraBtnsX + i * 11, guiTop + 11, 9, 9)) {
|
||||
hoverIdxExtraBtn = i;
|
||||
drawTexturedModalRect(extraBtnsX + i * 11, guiTop + 11, 193 + i * 9, 0, 9, 9);
|
||||
}
|
||||
}
|
||||
|
||||
// Draw extra buttons hover highlights
|
||||
int extraBtnsX = guiLeft + xSize - 75;
|
||||
// Draw tooltip
|
||||
String tooltipValue = "";
|
||||
|
||||
for (int i = 0; i < 6; ++i) {
|
||||
if (isInAABB(mouseX, mouseY, extraBtnsX + i * 11, guiTop + 11, 9, 9)) {
|
||||
drawTexturedModalRect(extraBtnsX + i * 11, guiTop + 11, 186 + i * 9, 18, 9, 9);
|
||||
}
|
||||
}
|
||||
if (hoverIdxArea != -1) {
|
||||
int level = 0;
|
||||
if (hoverIdxArea == selectionIdxArea) {
|
||||
level = selectedLevelArea;
|
||||
}
|
||||
tooltipValue = abilitiesArea.get(hoverIdxArea).ability.getFullName(level);
|
||||
} else if (hoverIdxHarvest != -1) {
|
||||
int level = 0;
|
||||
if (hoverIdxHarvest == selectionIdxHarvest) {
|
||||
level = selectedLevelHarvest;
|
||||
}
|
||||
tooltipValue = abilitiesHarvest.get(hoverIdxHarvest).ability.getFullName(level);
|
||||
} else if (hoverIdxExtraBtn != -1) {
|
||||
switch (hoverIdxExtraBtn) {
|
||||
case 0: tooltipValue = "Reset all presets"; break;
|
||||
case 1: tooltipValue = "Delete current preset"; break;
|
||||
case 2: tooltipValue = "Add new preset"; break;
|
||||
case 3: tooltipValue = "Select first preset"; break;
|
||||
case 4: tooltipValue = "Next preset"; break;
|
||||
case 5: tooltipValue = "Previous preset"; break;
|
||||
case 6: tooltipValue = "Close window"; break;
|
||||
}
|
||||
}
|
||||
|
||||
// Draw tooltip
|
||||
if (!"".equals(selectedPresetName)) {
|
||||
int tooltipWidth = Math.max(6, fontRendererObj.getStringWidth(selectedPresetName));
|
||||
int tooltipX = guiLeft + xSize / 2 - tooltipWidth / 2;
|
||||
int tooltipY = guiTop + ySize + 1 + 4;
|
||||
drawStretchedRect(tooltipX - 5, tooltipY - 4, 0, 76, tooltipWidth + 10, 186, 15, 3, 3);
|
||||
fontRendererObj.drawString(selectedPresetName, tooltipX, tooltipY, 0xffffffff);
|
||||
}
|
||||
}
|
||||
if (!tooltipValue.isEmpty()) {
|
||||
int tooltipWidth = Math.max(6, fontRendererObj.getStringWidth(tooltipValue));
|
||||
int tooltipX = guiLeft + xSize / 2 - tooltipWidth / 2;
|
||||
int tooltipY = guiTop + ySize + 1 + 4;
|
||||
drawStretchedRect(tooltipX - 5, tooltipY - 4, 0, 76, tooltipWidth + 10, 186, 15, 3, 3);
|
||||
fontRendererObj.drawString(tooltipValue, tooltipX, tooltipY, 0xffffffff);
|
||||
}
|
||||
}
|
||||
|
||||
protected void drawStretchedRect(int x, int y, int u, int v, int realWidth, int width, int height, int keepLeft, int keepRight) {
|
||||
int midWidth = width - keepLeft - keepRight;
|
||||
int realMidWidth = realWidth - keepLeft - keepRight;
|
||||
drawTexturedModalRect(x, y, u, v, keepLeft, height);
|
||||
for (int i = 0; i < realMidWidth; i += midWidth) {
|
||||
drawTexturedModalRect(x + keepLeft + i, y, u + keepLeft, v, Math.min(midWidth, realMidWidth - i), height);
|
||||
}
|
||||
drawTexturedModalRect(x + keepLeft + realMidWidth, y, u + keepLeft + midWidth, v, keepRight, height);
|
||||
}
|
||||
protected void drawStretchedRect(int x, int y, int u, int v, int realWidth, int width, int height, int keepLeft, int keepRight) {
|
||||
int midWidth = width - keepLeft - keepRight;
|
||||
int realMidWidth = realWidth - keepLeft - keepRight;
|
||||
drawTexturedModalRect(x, y, u, v, keepLeft, height);
|
||||
for (int i = 0; i < realMidWidth; i += midWidth) {
|
||||
drawTexturedModalRect(x + keepLeft + i, y, u + keepLeft, v, Math.min(midWidth, realMidWidth - i), height);
|
||||
}
|
||||
drawTexturedModalRect(x + keepLeft + realMidWidth, y, u + keepLeft + midWidth, v, keepRight, height);
|
||||
}
|
||||
|
||||
protected void drawSwitches(List<AbilityInfo> abilities, int selectionIdx, int selectedLevel, int x, int y, int mouseX, int mouseY) {
|
||||
// TODO: Store hovered ability, use it in click handling and the dynamic tooltip
|
||||
|
||||
for (int i = 0; i < abilities.size(); ++i) {
|
||||
AbilityInfo abilityInfo = abilities.get(i);
|
||||
boolean available = true; // TODO
|
||||
protected int drawSwitches(List<AbilityInfo> abilities, int selectionIdx, int selectedLevel, int x, int y, int mouseX, int mouseY) {
|
||||
int hoverIdx = -1;
|
||||
|
||||
// Draw switch
|
||||
drawTexturedModalRect(x + 20 * i, y, abilityInfo.textureU + (available ? 16 : 0), abilityInfo.textureV, 16, 16);
|
||||
|
||||
// Draw level LEDs
|
||||
if (abilityInfo.hasLevels) {
|
||||
int level = 0; // TODO
|
||||
for (int i = 0; i < abilities.size(); ++i) {
|
||||
AbilityInfo abilityInfo = abilities.get(i);
|
||||
boolean available = true; // TODO
|
||||
|
||||
if (i == selectionIdx) {
|
||||
level = selectedLevel + 1;
|
||||
}
|
||||
// Draw switch
|
||||
drawTexturedModalRect(x + 20 * i, y, abilityInfo.textureU + (available ? 16 : 0), abilityInfo.textureV, 16, 16);
|
||||
|
||||
// Draw level LEDs
|
||||
if (abilityInfo.ability.levels() > 1) {
|
||||
int level = 0;
|
||||
|
||||
drawTexturedModalRect(x + 20 * i + 17, y + 1, 222 + level * 2, 0, 2, 14);
|
||||
}
|
||||
if (i == selectionIdx) {
|
||||
level = selectedLevel + 1;
|
||||
}
|
||||
|
||||
if (i == selectionIdx) {
|
||||
// Draw selection highlight
|
||||
drawTexturedModalRect(x + 20 * i - 1, y - 1, 186, 0, 18, 18);
|
||||
} else if (available && isInAABB(mouseX, mouseY, x + 20 * i, y, 16, 16)) {
|
||||
// Draw hover highlight
|
||||
drawTexturedModalRect(x + 20 * i - 1, y - 1, 204, 0, 18, 18);
|
||||
}
|
||||
}
|
||||
}
|
||||
// TODO: Max allowed level instead?
|
||||
// int maxLevel = Math.min(abilityInfo.ability.levels(), 5);
|
||||
int maxLevel = 5;
|
||||
|
||||
if (level > 10 || level < 0) {
|
||||
// All-red LEDs for invalid levels
|
||||
level = -1;
|
||||
}
|
||||
|
||||
protected void drawNumber(int number, int x, int y) {
|
||||
number += 100; // Against accidental negatives
|
||||
drawDigit((number / 10) % 10, x, y);
|
||||
drawDigit(number % 10, x + 12, y);
|
||||
}
|
||||
drawTexturedModalRect(x + 20 * i + 17, y + 1, 188 + level * 2, maxLevel * 14, 2, 14);
|
||||
}
|
||||
|
||||
protected void drawDigit(int digit, int x, int y) {
|
||||
drawTexturedModalRect(x, y, digit * 10, 123, 10, 15);
|
||||
}
|
||||
boolean isHovered = isInAABB(mouseX, mouseY, x + 20 * i, y, 16, 16);
|
||||
|
||||
private boolean isInAABB(int mouseX, int mouseY, int x, int y, int width, int height) {
|
||||
return x <= mouseX && x + width > mouseX && y <= mouseY && y + height > mouseY;
|
||||
}
|
||||
if (isHovered) {
|
||||
hoverIdx = i;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void updateScreen() {
|
||||
EntityPlayer player = this.mc.thePlayer;
|
||||
if (i == selectionIdx) {
|
||||
// Draw selection highlight
|
||||
drawTexturedModalRect(x + 20 * i - 1, y - 1, 220, 9, 18, 18);
|
||||
} else if (available && isHovered) {
|
||||
// Draw hover highlight
|
||||
drawTexturedModalRect(x + 20 * i - 1, y - 1, 238, 9, 18, 18);
|
||||
}
|
||||
}
|
||||
|
||||
if(player.getHeldItem() == null || player.getHeldItem().getItem() != toolDef)
|
||||
player.closeScreen();
|
||||
}
|
||||
return hoverIdx;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handleMouseInput() {
|
||||
super.handleMouseInput();
|
||||
protected void drawNumber(int number, int x, int y) {
|
||||
number += 100; // Against accidental negatives
|
||||
drawDigit((number / 10) % 10, x, y);
|
||||
drawDigit(number % 10, x + 12, y);
|
||||
}
|
||||
|
||||
if(Mouse.getEventButton() == -1) {
|
||||
int scroll = Mouse.getEventDWheel();
|
||||
protected void drawDigit(int digit, int x, int y) {
|
||||
drawTexturedModalRect(x, y, digit * 10, 123, 10, 15);
|
||||
}
|
||||
|
||||
if(scroll > 0 && selectedPreset > 0) selectedPreset -= 1;
|
||||
if(scroll < 0 && selectedPreset < totalPresets) selectedPreset += 1;
|
||||
}
|
||||
}
|
||||
private boolean isInAABB(int mouseX, int mouseY, int x, int y, int width, int height) {
|
||||
return x <= mouseX && x + width > mouseX && y <= mouseY && y + height > mouseY;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseClicked(int mouseX, int mouseY, int button) {
|
||||
// TODO
|
||||
boolean clicked = false;
|
||||
|
||||
// TODO: Encapsulate?
|
||||
for (int i = 0; i < abilitiesArea.size(); ++i) {
|
||||
AbilityInfo abilityInfo = abilitiesArea.get(i);
|
||||
boolean available = true; // TODO
|
||||
@Override
|
||||
public void updateScreen() {
|
||||
EntityPlayer player = this.mc.thePlayer;
|
||||
|
||||
if (available && isInAABB(mouseX, mouseY, guiLeft + 15 + 20 * i, guiTop + 25, 16, 16)) {
|
||||
if (abilityInfo.hasLevels) {
|
||||
int availableLevels = 10;
|
||||
if(player.getHeldItem() == null || player.getHeldItem().getItem() != toolDef)
|
||||
player.closeScreen();
|
||||
}
|
||||
|
||||
if (i == selectionIdxArea) {
|
||||
selectedLevelArea = (selectedLevelArea + 1) % availableLevels;
|
||||
} else {
|
||||
selectedLevelArea = 0;
|
||||
}
|
||||
}
|
||||
@Override
|
||||
public void handleMouseInput() {
|
||||
super.handleMouseInput();
|
||||
|
||||
selectionIdxArea = i;
|
||||
clicked = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(Mouse.getEventButton() == -1) {
|
||||
int scroll = Mouse.getEventDWheel();
|
||||
|
||||
for (int i = 0; i < abilitiesHarvest.size(); ++i) {
|
||||
AbilityInfo abilityInfo = abilitiesHarvest.get(i);
|
||||
boolean available = true; // TODO
|
||||
if(scroll < 0 && selectedPreset > 0) selectedPreset -= 1;
|
||||
if(scroll > 0 && selectedPreset < totalPresets - 1) selectedPreset += 1;
|
||||
}
|
||||
}
|
||||
|
||||
if (available && isInAABB(mouseX, mouseY, guiLeft + 15 + 20 * i, guiTop + 45, 16, 16)) {
|
||||
if (abilityInfo.hasLevels) {
|
||||
int availableLevels = 11;
|
||||
@Override
|
||||
protected void mouseClicked(int mouseX, int mouseY, int button) {
|
||||
// Process switches
|
||||
// TODO: Encapsulate in a method
|
||||
if (hoverIdxArea != -1) {
|
||||
boolean available = true; // TODO
|
||||
|
||||
if (i == selectionIdxHarvest) {
|
||||
selectedLevelHarvest = (selectedLevelHarvest + 1) % availableLevels;
|
||||
} else {
|
||||
selectedLevelHarvest = 0;
|
||||
}
|
||||
}
|
||||
if (available) {
|
||||
int availableLevels = abilitiesArea.get(hoverIdxArea).ability.levels();
|
||||
|
||||
selectionIdxHarvest = i;
|
||||
clicked = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (hoverIdxArea != selectionIdxArea || availableLevels > 1) {
|
||||
mc.getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("hbm:item.techBoop"), 2F));
|
||||
}
|
||||
|
||||
if (clicked) {
|
||||
mc.getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("hbm:item.techBoop"), 2F));
|
||||
}
|
||||
|
||||
// TODO
|
||||
int extraBtnsX = guiLeft + xSize - 75;
|
||||
if (hoverIdxArea == selectionIdxArea) {
|
||||
selectedLevelArea = (selectedLevelArea + 1) % availableLevels;
|
||||
} else {
|
||||
selectedLevelArea = 0;
|
||||
}
|
||||
|
||||
clicked = false;
|
||||
selectionIdxArea = hoverIdxArea;
|
||||
}
|
||||
}
|
||||
|
||||
if (isInAABB(mouseX, mouseY, extraBtnsX + 0 * 11, guiTop + 11, 9, 9)) {
|
||||
doDelPreset();
|
||||
clicked = true;
|
||||
}
|
||||
if (hoverIdxHarvest != -1) {
|
||||
boolean available = true; // TODO
|
||||
|
||||
if (isInAABB(mouseX, mouseY, extraBtnsX + 1 * 11, guiTop + 11, 9, 9)) {
|
||||
doAddPreset();
|
||||
clicked = true;
|
||||
}
|
||||
if (available) {
|
||||
int availableLevels = abilitiesHarvest.get(hoverIdxHarvest).ability.levels();
|
||||
|
||||
if (isInAABB(mouseX, mouseY, extraBtnsX + 2 * 11, guiTop + 11, 9, 9)) {
|
||||
doZeroPreset();
|
||||
clicked = true;
|
||||
}
|
||||
if (hoverIdxHarvest == selectionIdxHarvest) {
|
||||
selectedLevelHarvest = (selectedLevelHarvest + 1) % availableLevels;
|
||||
} else {
|
||||
selectedLevelHarvest = 0;
|
||||
}
|
||||
|
||||
if (isInAABB(mouseX, mouseY, extraBtnsX + 3 * 11, guiTop + 11, 9, 9)) {
|
||||
doNextPreset();
|
||||
clicked = true;
|
||||
}
|
||||
selectionIdxHarvest = hoverIdxHarvest;
|
||||
|
||||
if (isInAABB(mouseX, mouseY, extraBtnsX + 4 * 11, guiTop + 11, 9, 9)) {
|
||||
doPrevPreset();
|
||||
clicked = true;
|
||||
}
|
||||
mc.getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("hbm:item.techBoop"), 2F));
|
||||
}
|
||||
}
|
||||
|
||||
// Process extra buttons
|
||||
if (hoverIdxExtraBtn != -1) {
|
||||
switch (hoverIdxExtraBtn) {
|
||||
case 0:
|
||||
doResetPresets();
|
||||
break;
|
||||
case 1:
|
||||
doDelPreset();
|
||||
break;
|
||||
case 2:
|
||||
doAddPreset();
|
||||
break;
|
||||
case 3:
|
||||
doZeroPreset();
|
||||
break;
|
||||
case 4:
|
||||
doNextPreset();
|
||||
break;
|
||||
case 5:
|
||||
doPrevPreset();
|
||||
break;
|
||||
case 6:
|
||||
doClose();
|
||||
break;
|
||||
}
|
||||
|
||||
if (isInAABB(mouseX, mouseY, extraBtnsX + 5 * 11, guiTop + 11, 9, 9)) {
|
||||
doClose();
|
||||
clicked = true;
|
||||
}
|
||||
mc.getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 0.5F));
|
||||
}
|
||||
|
||||
if (clicked) {
|
||||
mc.getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 0.5F));
|
||||
}
|
||||
}
|
||||
// Allow quick-closing
|
||||
if (!isInAABB(mouseX, mouseY, guiLeft, guiTop, xSize, ySize)) {
|
||||
doClose();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void keyTyped(char c, int key) {
|
||||
if(key == 1 || key == this.mc.gameSettings.keyBindInventory.getKeyCode()) {
|
||||
doClose();
|
||||
return;
|
||||
}
|
||||
|
||||
super.keyTyped(c, key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doesGuiPauseGame() {
|
||||
return false;
|
||||
}
|
||||
@Override
|
||||
protected void keyTyped(char c, int key) {
|
||||
if(key == 1 || key == this.mc.gameSettings.keyBindInventory.getKeyCode()) {
|
||||
doClose();
|
||||
return;
|
||||
}
|
||||
|
||||
super.keyTyped(c, key);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean doesGuiPauseGame() {
|
||||
return false;
|
||||
}
|
||||
|
||||
protected void doDelPreset() {
|
||||
// TODO
|
||||
if (totalPresets <= 1) {
|
||||
return;
|
||||
}
|
||||
totalPresets -= 1;
|
||||
selectedPreset -= 1;
|
||||
}
|
||||
protected void doResetPresets() {
|
||||
// TODO
|
||||
totalPresets = 1;
|
||||
selectedPreset = 0;
|
||||
selectionIdxArea = 0;
|
||||
selectedLevelArea = 0;
|
||||
selectionIdxHarvest = 0;
|
||||
selectedLevelHarvest = 0;
|
||||
}
|
||||
|
||||
protected void doAddPreset() {
|
||||
// TODO
|
||||
totalPresets += 1;
|
||||
selectedPreset += 1;
|
||||
}
|
||||
protected void doDelPreset() {
|
||||
// TODO
|
||||
if (totalPresets <= 1) {
|
||||
return;
|
||||
}
|
||||
totalPresets -= 1;
|
||||
selectedPreset -= 1;
|
||||
}
|
||||
|
||||
protected void doZeroPreset() {
|
||||
// TODO
|
||||
selectedPreset = 0;
|
||||
}
|
||||
protected void doAddPreset() {
|
||||
// TODO
|
||||
totalPresets += 1;
|
||||
selectedPreset += 1;
|
||||
}
|
||||
|
||||
protected void doNextPreset() {
|
||||
// TODO
|
||||
selectedPreset = (selectedPreset + 1) % totalPresets;
|
||||
}
|
||||
protected void doZeroPreset() {
|
||||
// TODO
|
||||
selectedPreset = 0;
|
||||
}
|
||||
|
||||
protected void doPrevPreset() {
|
||||
// TODO
|
||||
selectedPreset = (selectedPreset + totalPresets - 1) % totalPresets;
|
||||
}
|
||||
protected void doNextPreset() {
|
||||
// TODO
|
||||
selectedPreset = (selectedPreset + 1) % totalPresets;
|
||||
}
|
||||
|
||||
protected void doClose() {
|
||||
this.mc.thePlayer.closeScreen();
|
||||
}
|
||||
protected void doPrevPreset() {
|
||||
// TODO
|
||||
selectedPreset = (selectedPreset + totalPresets - 1) % totalPresets;
|
||||
}
|
||||
|
||||
protected void doClose() {
|
||||
this.mc.thePlayer.closeScreen();
|
||||
}
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
@ -1,11 +1,11 @@
|
||||
package com.hbm.items.tool;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import com.google.common.collect.HashMultimap;
|
||||
import com.google.common.collect.Multimap;
|
||||
import com.hbm.handler.WeaponAbility;
|
||||
import com.hbm.handler.ability.AvailableAbilities;
|
||||
import com.hbm.handler.ability.IWeaponAbility;
|
||||
import com.hbm.items.ModItems;
|
||||
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
@ -19,13 +19,13 @@ import net.minecraft.item.ItemStack;
|
||||
import net.minecraft.item.ItemSword;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
|
||||
public class ItemSwordAbility extends ItemSword implements IItemWithAbility {
|
||||
public class ItemSwordAbility extends ItemSword {
|
||||
|
||||
private EnumRarity rarity = EnumRarity.common;
|
||||
// was there a reason for this to be private?
|
||||
protected float damage;
|
||||
protected double movement;
|
||||
private List<WeaponAbility> hitAbility = new ArrayList();
|
||||
private AvailableAbilities hitAbilities = new AvailableAbilities();
|
||||
|
||||
public ItemSwordAbility(float damage, double movement, ToolMaterial material) {
|
||||
super(material);
|
||||
@ -33,8 +33,8 @@ public class ItemSwordAbility extends ItemSword implements IItemWithAbility {
|
||||
this.movement = movement;
|
||||
}
|
||||
|
||||
public ItemSwordAbility addHitAbility(WeaponAbility weaponAbility) {
|
||||
this.hitAbility.add(weaponAbility);
|
||||
public ItemSwordAbility addHitAbility(IWeaponAbility weaponAbility, int level) {
|
||||
this.hitAbilities.addAbility(weaponAbility, level);
|
||||
return this;
|
||||
}
|
||||
|
||||
@ -50,15 +50,15 @@ public class ItemSwordAbility extends ItemSword implements IItemWithAbility {
|
||||
|
||||
public boolean hitEntity(ItemStack stack, EntityLivingBase victim, EntityLivingBase attacker) {
|
||||
|
||||
if(!attacker.worldObj.isRemote && !this.hitAbility.isEmpty() && attacker instanceof EntityPlayer && canOperate(stack)) {
|
||||
if(!attacker.worldObj.isRemote && attacker instanceof EntityPlayer && canOperate(stack)) {
|
||||
|
||||
// hacky hacky hack
|
||||
if(this == ModItems.mese_gavel)
|
||||
attacker.worldObj.playSoundAtEntity(victim, "hbm:weapon.whack", 3.0F, 1.F);
|
||||
|
||||
for(WeaponAbility ability : this.hitAbility) {
|
||||
ability.onHit(attacker.worldObj, (EntityPlayer) attacker, victim, this);
|
||||
}
|
||||
this.hitAbilities.get().forEach((ability, level) -> {
|
||||
((IWeaponAbility)ability).onHit(level, attacker.worldObj, (EntityPlayer) attacker, victim, this);
|
||||
});
|
||||
}
|
||||
|
||||
stack.damageItem(1, attacker);
|
||||
@ -77,23 +77,10 @@ public class ItemSwordAbility extends ItemSword implements IItemWithAbility {
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean ext) {
|
||||
|
||||
if(!this.hitAbility.isEmpty()) {
|
||||
|
||||
list.add("Weapon modifiers: ");
|
||||
|
||||
for(WeaponAbility ability : this.hitAbility) {
|
||||
list.add(" " + EnumChatFormatting.RED + ability.getFullName());
|
||||
}
|
||||
}
|
||||
hitAbilities.addInformation(list);
|
||||
}
|
||||
|
||||
protected boolean canOperate(ItemStack stack) {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean isShears(ItemStack stack) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 4.0 KiB After Width: | Height: | Size: 4.4 KiB |
Loading…
x
Reference in New Issue
Block a user