mirror of
https://github.com/HbmMods/Hbm-s-Nuclear-Tech-GIT.git
synced 2026-01-25 10:32:49 +00:00
show current tool area ability next to crosshair, to prevent accidentally breaking yo shit
This commit is contained in:
parent
94e3df1751
commit
dd0a604aa6
@ -4,29 +4,35 @@ import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Comparator;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.Set;
|
||||
|
||||
import org.lwjgl.opengl.GL11;
|
||||
|
||||
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.items.IKeybindReceiver;
|
||||
import com.hbm.handler.HbmKeybinds.EnumKeybind;
|
||||
import com.hbm.blocks.ModBlocks;
|
||||
import com.hbm.handler.HbmKeybinds.EnumKeybind;
|
||||
import com.hbm.handler.ability.AvailableAbilities;
|
||||
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.interfaces.IItemHUD;
|
||||
import com.hbm.inventory.gui.GUIScreenToolAbility;
|
||||
import com.hbm.items.IItemControlReceiver;
|
||||
import com.hbm.items.IKeybindReceiver;
|
||||
import com.hbm.main.MainRegistry;
|
||||
import com.hbm.packet.PacketDispatcher;
|
||||
import com.hbm.packet.toclient.PlayerInformPacket;
|
||||
import com.hbm.tileentity.IGUIProvider;
|
||||
import com.hbm.util.Tuple.Pair;
|
||||
|
||||
import api.hbm.item.IDepthRockTool;
|
||||
import cpw.mods.fml.relauncher.ReflectionHelper;
|
||||
@ -34,6 +40,10 @@ import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.block.Block;
|
||||
import net.minecraft.block.material.Material;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.Gui;
|
||||
import net.minecraft.client.gui.GuiIngame;
|
||||
import net.minecraft.client.renderer.OpenGlHelper;
|
||||
import net.minecraft.enchantment.Enchantment;
|
||||
import net.minecraft.enchantment.EnchantmentHelper;
|
||||
import net.minecraft.entity.EntityLivingBase;
|
||||
@ -53,12 +63,14 @@ import net.minecraft.network.play.server.S23PacketBlockChange;
|
||||
import net.minecraft.stats.StatList;
|
||||
import net.minecraft.util.EnumChatFormatting;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.client.event.RenderGameOverlayEvent.ElementType;
|
||||
import net.minecraftforge.client.event.RenderGameOverlayEvent.Pre;
|
||||
import net.minecraftforge.common.ForgeHooks;
|
||||
import net.minecraftforge.common.IShearable;
|
||||
import net.minecraftforge.event.world.BlockEvent;
|
||||
|
||||
public class ItemToolAbility extends ItemTool implements IDepthRockTool, IGUIProvider, IItemControlReceiver, IKeybindReceiver {
|
||||
|
||||
public class ItemToolAbility extends ItemTool implements IDepthRockTool, IGUIProvider, IItemControlReceiver, IKeybindReceiver, IItemHUD {
|
||||
|
||||
protected boolean isShears = false;
|
||||
protected EnumToolType toolType;
|
||||
protected EnumRarity rarity = EnumRarity.common;
|
||||
@ -69,7 +81,7 @@ public class ItemToolAbility extends ItemTool implements IDepthRockTool, IGUIPro
|
||||
protected boolean rockBreaker = false;
|
||||
|
||||
public static enum EnumToolType {
|
||||
|
||||
|
||||
PICKAXE(
|
||||
Sets.newHashSet(new Material[] { Material.iron, Material.anvil, Material.rock, Material.glass }),
|
||||
Sets.newHashSet(new Block[] { Blocks.cobblestone, Blocks.double_stone_slab, Blocks.stone_slab, Blocks.stone, Blocks.sandstone, Blocks.mossy_cobblestone, Blocks.iron_ore, Blocks.iron_block, Blocks.coal_ore, Blocks.gold_block, Blocks.gold_ore, Blocks.diamond_ore, Blocks.diamond_block, Blocks.ice, Blocks.netherrack, Blocks.lapis_ore, Blocks.lapis_block, Blocks.redstone_ore, Blocks.lit_redstone_ore, Blocks.rail, Blocks.detector_rail, Blocks.golden_rail, Blocks.activator_rail })
|
||||
@ -98,7 +110,7 @@ public class ItemToolAbility extends ItemTool implements IDepthRockTool, IGUIPro
|
||||
public Set<Material> materials = new HashSet();
|
||||
public Set<Block> blocks = new HashSet();
|
||||
}
|
||||
|
||||
|
||||
public ItemToolAbility setShears() {
|
||||
this.isShears = true;
|
||||
return this;
|
||||
@ -109,7 +121,7 @@ public class ItemToolAbility extends ItemTool implements IDepthRockTool, IGUIPro
|
||||
this.damage = damage;
|
||||
this.movement = movement;
|
||||
this.toolType = type;
|
||||
|
||||
|
||||
// hacky workaround, might be good to rethink this entire system
|
||||
if(type == EnumToolType.MINER) {
|
||||
this.setHarvestLevel("pickaxe", material.getHarvestLevel());
|
||||
@ -163,15 +175,15 @@ public class ItemToolAbility extends ItemTool implements IDepthRockTool, IGUIPro
|
||||
|
||||
World world = player.worldObj;
|
||||
Block block = world.getBlock(x, y, z);
|
||||
|
||||
/*
|
||||
|
||||
/*
|
||||
* The original implementation of this always returned FALSE which uses the vanilla block break code.
|
||||
* This one now returns TRUE when an ability applies and instead relies on breakExtraBlock, which has the minor
|
||||
* issue of only running on the sever, while the client uses the vanilla implementation. breakExtraBlock was only
|
||||
* meant to be used for AoE or vein miner and not for the block that's being mined, hence break EXTRA block.
|
||||
* The consequence was that the server would fail to break keyholes since breakExtraBlock is supposed to exclude
|
||||
* them, while the client happily removes the block, causing a desync.
|
||||
*
|
||||
*
|
||||
* Since keyholes aren't processable and exempt from silk touch anyway, we just default to the vanilla implementation in every case.
|
||||
*/
|
||||
if(block == ModBlocks.stone_keyhole || block == ModBlocks.stone_keyhole_meta) return false;
|
||||
@ -187,7 +199,7 @@ public class ItemToolAbility extends ItemTool implements IDepthRockTool, IGUIPro
|
||||
preset.harvestAbility.preHarvestAll(preset.harvestAbilityLevel, world, player);
|
||||
|
||||
boolean skipRef = preset.areaAbility.onDig(preset.areaAbilityLevel, world, x, y, z, player, this);
|
||||
|
||||
|
||||
if(!skipRef) {
|
||||
breakExtraBlock(world, x, y, z, player, x, y, z);
|
||||
}
|
||||
@ -291,7 +303,7 @@ public class ItemToolAbility extends ItemTool implements IDepthRockTool, IGUIPro
|
||||
|
||||
Block block = world.getBlock(x, y, z);
|
||||
int meta = world.getBlockMetadata(x, y, z);
|
||||
|
||||
|
||||
if(!(canHarvestBlock(block, stack) ||
|
||||
canShearBlock(block, stack, world, x, y, z)) ||
|
||||
(block.getBlockHardness(world, x, y, z) == -1.0F && block.getPlayerRelativeBlockHardness(player, world, x, y, z) == 0.0F) ||
|
||||
@ -302,8 +314,8 @@ public class ItemToolAbility extends ItemTool implements IDepthRockTool, IGUIPro
|
||||
float strength = ForgeHooks.blockStrength(block, player, world, x, y, z);
|
||||
|
||||
if(
|
||||
!ForgeHooks.canHarvestBlock(block, player, meta) ||
|
||||
refStrength / strength > 10f ||
|
||||
!ForgeHooks.canHarvestBlock(block, player, meta) ||
|
||||
refStrength / strength > 10f ||
|
||||
refBlock.getPlayerRelativeBlockHardness(player, world, refX, refY, refZ) < 0
|
||||
)
|
||||
return;
|
||||
@ -320,7 +332,7 @@ public class ItemToolAbility extends ItemTool implements IDepthRockTool, IGUIPro
|
||||
|
||||
/** Assumes a canShearBlock check has passed, will most likely crash otherwise! */
|
||||
public static void shearBlock(World world, int x, int y, int z, Block block, EntityPlayer player) {
|
||||
|
||||
|
||||
ItemStack held = player.getHeldItem();
|
||||
|
||||
IShearable target = (IShearable) block;
|
||||
@ -369,7 +381,7 @@ public class ItemToolAbility extends ItemTool implements IDepthRockTool, IGUIPro
|
||||
player.destroyCurrentEquippedItem();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if(removedByPlayer && canHarvest) {
|
||||
try {
|
||||
blockCaptureDrops.invoke(block, true);
|
||||
@ -384,7 +396,7 @@ public class ItemToolAbility extends ItemTool implements IDepthRockTool, IGUIPro
|
||||
} catch (InvocationTargetException e) {
|
||||
// Might be possible? Not in practice, though
|
||||
MainRegistry.logger.error("Failed to capture drops for block " + block, e);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -441,9 +453,9 @@ public class ItemToolAbility extends ItemTool implements IDepthRockTool, IGUIPro
|
||||
|
||||
NBTTagList nbtPresets = nbt.getTagList("abilityPresets", 10);
|
||||
int numPresets = Math.min(nbtPresets.tagCount(), 99);
|
||||
|
||||
|
||||
presets = new ArrayList<ToolPreset>(numPresets);
|
||||
|
||||
|
||||
for(int i = 0; i < numPresets; i++) {
|
||||
NBTTagCompound nbtPreset = nbtPresets.getCompoundTagAt(i);
|
||||
ToolPreset preset = new ToolPreset();
|
||||
@ -544,12 +556,12 @@ public class ItemToolAbility extends ItemTool implements IDepthRockTool, IGUIPro
|
||||
|
||||
@Override
|
||||
public void handleKeybind(EntityPlayer player, ItemStack stack, EnumKeybind keybind, boolean state) {
|
||||
|
||||
|
||||
if(keybind == EnumKeybind.ABILITY_CYCLE && state) {
|
||||
|
||||
World world = player.worldObj;
|
||||
if(!canOperate(stack)) return;
|
||||
|
||||
|
||||
Configuration config = getConfiguration(stack);
|
||||
if(config.presets.size() < 2 || world.isRemote) return;
|
||||
|
||||
@ -569,4 +581,38 @@ public class ItemToolAbility extends ItemTool implements IDepthRockTool, IGUIPro
|
||||
public void handleKeybindClient(EntityPlayer player, ItemStack stack, EnumKeybind keybind, boolean state) {
|
||||
if(state) player.openGui(MainRegistry.instance, 0, player.worldObj, 0, 0, 0);
|
||||
}
|
||||
|
||||
private static final Map<IBaseAbility, Pair<Integer, Integer>> abilityGui = new HashMap<>();
|
||||
|
||||
static {
|
||||
abilityGui.put(IToolAreaAbility.RECURSION, new Pair<Integer,Integer>(0, 138));
|
||||
abilityGui.put(IToolAreaAbility.HAMMER, new Pair<Integer,Integer>(16, 138));
|
||||
abilityGui.put(IToolAreaAbility.HAMMER_FLAT, new Pair<Integer,Integer>(32, 138));
|
||||
abilityGui.put(IToolAreaAbility.EXPLOSION, new Pair<Integer,Integer>(48, 138));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void renderHUD(Pre event, ElementType type, EntityPlayer player, ItemStack stack) {
|
||||
if(type != ElementType.CROSSHAIRS) return;
|
||||
|
||||
Configuration config = getConfiguration(stack);
|
||||
ToolPreset preset = config.getActivePreset();
|
||||
Pair<Integer, Integer> uv = abilityGui.get(preset.areaAbility);
|
||||
|
||||
if(uv == null) return;
|
||||
|
||||
GuiIngame gui = Minecraft.getMinecraft().ingameGUI;
|
||||
int size = 16;
|
||||
|
||||
GL11.glPushMatrix();
|
||||
Minecraft.getMinecraft().renderEngine.bindTexture(GUIScreenToolAbility.texture);
|
||||
GL11.glEnable(GL11.GL_BLEND);
|
||||
OpenGlHelper.glBlendFunc(GL11.GL_ONE_MINUS_DST_COLOR, GL11.GL_ONE_MINUS_SRC_COLOR, 1, 0);
|
||||
gui.drawTexturedModalRect(event.resolution.getScaledWidth() / 2 - size - 8, event.resolution.getScaledHeight() / 2 + 8, uv.key, uv.value, size, size);
|
||||
OpenGlHelper.glBlendFunc(GL11.GL_SRC_ALPHA, GL11.GL_ONE_MINUS_SRC_ALPHA, 1, 0);
|
||||
GL11.glDisable(GL11.GL_BLEND);
|
||||
GL11.glPopMatrix();
|
||||
Minecraft.getMinecraft().renderEngine.bindTexture(Gui.icons);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 4.4 KiB After Width: | Height: | Size: 4.3 KiB |
Loading…
x
Reference in New Issue
Block a user