Add a keybind to toggle voidwalker's sash

This commit is contained in:
Vladislav Laetansky committed 2022-07-25 14:36:02 +03:00
1 parent 337c7e1022
commit 43c15e32a7
11 files changed
+159 -32

No files matched your search

@@ -8,6 +8,7 @@ import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.common.config.Configuration;
import taintedmagic.client.handler.SashServerHandler;
import taintedmagic.common.handler.ConfigHandler;
import taintedmagic.common.handler.TMEventHandler;
import taintedmagic.common.handler.UpdateHandler;
@@ -60,6 +61,10 @@ public class CommonProxy {
return null;
}
public boolean isSashEnabled(EntityPlayer player) {
return SashServerHandler.isSashEnabled(player);
}
public World getClientWorld () {
return null;
}
@@ -139,7 +139,7 @@ public class ItemVoidwalkerBoots extends ItemArmor
if (player.onGround || player.capabilities.isFlying) {
float bonus = 0.12F;
final ItemStack sash = PlayerHandler.getPlayerBaubles(player).getStackInSlot(3);
if (sash != null && sash.getItem() instanceof ItemVoidwalkerSash && ItemVoidwalkerSash.isSpeedEnabled(sash)) {
if (sash != null && sash.getItem() instanceof ItemVoidwalkerSash && TaintedMagic.proxy.isSashEnabled(player)) {
bonus *= 2.0F;
}
@@ -168,7 +168,7 @@ public class ItemVoidwalkerBoots extends ItemArmor
if (boots != null && boots.getItem() == ItemRegistry.ItemVoidwalkerBoots) {
player.motionY *= 1.25D;
}
if (sash != null && sash.getItem() instanceof ItemVoidwalkerSash && ItemVoidwalkerSash.isSpeedEnabled(sash)) {
if (sash != null && sash.getItem() instanceof ItemVoidwalkerSash && TaintedMagic.proxy.isSashEnabled(player)) {
player.motionY *= 1.05D;
}
}
@@ -9,12 +9,12 @@ import net.minecraft.entity.EntityLivingBase;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.item.EnumRarity;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.util.EnumChatFormatting;
import net.minecraft.util.StatCollector;
import net.minecraft.world.World;
import net.minecraftforge.common.MinecraftForge;
import taintedmagic.client.handler.HUDHandler;
import taintedmagic.client.handler.SashClientHandler;
import taintedmagic.client.handler.SashServerHandler;
import taintedmagic.common.TaintedMagic;
import thaumcraft.api.IRunicArmor;
import thaumcraft.api.IWarpingGear;
@@ -23,8 +23,6 @@ import thaumcraft.common.Thaumcraft;
public class ItemVoidwalkerSash extends ItemRunic implements IRunicArmor, IWarpingGear, IBauble {
public static final String TAG_MODE = "mode";
public ItemVoidwalkerSash () {
super(20);
setCreativeTab(TaintedMagic.tabTM);
@@ -44,7 +42,7 @@ public class ItemVoidwalkerSash extends ItemRunic implements IRunicArmor, IWarpi
@Override
public void addInformation (final ItemStack stack, final EntityPlayer player, final List list, final boolean b) {
if (isSpeedEnabled(stack)) {
if (TaintedMagic.proxy.isSashEnabled(player)) {
list.add(EnumChatFormatting.GREEN + StatCollector.translateToLocal("text.sash.speed.on"));
}
else {
@@ -95,33 +93,14 @@ public class ItemVoidwalkerSash extends ItemRunic implements IRunicArmor, IWarpi
@Override
public ItemStack onItemRightClick (final ItemStack stack, final World world, final EntityPlayer player) {
if (!world.isRemote && player.isSneaking()) {
if (stack.stackTagCompound == null) {
stack.setTagCompound(new NBTTagCompound());
stack.stackTagCompound.setBoolean(TAG_MODE, true);
}
if (stack.stackTagCompound != null) {
stack.stackTagCompound.setBoolean(TAG_MODE, !stack.stackTagCompound.getBoolean(TAG_MODE));
if (isSpeedEnabled(stack)) {
HUDHandler.displayString(EnumChatFormatting.GREEN + StatCollector.translateToLocal("text.sash.speed.on"),
300, false);
}
else {
HUDHandler.displayString(EnumChatFormatting.RED + StatCollector.translateToLocal("text.sash.speed.off"),
300, false);
}
if (player.isSneaking()) {
if (world.isRemote) {
SashClientHandler.toggle();
} else {
SashServerHandler.toggleSashStatus(player);
}
}
return stack;
}
/**
* Returns true if the speed boost feature is enabled.
*/
public static boolean isSpeedEnabled (final ItemStack stack) {
if (stack.stackTagCompound == null)
return true;
return stack.stackTagCompound.getBoolean(TAG_MODE);
}
}
@@ -12,5 +12,6 @@ public class PacketHandler {
public static void initPackets () {
INSTANCE.registerMessage(PacketKatanaAttack.class, PacketKatanaAttack.class, 0, Side.SERVER);
INSTANCE.registerMessage(PacketSashToggle.class, PacketSashToggle.class, 1, Side.SERVER);
}
}
@@ -0,0 +1,36 @@
package taintedmagic.common.network;
import baubles.common.lib.PlayerHandler;
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.EntityPlayer;
import net.minecraft.item.ItemStack;
import taintedmagic.client.handler.SashServerHandler;
import taintedmagic.common.items.equipment.ItemVoidwalkerSash;
public class PacketSashToggle implements IMessage, IMessageHandler<PacketSashToggle, IMessage> {
@Override
public void fromBytes(ByteBuf buf) {
// do nothing
}
@Override
public void toBytes(ByteBuf buf) {
// do nothing
}
@Override
public IMessage onMessage(PacketSashToggle message, MessageContext ctx) {
EntityPlayer player = ctx.getServerHandler().playerEntity;
final ItemStack sash = PlayerHandler.getPlayerBaubles(player).getStackInSlot(3);
if (sash != null && sash.getItem() instanceof ItemVoidwalkerSash) {
SashServerHandler.toggleSashStatus(player);
}
return null;
}
}