Merge pull request #1982 from KellenHurrey/master

Added a keybind for toggling the magnet armor modifications
This commit is contained in:
HbmMods 2025-03-17 08:09:59 +01:00 committed by GitHub
commit 850679ca94
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 35 additions and 7 deletions

View File

@ -26,6 +26,7 @@ public class HbmPlayerProps implements IExtendedEntityProperties {
public boolean enableHUD = true;
public boolean enableBackpack = true;
public boolean enableMagnet = true;
private boolean[] keysPressed = new boolean[EnumKeybind.values().length];
@ -71,6 +72,10 @@ public class HbmPlayerProps implements IExtendedEntityProperties {
return this.enableBackpack && getKeyPressed(EnumKeybind.JETPACK);
}
public boolean isMagnetActive(){
return this.enableMagnet;
}
public void setKeyPressed(EnumKeybind key, boolean pressed) {
if(!getKeyPressed(key) && pressed) {
@ -86,6 +91,16 @@ public class HbmPlayerProps implements IExtendedEntityProperties {
MainRegistry.proxy.displayTooltip(EnumChatFormatting.RED + "Jetpack OFF", MainRegistry.proxy.ID_JETPACK);
}
}
if (key == EnumKeybind.TOGGLE_MAGNET){
if (!player.worldObj.isRemote){
this.enableMagnet = !this.enableMagnet;
if(this.enableMagnet)
MainRegistry.proxy.displayTooltip(EnumChatFormatting.GREEN + "Magnet ON", MainRegistry.proxy.ID_MAGNET);
else
MainRegistry.proxy.displayTooltip(EnumChatFormatting.RED + "Magnet OFF", MainRegistry.proxy.ID_MAGNET);
}
}
if(key == EnumKeybind.TOGGLE_HEAD) {
if(!player.worldObj.isRemote) {
@ -174,6 +189,7 @@ public class HbmPlayerProps implements IExtendedEntityProperties {
buf.writeBoolean(this.enableHUD);
buf.writeInt(this.reputation);
buf.writeBoolean(this.isOnLadder);
buf.writeBoolean(this.enableMagnet);
}
public void deserialize(ByteBuf buf) {
@ -185,6 +201,7 @@ public class HbmPlayerProps implements IExtendedEntityProperties {
this.enableHUD = buf.readBoolean();
this.reputation = buf.readInt();
this.isOnLadder = buf.readBoolean();
this.enableMagnet = buf.readBoolean();
}
}
@ -198,6 +215,7 @@ public class HbmPlayerProps implements IExtendedEntityProperties {
props.setFloat("shield", shield);
props.setFloat("maxShield", maxShield);
props.setBoolean("enableBackpack", enableBackpack);
props.setBoolean("enableMagnet", enableMagnet);
props.setBoolean("enableHUD", enableHUD);
props.setInteger("reputation", reputation);
props.setBoolean("isOnLadder", isOnLadder);
@ -216,6 +234,7 @@ public class HbmPlayerProps implements IExtendedEntityProperties {
this.shield = props.getFloat("shield");
this.maxShield = props.getFloat("maxShield");
this.enableBackpack = props.getBoolean("enableBackpack");
this.enableMagnet = props.getBoolean("enableMagnet");
this.enableHUD = props.getBoolean("enableHUD");
this.reputation = props.getInteger("reputation");
this.isOnLadder = props.getBoolean("isOnLadder");

View File

@ -22,6 +22,7 @@ public class HbmKeybinds {
public static KeyBinding calculatorKey = new KeyBinding(category + ".calculator", Keyboard.KEY_N, category);
public static KeyBinding jetpackKey = new KeyBinding(category + ".toggleBack", Keyboard.KEY_C, category);
public static KeyBinding magnetKey = new KeyBinding(category + ".toggleMagnet", Keyboard.KEY_Z, category);
public static KeyBinding hudKey = new KeyBinding(category + ".toggleHUD", Keyboard.KEY_V, category);
public static KeyBinding dashKey = new KeyBinding(category + ".dash", Keyboard.KEY_LSHIFT, category);
public static KeyBinding trainKey = new KeyBinding(category + ".trainInv", Keyboard.KEY_R, category);
@ -43,6 +44,7 @@ public class HbmKeybinds {
public static void register() {
ClientRegistry.registerKeyBinding(calculatorKey);
ClientRegistry.registerKeyBinding(jetpackKey);
ClientRegistry.registerKeyBinding(magnetKey);
ClientRegistry.registerKeyBinding(hudKey);
ClientRegistry.registerKeyBinding(dashKey);
ClientRegistry.registerKeyBinding(trainKey);
@ -98,6 +100,7 @@ public class HbmKeybinds {
public static enum EnumKeybind {
JETPACK,
TOGGLE_JETPACK,
TOGGLE_MAGNET,
TOGGLE_HEAD,
DASH,
TRAIN,

View File

@ -2,6 +2,7 @@ package com.hbm.items.armor;
import java.util.List;
import com.hbm.extprop.HbmPlayerProps;
import com.hbm.handler.ArmorModHandler;
import net.minecraft.entity.EntityLivingBase;
@ -36,7 +37,10 @@ public class ItemModLodestone extends ItemArmorMod {
@Override
public void modUpdate(EntityLivingBase entity, ItemStack armor) {
// No magnet if keybind toggled
if (entity instanceof EntityPlayer && !HbmPlayerProps.getData((EntityPlayer) entity).isMagnetActive()) return;
List<EntityItem> items = entity.worldObj.getEntitiesWithinAABB(EntityItem.class, entity.boundingBox.expand(range, range, range));
for(EntityItem item : items) {

View File

@ -2038,6 +2038,7 @@ public class ClientProxy extends ServerProxy {
switch(key){
case JETPACK: return Minecraft.getMinecraft().gameSettings.keyBindJump.getIsKeyPressed();
case TOGGLE_JETPACK: return HbmKeybinds.jetpackKey.getIsKeyPressed();
case TOGGLE_MAGNET: return HbmKeybinds.magnetKey.getIsKeyPressed();
case TOGGLE_HEAD: return HbmKeybinds.hudKey.getIsKeyPressed();
case RELOAD: return HbmKeybinds.reloadKey.getIsKeyPressed();
case DASH: return HbmKeybinds.dashKey.getIsKeyPressed();

View File

@ -21,12 +21,13 @@ public class ServerProxy {
public static final int ID_CABLE = 3;
public static final int ID_DRONE = 4;
public static final int ID_JETPACK = 5;
public static final int ID_HUD = 6;
public static final int ID_DETONATOR = 7;
public static final int ID_FLUID_ID = 8;
public static final int ID_TOOLABILITY = 9;
public static final int ID_GUN_MODE = 10;
public static final int ID_GAS_HAZARD = 11;
public static final int ID_MAGNET = 6;
public static final int ID_HUD = 7;
public static final int ID_DETONATOR = 8;
public static final int ID_FLUID_ID = 9;
public static final int ID_TOOLABILITY = 10;
public static final int ID_GUN_MODE = 11;
public static final int ID_GAS_HAZARD = 12;
public void registerPreRenderInfo() { }
public void registerRenderInfo() { }