Switch weapon abilities to the new system

This commit is contained in:
abel1502 2025-05-17 18:37:09 +03:00
parent f1184f8731
commit 634836c549
No known key found for this signature in database
GPG Key ID: 076926596A536338
6 changed files with 7623 additions and 7542 deletions

View File

@ -1,14 +1,21 @@
package com.hbm.handler.ability; package com.hbm.handler.ability;
import java.util.Collections;
import java.util.HashMap; 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 // All abilities available on a given tool
public class AvailableAbilities { public class AvailableAbilities {
private HashMap<IBaseAbility, Integer> abilities = new HashMap<IBaseAbility, Integer>(); 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()) { if (level < 0 || level >= ability.levels()) {
throw new IllegalArgumentException("Illegal level " + level + " for ability " + ability.getName()); throw new IllegalArgumentException("Illegal level " + level + " for ability " + ability.getName());
} }
@ -17,16 +24,61 @@ public class AvailableAbilities {
return this; 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); abilities.remove(ability);
return this; return this;
} }
boolean supportsAbility(IBaseAbility ability) { public boolean supportsAbility(IBaseAbility ability) {
return abilities.containsKey(ability); return abilities.containsKey(ability);
} }
int maxLevel(IBaseAbility ability) { public int maxLevel(IBaseAbility ability) {
return abilities.getOrDefault(ability, -1); 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));
});
}
}
} }

View File

@ -4,7 +4,6 @@ import com.hbm.blocks.ModBlocks;
import com.hbm.blocks.generic.BlockBobble.BobbleType; import com.hbm.blocks.generic.BlockBobble.BobbleType;
import com.hbm.handler.threading.PacketThreading; import com.hbm.handler.threading.PacketThreading;
import com.hbm.items.ModItems; import com.hbm.items.ModItems;
import com.hbm.items.tool.IItemWithAbility;
import com.hbm.lib.ModDamageSource; import com.hbm.lib.ModDamageSource;
import com.hbm.packet.toclient.AuxParticlePacketNT; import com.hbm.packet.toclient.AuxParticlePacketNT;
import com.hbm.potion.HbmPotion; 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.EntityPlayer;
import net.minecraft.entity.player.EntityPlayerMP; import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.init.Blocks; import net.minecraft.init.Blocks;
import net.minecraft.item.Item;
import net.minecraft.init.Items; import net.minecraft.init.Items;
import net.minecraft.item.ItemStack; import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
@ -35,7 +35,8 @@ import net.minecraft.util.DamageSource;
import net.minecraft.world.World; import net.minecraft.world.World;
public interface IWeaponAbility extends IBaseAbility { 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 // region handlers
public static final IWeaponAbility NONE = new IWeaponAbility() { public static final IWeaponAbility NONE = new IWeaponAbility() {
@ -46,7 +47,7 @@ public interface IWeaponAbility extends IBaseAbility {
} }
@Override @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() { public static final IWeaponAbility RADIATION = new IWeaponAbility() {
@ -68,7 +69,7 @@ public interface IWeaponAbility extends IBaseAbility {
} }
@Override @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) if(victim instanceof EntityLivingBase)
ContaminationUtil.contaminate((EntityLivingBase)victim, HazardType.RADIATION, ContaminationType.CREATIVE, radAtLevel[level]); ContaminationUtil.contaminate((EntityLivingBase)victim, HazardType.RADIATION, ContaminationType.CREATIVE, radAtLevel[level]);
} }
@ -93,7 +94,7 @@ public interface IWeaponAbility extends IBaseAbility {
} }
@Override @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]; float amount = amountAtLevel[level];
if(victim instanceof EntityLivingBase) { if(victim instanceof EntityLivingBase) {
@ -125,7 +126,7 @@ public interface IWeaponAbility extends IBaseAbility {
} }
@Override @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]; int duration = durationAtLevel[level];
if(victim instanceof EntityLivingBase) { if(victim instanceof EntityLivingBase) {
@ -156,7 +157,7 @@ public interface IWeaponAbility extends IBaseAbility {
} }
@Override @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]; int divider = dividerAtLevel[level];
if(victim instanceof EntityLivingBase) { if(victim instanceof EntityLivingBase) {
@ -198,7 +199,7 @@ public interface IWeaponAbility extends IBaseAbility {
} }
@Override @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]; int duration = durationAtLevel[level];
if(victim instanceof EntityLivingBase) { if(victim instanceof EntityLivingBase) {
@ -228,7 +229,7 @@ public interface IWeaponAbility extends IBaseAbility {
} }
@Override @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) { if(victim instanceof EntityLivingBase) {
victim.setFire(durationAtLevel[level]); victim.setFire(durationAtLevel[level]);
} }
@ -241,7 +242,7 @@ public interface IWeaponAbility extends IBaseAbility {
return "weapon.ability.chainsaw"; return "weapon.ability.chainsaw";
} }
public final int[] dividerAtLevel = {10, 15}; public final int[] dividerAtLevel = {15, 10};
@Override @Override
public int levels() { public int levels() {
@ -254,7 +255,7 @@ public interface IWeaponAbility extends IBaseAbility {
} }
@Override @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]; int divider = dividerAtLevel[level];
if(victim instanceof EntityLivingBase) { if(victim instanceof EntityLivingBase) {
@ -291,7 +292,7 @@ public interface IWeaponAbility extends IBaseAbility {
} }
@Override @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) { if(victim instanceof EntityLivingBase && ((EntityLivingBase) victim).getHealth() <= 0.0F) {
EntityLivingBase living = (EntityLivingBase) victim; EntityLivingBase living = (EntityLivingBase) victim;
@ -332,7 +333,7 @@ public interface IWeaponAbility extends IBaseAbility {
} }
@Override @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) { if(victim instanceof EntityMob && ((EntityMob) victim).getHealth() <= 0.0F) {
EntityMob mob = (EntityMob) victim; EntityMob mob = (EntityMob) victim;

View File

@ -6,6 +6,10 @@ import java.util.List;
import org.lwjgl.input.Mouse; import org.lwjgl.input.Mouse;
import org.lwjgl.opengl.GL11; 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.items.tool.ItemToolAbility;
import com.hbm.lib.RefStrings; import com.hbm.lib.RefStrings;
import com.hbm.util.EnumUtil; import com.hbm.util.EnumUtil;
@ -20,337 +24,373 @@ import net.minecraft.util.ResourceLocation;
public class GUIScreenToolAbility extends GuiScreen { public class GUIScreenToolAbility extends GuiScreen {
public static ResourceLocation texture = new ResourceLocation(RefStrings.MODID + ":textures/gui/tool/gui_tool_ability.png"); public static ResourceLocation texture = new ResourceLocation(RefStrings.MODID + ":textures/gui/tool/gui_tool_ability.png");
protected int guiLeft; protected int guiLeft;
protected int guiTop; protected int guiTop;
protected int xSize; protected int xSize;
protected int ySize; protected int ySize;
protected int insetWidth; protected int insetWidth;
protected ItemToolAbility toolDef; protected ItemToolAbility toolDef;
protected ItemStack toolStack; protected ItemStack toolStack;
// TODO: Move elsewhere? public static class AbilityInfo {
public static class AbilityInfo { public IBaseAbility ability;
String name; public int textureU, textureV;
int textureU, textureV;
boolean hasLevels;
public AbilityInfo(String name, int textureU, int textureV, boolean hasLevels) { public AbilityInfo(IBaseAbility ability, int textureU, int textureV) {
this.name = name; this.ability = ability;
this.textureU = textureU; this.textureU = textureU;
this.textureV = textureV; this.textureV = textureV;
this.hasLevels = hasLevels; }
} }
}
public static final List<AbilityInfo> abilitiesArea = new ArrayList<>(); public static final List<AbilityInfo> abilitiesArea = new ArrayList<>();
public static final List<AbilityInfo> abilitiesHarvest = new ArrayList<>(); public static final List<AbilityInfo> abilitiesHarvest = new ArrayList<>();
static { static {
abilitiesArea.add(new AbilityInfo(null, 0, 91, false)); abilitiesArea.add(new AbilityInfo(IToolAreaAbility.NONE, 0, 91));
abilitiesArea.add(new AbilityInfo("tool.ability.recursion", 32, 91, true)); abilitiesArea.add(new AbilityInfo(IToolAreaAbility.RECURSION, 32, 91));
abilitiesArea.add(new AbilityInfo("tool.ability.hammer", 64, 91, true)); abilitiesArea.add(new AbilityInfo(IToolAreaAbility.HAMMER, 64, 91));
abilitiesArea.add(new AbilityInfo("tool.ability.explosion", 96, 91, true)); abilitiesArea.add(new AbilityInfo(IToolAreaAbility.EXPLOSION, 96, 91));
abilitiesHarvest.add(new AbilityInfo(null, 0, 107, false)); abilitiesHarvest.add(new AbilityInfo(IToolHarvestAbility.NONE, 0, 107));
abilitiesHarvest.add(new AbilityInfo("tool.ability.silktouch", 32, 107, false)); abilitiesHarvest.add(new AbilityInfo(IToolHarvestAbility.SILK, 32, 107));
abilitiesHarvest.add(new AbilityInfo("tool.ability.luck", 64, 107, true)); abilitiesHarvest.add(new AbilityInfo(IToolHarvestAbility.LUCK, 64, 107));
abilitiesHarvest.add(new AbilityInfo("tool.ability.smelter", 96, 107, false)); abilitiesHarvest.add(new AbilityInfo(IToolHarvestAbility.SMELTER, 96, 107));
abilitiesHarvest.add(new AbilityInfo("tool.ability.shredder", 128, 107, false)); abilitiesHarvest.add(new AbilityInfo(IToolHarvestAbility.SHREDDER, 128, 107));
abilitiesHarvest.add(new AbilityInfo("tool.ability.centrifuge", 160, 107, false)); abilitiesHarvest.add(new AbilityInfo(IToolHarvestAbility.CENTRIFUGE, 160, 107));
abilitiesHarvest.add(new AbilityInfo("tool.ability.crystallizer", 192, 107, false)); abilitiesHarvest.add(new AbilityInfo(IToolHarvestAbility.CRYSTALLIZER, 192, 107));
abilitiesHarvest.add(new AbilityInfo("tool.ability.mercury", 224, 107, false)); abilitiesHarvest.add(new AbilityInfo(IToolHarvestAbility.MERCURY, 224, 107));
} }
// TODO: availability status for abilities; list of presets; selected preset index; // TODO: availability status for abilities; list of presets; selected preset index;
// TODO: Remove this in favor of current preset // TODO: Remove this in favor of current preset
int selectionIdxArea = 0; int selectionIdxArea = 0;
int selectedLevelArea = 0; int selectedLevelArea = 0;
int selectionIdxHarvest = 0; int selectionIdxHarvest = 0;
int selectedLevelHarvest = 0; int selectedLevelHarvest = 0;
int selectedPreset = 0; int selectedPreset = 0;
int totalPresets = 1; int totalPresets = 1;
String selectedPresetName = "lorem ipsum";
int hoverIdxArea = -1;
public GUIScreenToolAbility(ItemToolAbility toolDef) { int hoverIdxHarvest = -1;
super(); int hoverIdxExtraBtn = -1;
this.toolDef = toolDef; public GUIScreenToolAbility(ItemToolAbility toolDef) {
this.xSize = 186; // Note: increased dynamically super();
this.ySize = 76;
this.toolDef = toolDef;
this.xSize = 186; // Note: increased dynamically
this.ySize = 76;
this.insetWidth = 20 * Math.max(abilitiesArea.size() - 4, abilitiesHarvest.size() - 8); this.insetWidth = 20 * Math.max(abilitiesArea.size() - 4, abilitiesHarvest.size() - 8);
this.xSize += insetWidth; this.xSize += insetWidth;
} }
@Override @Override
public void initGui() { public void initGui() {
this.toolStack = this.mc.thePlayer.getHeldItem(); this.toolStack = this.mc.thePlayer.getHeldItem();
if(this.toolStack == null) { if(this.toolStack == null) {
doClose(); doClose();
} }
guiLeft = (width - xSize) / 2; guiLeft = (width - xSize) / 2;
guiTop = (height - ySize) / 2; guiTop = (height - ySize) / 2;
} }
@Override @Override
public void drawScreen(int mouseX, int mouseY, float f) { public void drawScreen(int mouseX, int mouseY, float f) {
this.drawDefaultBackground(); 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) { // Draw window background
GL11.glColor4f(1.0F, 1.0F, 1.0F, 1.0F); drawStretchedRect(guiLeft, guiTop, 0, 0, xSize, xSize - insetWidth, ySize, 74, 76);
Minecraft.getMinecraft().getTextureManager().bindTexture(texture);
// 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 // Draw preset indicator
drawStretchedRect(guiLeft, guiTop, 0, 0, xSize, xSize - insetWidth, ySize, 74, 76); drawNumber(selectedPreset + 1, guiLeft + insetWidth + 115, guiTop + 25);
drawNumber(totalPresets, guiLeft + insetWidth + 149, guiTop + 25);
// 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 // Draw extra buttons hover highlights
drawNumber(selectedPreset + 1, guiLeft + insetWidth + 115, guiTop + 25); int extraBtnsX = guiLeft + xSize - 86;
drawNumber(totalPresets, guiLeft + insetWidth + 149, guiTop + 25);
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 // Draw tooltip
int extraBtnsX = guiLeft + xSize - 75; String tooltipValue = "";
for (int i = 0; i < 6; ++i) { if (hoverIdxArea != -1) {
if (isInAABB(mouseX, mouseY, extraBtnsX + i * 11, guiTop + 11, 9, 9)) { int level = 0;
drawTexturedModalRect(extraBtnsX + i * 11, guiTop + 11, 186 + i * 9, 18, 9, 9); 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 (!tooltipValue.isEmpty()) {
if (!"".equals(selectedPresetName)) { int tooltipWidth = Math.max(6, fontRendererObj.getStringWidth(tooltipValue));
int tooltipWidth = Math.max(6, fontRendererObj.getStringWidth(selectedPresetName)); int tooltipX = guiLeft + xSize / 2 - tooltipWidth / 2;
int tooltipX = guiLeft + xSize / 2 - tooltipWidth / 2; int tooltipY = guiTop + ySize + 1 + 4;
int tooltipY = guiTop + ySize + 1 + 4; drawStretchedRect(tooltipX - 5, tooltipY - 4, 0, 76, tooltipWidth + 10, 186, 15, 3, 3);
drawStretchedRect(tooltipX - 5, tooltipY - 4, 0, 76, tooltipWidth + 10, 186, 15, 3, 3); fontRendererObj.drawString(tooltipValue, tooltipX, tooltipY, 0xffffffff);
fontRendererObj.drawString(selectedPresetName, tooltipX, tooltipY, 0xffffffff); }
} }
}
protected void drawStretchedRect(int x, int y, int u, int v, int realWidth, int width, int height, int keepLeft, int keepRight) { 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 midWidth = width - keepLeft - keepRight;
int realMidWidth = realWidth - keepLeft - keepRight; int realMidWidth = realWidth - keepLeft - keepRight;
drawTexturedModalRect(x, y, u, v, keepLeft, height); drawTexturedModalRect(x, y, u, v, keepLeft, height);
for (int i = 0; i < realMidWidth; i += midWidth) { 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 + i, y, u + keepLeft, v, Math.min(midWidth, realMidWidth - i), height);
} }
drawTexturedModalRect(x + keepLeft + realMidWidth, y, u + keepLeft + midWidth, v, keepRight, 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) { protected int 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 int hoverIdx = -1;
for (int i = 0; i < abilities.size(); ++i) {
AbilityInfo abilityInfo = abilities.get(i);
boolean available = true; // TODO
// Draw switch for (int i = 0; i < abilities.size(); ++i) {
drawTexturedModalRect(x + 20 * i, y, abilityInfo.textureU + (available ? 16 : 0), abilityInfo.textureV, 16, 16); AbilityInfo abilityInfo = abilities.get(i);
boolean available = true; // TODO
// Draw level LEDs
if (abilityInfo.hasLevels) {
int level = 0; // TODO
if (i == selectionIdx) { // Draw switch
level = selectedLevel + 1; 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) { // TODO: Max allowed level instead?
// Draw selection highlight // int maxLevel = Math.min(abilityInfo.ability.levels(), 5);
drawTexturedModalRect(x + 20 * i - 1, y - 1, 186, 0, 18, 18); int maxLevel = 5;
} else if (available && isInAABB(mouseX, mouseY, x + 20 * i, y, 16, 16)) {
// Draw hover highlight if (level > 10 || level < 0) {
drawTexturedModalRect(x + 20 * i - 1, y - 1, 204, 0, 18, 18); // All-red LEDs for invalid levels
} level = -1;
} }
}
protected void drawNumber(int number, int x, int y) { drawTexturedModalRect(x + 20 * i + 17, y + 1, 188 + level * 2, maxLevel * 14, 2, 14);
number += 100; // Against accidental negatives }
drawDigit((number / 10) % 10, x, y);
drawDigit(number % 10, x + 12, y);
}
protected void drawDigit(int digit, int x, int y) { boolean isHovered = isInAABB(mouseX, mouseY, x + 20 * i, y, 16, 16);
drawTexturedModalRect(x, y, digit * 10, 123, 10, 15);
}
private boolean isInAABB(int mouseX, int mouseY, int x, int y, int width, int height) { if (isHovered) {
return x <= mouseX && x + width > mouseX && y <= mouseY && y + height > mouseY; hoverIdx = i;
} }
@Override if (i == selectionIdx) {
public void updateScreen() { // Draw selection highlight
EntityPlayer player = this.mc.thePlayer; 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) return hoverIdx;
player.closeScreen(); }
}
@Override protected void drawNumber(int number, int x, int y) {
public void handleMouseInput() { number += 100; // Against accidental negatives
super.handleMouseInput(); drawDigit((number / 10) % 10, x, y);
drawDigit(number % 10, x + 12, y);
}
if(Mouse.getEventButton() == -1) { protected void drawDigit(int digit, int x, int y) {
int scroll = Mouse.getEventDWheel(); drawTexturedModalRect(x, y, digit * 10, 123, 10, 15);
}
if(scroll > 0 && selectedPreset > 0) selectedPreset -= 1; private boolean isInAABB(int mouseX, int mouseY, int x, int y, int width, int height) {
if(scroll < 0 && selectedPreset < totalPresets) selectedPreset += 1; return x <= mouseX && x + width > mouseX && y <= mouseY && y + height > mouseY;
} }
}
@Override @Override
protected void mouseClicked(int mouseX, int mouseY, int button) { public void updateScreen() {
// TODO EntityPlayer player = this.mc.thePlayer;
boolean clicked = false;
// TODO: Encapsulate?
for (int i = 0; i < abilitiesArea.size(); ++i) {
AbilityInfo abilityInfo = abilitiesArea.get(i);
boolean available = true; // TODO
if (available && isInAABB(mouseX, mouseY, guiLeft + 15 + 20 * i, guiTop + 25, 16, 16)) { if(player.getHeldItem() == null || player.getHeldItem().getItem() != toolDef)
if (abilityInfo.hasLevels) { player.closeScreen();
int availableLevels = 10; }
if (i == selectionIdxArea) { @Override
selectedLevelArea = (selectedLevelArea + 1) % availableLevels; public void handleMouseInput() {
} else { super.handleMouseInput();
selectedLevelArea = 0;
}
}
selectionIdxArea = i; if(Mouse.getEventButton() == -1) {
clicked = true; int scroll = Mouse.getEventDWheel();
break;
}
}
for (int i = 0; i < abilitiesHarvest.size(); ++i) { if(scroll < 0 && selectedPreset > 0) selectedPreset -= 1;
AbilityInfo abilityInfo = abilitiesHarvest.get(i); if(scroll > 0 && selectedPreset < totalPresets - 1) selectedPreset += 1;
boolean available = true; // TODO }
}
if (available && isInAABB(mouseX, mouseY, guiLeft + 15 + 20 * i, guiTop + 45, 16, 16)) { @Override
if (abilityInfo.hasLevels) { protected void mouseClicked(int mouseX, int mouseY, int button) {
int availableLevels = 11; // Process switches
// TODO: Encapsulate in a method
if (hoverIdxArea != -1) {
boolean available = true; // TODO
if (i == selectionIdxHarvest) { if (available) {
selectedLevelHarvest = (selectedLevelHarvest + 1) % availableLevels; int availableLevels = abilitiesArea.get(hoverIdxArea).ability.levels();
} else {
selectedLevelHarvest = 0;
}
}
selectionIdxHarvest = i; if (hoverIdxArea != selectionIdxArea || availableLevels > 1) {
clicked = true; mc.getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("hbm:item.techBoop"), 2F));
break; }
}
}
if (clicked) { if (hoverIdxArea == selectionIdxArea) {
mc.getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("hbm:item.techBoop"), 2F)); selectedLevelArea = (selectedLevelArea + 1) % availableLevels;
} } else {
selectedLevelArea = 0;
// TODO }
int extraBtnsX = guiLeft + xSize - 75;
clicked = false; selectionIdxArea = hoverIdxArea;
}
}
if (isInAABB(mouseX, mouseY, extraBtnsX + 0 * 11, guiTop + 11, 9, 9)) { if (hoverIdxHarvest != -1) {
doDelPreset(); boolean available = true; // TODO
clicked = true;
}
if (isInAABB(mouseX, mouseY, extraBtnsX + 1 * 11, guiTop + 11, 9, 9)) { if (available) {
doAddPreset(); int availableLevels = abilitiesHarvest.get(hoverIdxHarvest).ability.levels();
clicked = true;
}
if (isInAABB(mouseX, mouseY, extraBtnsX + 2 * 11, guiTop + 11, 9, 9)) { if (hoverIdxHarvest == selectionIdxHarvest) {
doZeroPreset(); selectedLevelHarvest = (selectedLevelHarvest + 1) % availableLevels;
clicked = true; } else {
} selectedLevelHarvest = 0;
}
if (isInAABB(mouseX, mouseY, extraBtnsX + 3 * 11, guiTop + 11, 9, 9)) { selectionIdxHarvest = hoverIdxHarvest;
doNextPreset();
clicked = true;
}
if (isInAABB(mouseX, mouseY, extraBtnsX + 4 * 11, guiTop + 11, 9, 9)) { mc.getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("hbm:item.techBoop"), 2F));
doPrevPreset(); }
clicked = true; }
}
// 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)) { mc.getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 0.5F));
doClose(); }
clicked = true;
}
if (clicked) { // Allow quick-closing
mc.getSoundHandler().playSound(PositionedSoundRecord.func_147674_a(new ResourceLocation("gui.button.press"), 0.5F)); if (!isInAABB(mouseX, mouseY, guiLeft, guiTop, xSize, ySize)) {
} doClose();
} }
}
@Override @Override
protected void keyTyped(char c, int key) { protected void keyTyped(char c, int key) {
if(key == 1 || key == this.mc.gameSettings.keyBindInventory.getKeyCode()) { if(key == 1 || key == this.mc.gameSettings.keyBindInventory.getKeyCode()) {
doClose(); doClose();
return; return;
} }
super.keyTyped(c, key); super.keyTyped(c, key);
} }
@Override @Override
public boolean doesGuiPauseGame() { public boolean doesGuiPauseGame() {
return false; return false;
} }
protected void doDelPreset() { protected void doResetPresets() {
// TODO // TODO
if (totalPresets <= 1) { totalPresets = 1;
return; selectedPreset = 0;
} selectionIdxArea = 0;
totalPresets -= 1; selectedLevelArea = 0;
selectedPreset -= 1; selectionIdxHarvest = 0;
} selectedLevelHarvest = 0;
}
protected void doAddPreset() { protected void doDelPreset() {
// TODO // TODO
totalPresets += 1; if (totalPresets <= 1) {
selectedPreset += 1; return;
} }
totalPresets -= 1;
selectedPreset -= 1;
}
protected void doZeroPreset() { protected void doAddPreset() {
// TODO // TODO
selectedPreset = 0; totalPresets += 1;
} selectedPreset += 1;
}
protected void doNextPreset() { protected void doZeroPreset() {
// TODO // TODO
selectedPreset = (selectedPreset + 1) % totalPresets; selectedPreset = 0;
} }
protected void doPrevPreset() { protected void doNextPreset() {
// TODO // TODO
selectedPreset = (selectedPreset + totalPresets - 1) % totalPresets; selectedPreset = (selectedPreset + 1) % totalPresets;
} }
protected void doClose() { protected void doPrevPreset() {
this.mc.thePlayer.closeScreen(); // TODO
} selectedPreset = (selectedPreset + totalPresets - 1) % totalPresets;
}
protected void doClose() {
this.mc.thePlayer.closeScreen();
}
} }

File diff suppressed because it is too large Load Diff

View File

@ -1,11 +1,11 @@
package com.hbm.items.tool; package com.hbm.items.tool;
import java.util.ArrayList;
import java.util.List; import java.util.List;
import com.google.common.collect.HashMultimap; import com.google.common.collect.HashMultimap;
import com.google.common.collect.Multimap; 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 com.hbm.items.ModItems;
import cpw.mods.fml.relauncher.Side; import cpw.mods.fml.relauncher.Side;
@ -19,13 +19,13 @@ import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemSword; import net.minecraft.item.ItemSword;
import net.minecraft.util.EnumChatFormatting; import net.minecraft.util.EnumChatFormatting;
public class ItemSwordAbility extends ItemSword implements IItemWithAbility { public class ItemSwordAbility extends ItemSword {
private EnumRarity rarity = EnumRarity.common; private EnumRarity rarity = EnumRarity.common;
// was there a reason for this to be private? // was there a reason for this to be private?
protected float damage; protected float damage;
protected double movement; protected double movement;
private List<WeaponAbility> hitAbility = new ArrayList(); private AvailableAbilities hitAbilities = new AvailableAbilities();
public ItemSwordAbility(float damage, double movement, ToolMaterial material) { public ItemSwordAbility(float damage, double movement, ToolMaterial material) {
super(material); super(material);
@ -33,8 +33,8 @@ public class ItemSwordAbility extends ItemSword implements IItemWithAbility {
this.movement = movement; this.movement = movement;
} }
public ItemSwordAbility addHitAbility(WeaponAbility weaponAbility) { public ItemSwordAbility addHitAbility(IWeaponAbility weaponAbility, int level) {
this.hitAbility.add(weaponAbility); this.hitAbilities.addAbility(weaponAbility, level);
return this; return this;
} }
@ -50,15 +50,15 @@ public class ItemSwordAbility extends ItemSword implements IItemWithAbility {
public boolean hitEntity(ItemStack stack, EntityLivingBase victim, EntityLivingBase attacker) { 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 // hacky hacky hack
if(this == ModItems.mese_gavel) if(this == ModItems.mese_gavel)
attacker.worldObj.playSoundAtEntity(victim, "hbm:weapon.whack", 3.0F, 1.F); attacker.worldObj.playSoundAtEntity(victim, "hbm:weapon.whack", 3.0F, 1.F);
for(WeaponAbility ability : this.hitAbility) { this.hitAbilities.get().forEach((ability, level) -> {
ability.onHit(attacker.worldObj, (EntityPlayer) attacker, victim, this); ((IWeaponAbility)ability).onHit(level, attacker.worldObj, (EntityPlayer) attacker, victim, this);
} });
} }
stack.damageItem(1, attacker); stack.damageItem(1, attacker);
@ -77,23 +77,10 @@ public class ItemSwordAbility extends ItemSword implements IItemWithAbility {
@SideOnly(Side.CLIENT) @SideOnly(Side.CLIENT)
public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean ext) { public void addInformation(ItemStack stack, EntityPlayer player, List list, boolean ext) {
hitAbilities.addInformation(list);
if(!this.hitAbility.isEmpty()) {
list.add("Weapon modifiers: ");
for(WeaponAbility ability : this.hitAbility) {
list.add(" " + EnumChatFormatting.RED + ability.getFullName());
}
}
} }
protected boolean canOperate(ItemStack stack) { protected boolean canOperate(ItemStack stack) {
return true; 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