mirror of
https://github.com/GTNewHorizons/Draconic-Evolution.git
synced 2026-10-26 14:24:14 +00:00
Add toggle key bind for magnet (#25)
* Add toggle key bind for magnet * Add toggle notification for magnet
This commit is contained in:
1 parent
7e1fe75c55
commit
8c9161dc83
10 files changed
+237
-11
No files matched your search
+17
@@ -17,18 +17,24 @@ import cpw.mods.fml.common.eventhandler.EventPriority;
|
||||
import cpw.mods.fml.common.eventhandler.SubscribeEvent;
|
||||
import cpw.mods.fml.common.gameevent.TickEvent;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.model.ModelBiped;
|
||||
import net.minecraft.client.renderer.RenderHelper;
|
||||
import net.minecraft.client.renderer.entity.RenderItem;
|
||||
import net.minecraft.entity.Entity;
|
||||
import net.minecraft.entity.SharedMonsterAttributes;
|
||||
import net.minecraft.entity.ai.attributes.IAttributeInstance;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemArmor;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import net.minecraftforge.client.event.FOVUpdateEvent;
|
||||
import net.minecraftforge.client.event.RenderGameOverlayEvent;
|
||||
import net.minecraftforge.client.event.RenderPlayerEvent;
|
||||
import net.minecraftforge.client.model.AdvancedModelLoader;
|
||||
import net.minecraftforge.client.model.IModelCustom;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL12;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Iterator;
|
||||
@@ -47,6 +53,7 @@ public class ClientEventHandler {
|
||||
public static boolean bowZoom = false;
|
||||
public static boolean lastTickBowZoom = false;
|
||||
public static int tickSet = 0;
|
||||
public static ItemDisplayManager statusDisplayManager = new ItemDisplayManager(60);
|
||||
private static int remountTicksRemaining = 0;
|
||||
private static int remountEntityID = 0;
|
||||
public static float energyCrystalAlphaValue = 0f;
|
||||
@@ -96,6 +103,16 @@ public class ClientEventHandler {
|
||||
|
||||
searchForPlayerMount();
|
||||
}
|
||||
|
||||
statusDisplayManager.tick();
|
||||
}
|
||||
|
||||
@SubscribeEvent
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void renderGameOverlayEvent (final RenderGameOverlayEvent.Post event) {
|
||||
if (event.type == RenderGameOverlayEvent.ElementType.ALL) {
|
||||
statusDisplayManager.drawItemStack();
|
||||
}
|
||||
}
|
||||
|
||||
@SubscribeEvent(priority = EventPriority.LOW)
|
||||
|
||||
+60
@@ -0,0 +1,60 @@
|
||||
package com.brandon3055.draconicevolution.client.handler;
|
||||
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.FontRenderer;
|
||||
import net.minecraft.client.gui.ScaledResolution;
|
||||
import net.minecraft.client.renderer.RenderHelper;
|
||||
import net.minecraft.client.renderer.entity.RenderItem;
|
||||
import net.minecraft.client.renderer.texture.TextureManager;
|
||||
import net.minecraft.item.ItemStack;
|
||||
import org.lwjgl.opengl.GL11;
|
||||
import org.lwjgl.opengl.GL12;
|
||||
|
||||
public final class ItemDisplayManager {
|
||||
|
||||
private final int ticks;
|
||||
private ItemStack itemStack;
|
||||
private int ticksCounter;
|
||||
private static final RenderItem renderItem = new RenderItem();
|
||||
private static final FontRenderer fontRenderer = Minecraft.getMinecraft().fontRenderer;
|
||||
private static final TextureManager textureManager = Minecraft.getMinecraft().getTextureManager();
|
||||
|
||||
public ItemDisplayManager(int ticks) {
|
||||
this.ticks = ticks;
|
||||
}
|
||||
|
||||
public void startDrawing(ItemStack itemStack) {
|
||||
this.itemStack = itemStack;
|
||||
ticksCounter = ticks;
|
||||
}
|
||||
|
||||
public void tick() {
|
||||
if (--ticksCounter == 0) {
|
||||
itemStack = null;
|
||||
}
|
||||
}
|
||||
|
||||
public void drawItemStack() {
|
||||
if (ticksCounter > 0 && itemStack != null && itemStack.getItem() != null) {
|
||||
GL11.glColor4f(1.0f, 1.0f, 1.0f, 1.0f);
|
||||
GL11.glEnable(GL12.GL_RESCALE_NORMAL);
|
||||
RenderHelper.enableGUIStandardItemLighting();
|
||||
|
||||
GL11.glPushMatrix();
|
||||
|
||||
final Minecraft mc = Minecraft.getMinecraft();
|
||||
final ScaledResolution res = new ScaledResolution(mc, mc.displayWidth, mc.displayHeight);
|
||||
final int y = res.getScaledHeight();
|
||||
|
||||
GL11.glTranslatef(7.0f, y * 0.25f, 0);
|
||||
|
||||
renderItem.renderItemAndEffectIntoGUI(fontRenderer, textureManager, itemStack, 0, 0);
|
||||
|
||||
GL11.glPopMatrix();
|
||||
|
||||
RenderHelper.disableStandardItemLighting();
|
||||
GL11.glDisable(GL12.GL_RESCALE_NORMAL);
|
||||
GL11.glDisable(GL11.GL_BLEND);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -11,20 +11,29 @@ import org.lwjgl.input.Keyboard;
|
||||
* Created by Brandon on 14/08/2014.
|
||||
*/
|
||||
@SideOnly(Side.CLIENT)
|
||||
public class KeyBindings {
|
||||
public static KeyBinding placeItem;
|
||||
public static KeyBinding toolConfig;
|
||||
public static KeyBinding toolProfileChange;
|
||||
public static KeyBinding toggleFlight;
|
||||
public final class KeyBindings {
|
||||
|
||||
public static void init() {
|
||||
public static final KeyBinding placeItem;
|
||||
public static final KeyBinding toolConfig;
|
||||
public static final KeyBinding toolProfileChange;
|
||||
public static final KeyBinding toggleFlight;
|
||||
public static final KeyBinding toggleMagnet;
|
||||
|
||||
static {
|
||||
placeItem = new KeyBinding("key.placeItem", Keyboard.KEY_P, References.MODNAME);
|
||||
toolConfig = new KeyBinding("key.toolConfig", Keyboard.KEY_C, References.MODNAME);
|
||||
toolProfileChange = new KeyBinding("key.toolProfileChange", Keyboard.KEY_BACKSLASH, References.MODNAME);
|
||||
toggleFlight = new KeyBinding("key.toggleFlight", Keyboard.KEY_NONE, References.MODNAME);
|
||||
toggleMagnet = new KeyBinding("key.toggleMagnet", Keyboard.KEY_NONE, References.MODNAME);
|
||||
}
|
||||
|
||||
private KeyBindings() {}
|
||||
|
||||
public static void init() {
|
||||
ClientRegistry.registerKeyBinding(placeItem);
|
||||
ClientRegistry.registerKeyBinding(toolConfig);
|
||||
ClientRegistry.registerKeyBinding(toolProfileChange);
|
||||
ClientRegistry.registerKeyBinding(toggleFlight);
|
||||
ClientRegistry.registerKeyBinding(toggleMagnet);
|
||||
}
|
||||
}
|
||||
@@ -5,6 +5,7 @@ import com.brandon3055.draconicevolution.DraconicEvolution;
|
||||
import com.brandon3055.draconicevolution.common.ModItems;
|
||||
import com.brandon3055.draconicevolution.common.items.tools.baseclasses.ToolHandler;
|
||||
import com.brandon3055.draconicevolution.common.network.ButtonPacket;
|
||||
import com.brandon3055.draconicevolution.common.network.MagnetTogglePacket;
|
||||
import com.brandon3055.draconicevolution.common.network.PlacedItemPacket;
|
||||
import com.brandon3055.draconicevolution.common.network.TeleporterPacket;
|
||||
import com.brandon3055.draconicevolution.common.utills.IConfigurableItem;
|
||||
@@ -55,6 +56,12 @@ public class KeyInputHandler {
|
||||
player.sendPlayerAbilities();
|
||||
}
|
||||
}
|
||||
} else if (KeyBindings.toggleMagnet.isPressed()) {
|
||||
EntityPlayer player = Minecraft.getMinecraft().thePlayer;
|
||||
|
||||
if (player.inventory.hasItem(ModItems.magnet)) {
|
||||
DraconicEvolution.network.sendToServer(new MagnetTogglePacket());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -127,7 +127,8 @@ public class CommonProxy {
|
||||
DraconicEvolution.network.registerMessage(ShieldHitPacket.Handler.class, ShieldHitPacket.class, 16, Side.CLIENT);
|
||||
DraconicEvolution.network.registerMessage(ContributorPacket.Handler.class, ContributorPacket.class, 17, Side.CLIENT);
|
||||
DraconicEvolution.network.registerMessage(ContributorPacket.Handler.class, ContributorPacket.class, 18, Side.SERVER);
|
||||
|
||||
DraconicEvolution.network.registerMessage(MagnetTogglePacket.Handler.class, MagnetTogglePacket.class, 19, Side.SERVER);
|
||||
DraconicEvolution.network.registerMessage(MagnetToggleAckPacket.Handler.class, MagnetToggleAckPacket.class, 20, Side.CLIENT);
|
||||
}
|
||||
|
||||
public void registerTileEntities() {
|
||||
|
||||
@@ -72,12 +72,12 @@ public class Magnet extends ItemDE {
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public boolean hasEffect(ItemStack stack, int pass) {
|
||||
return ItemNBTHelper.getBoolean(stack, "MagnetEnabled", false);
|
||||
return isEnabled(stack);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onUpdate(ItemStack stack, World world, Entity entity, int slot, boolean hotbar) {
|
||||
if (!entity.isSneaking() && entity.ticksExisted % 5 == 0 && ItemNBTHelper.getBoolean(stack, "MagnetEnabled", false) && entity instanceof EntityPlayer) {
|
||||
if (!entity.isSneaking() && entity.ticksExisted % 5 == 0 && isEnabled(stack) && entity instanceof EntityPlayer) {
|
||||
int range = stack.getItemDamage() == 0 ? 8 : 32;
|
||||
|
||||
List<EntityItem> items = world.getEntitiesWithinAABB(EntityItem.class, AxisAlignedBB.getBoundingBox(entity.posX, entity.posY, entity.posZ, entity.posX, entity.posY, entity.posZ).expand(range, range, range));
|
||||
@@ -121,10 +121,23 @@ public class Magnet extends ItemDE {
|
||||
}
|
||||
}
|
||||
|
||||
public static boolean isEnabled(ItemStack itemStack) {
|
||||
return ItemNBTHelper.getBoolean(itemStack, "MagnetEnabled", false);
|
||||
}
|
||||
|
||||
public static void toggle(ItemStack itemStack) {
|
||||
ItemNBTHelper.setBoolean(itemStack, "MagnetEnabled", !isEnabled(itemStack));
|
||||
}
|
||||
|
||||
public static void setStatus(ItemStack itemStack, boolean status) {
|
||||
ItemNBTHelper.setBoolean(itemStack, "MagnetEnabled", status);
|
||||
}
|
||||
|
||||
@Override
|
||||
public ItemStack onItemRightClick(ItemStack stack, World world, EntityPlayer player) {
|
||||
if (player.isSneaking())
|
||||
ItemNBTHelper.setBoolean(stack, "MagnetEnabled", !ItemNBTHelper.getBoolean(stack, "MagnetEnabled", false));
|
||||
if (player.isSneaking()) {
|
||||
toggle(stack);
|
||||
}
|
||||
return stack;
|
||||
}
|
||||
|
||||
|
||||
+55
@@ -0,0 +1,55 @@
|
||||
package com.brandon3055.draconicevolution.common.network;
|
||||
|
||||
import com.brandon3055.draconicevolution.client.handler.ClientEventHandler;
|
||||
import com.brandon3055.draconicevolution.common.items.tools.Magnet;
|
||||
import com.brandon3055.draconicevolution.common.utills.InventoryUtils;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
import cpw.mods.fml.relauncher.Side;
|
||||
import cpw.mods.fml.relauncher.SideOnly;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public final class MagnetToggleAckPacket implements IMessage {
|
||||
|
||||
private boolean status;
|
||||
|
||||
public MagnetToggleAckPacket() {}
|
||||
|
||||
public MagnetToggleAckPacket(boolean status) {
|
||||
this.status = status;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
status = buf.readBoolean();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
buf.writeBoolean(status);
|
||||
}
|
||||
|
||||
public static final class Handler implements IMessageHandler<MagnetToggleAckPacket, IMessage> {
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
@Override
|
||||
public IMessage onMessage(MagnetToggleAckPacket message, MessageContext ctx) {
|
||||
EntityPlayer player = Minecraft.getMinecraft().thePlayer;
|
||||
Optional<ItemStack> magnetOptional = InventoryUtils.getItemInPlayerInventory(player, Magnet.class);
|
||||
|
||||
if (magnetOptional.isPresent()) {
|
||||
ItemStack itemStack = magnetOptional.get().copy();
|
||||
Magnet.setStatus(itemStack, message.status);
|
||||
ClientEventHandler.statusDisplayManager.startDrawing(itemStack);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
+45
@@ -0,0 +1,45 @@
|
||||
package com.brandon3055.draconicevolution.common.network;
|
||||
|
||||
import com.brandon3055.draconicevolution.DraconicEvolution;
|
||||
import com.brandon3055.draconicevolution.common.items.tools.Magnet;
|
||||
import com.brandon3055.draconicevolution.common.utills.InventoryUtils;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessage;
|
||||
import cpw.mods.fml.common.network.simpleimpl.IMessageHandler;
|
||||
import cpw.mods.fml.common.network.simpleimpl.MessageContext;
|
||||
import io.netty.buffer.ByteBuf;
|
||||
import net.minecraft.entity.player.EntityPlayerMP;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
public final class MagnetTogglePacket implements IMessage {
|
||||
|
||||
public MagnetTogglePacket() {}
|
||||
|
||||
@Override
|
||||
public void fromBytes(ByteBuf buf) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
@Override
|
||||
public void toBytes(ByteBuf buf) {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
|
||||
public static final class Handler implements IMessageHandler<MagnetTogglePacket, IMessage> {
|
||||
|
||||
@Override
|
||||
public IMessage onMessage(MagnetTogglePacket message, MessageContext ctx) {
|
||||
EntityPlayerMP player = ctx.getServerHandler().playerEntity;
|
||||
|
||||
Optional<ItemStack> magnetOptional = InventoryUtils.getItemInPlayerInventory(player, Magnet.class);
|
||||
magnetOptional.ifPresent(itemStack -> {
|
||||
Magnet.toggle(itemStack);
|
||||
DraconicEvolution.network.sendTo(new MagnetToggleAckPacket(Magnet.isEnabled(itemStack)), player);
|
||||
});
|
||||
|
||||
return null;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.brandon3055.draconicevolution.common.utills;
|
||||
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
import net.minecraft.item.Item;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Optional;
|
||||
|
||||
public final class InventoryUtils {
|
||||
|
||||
private InventoryUtils() {}
|
||||
public static Optional<ItemStack> getItemInPlayerInventory(EntityPlayer player, Class<? extends Item> item) {
|
||||
return Arrays.stream(player.inventory.mainInventory)
|
||||
.filter(itemStack -> itemStack != null && item.isInstance(itemStack.getItem()))
|
||||
.findAny();
|
||||
}
|
||||
}
|
||||
@@ -424,6 +424,7 @@ key.placeItem=Place Item in world
|
||||
key.toolConfig=Tool & Armor Config GUI
|
||||
key.toolProfileChange=Change Tool Config Profile
|
||||
key.toggleFlight=Toggle Creative Flight
|
||||
key.toggleMagnet=Toggle Magnet
|
||||
|
||||
//Damage ----------------------------------------------------------------------------------------------------------------------------------------
|
||||
death.attack.chaos=%1$s was torn apart by a Chaos Guardian
|
||||
|
||||
Reference in new issue
Block a user