Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slow Boots + Omni Toggle #25

Merged
merged 4 commits into from
Feb 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
61 changes: 51 additions & 10 deletions src/main/java/thaumicboots/api/ItemBoots.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,11 @@ public class ItemBoots extends ItemArmor
public String unlocalisedName;

public double jumpBonus;
public boolean omniMovement;

public static final String TAG_MODE_JUMP = "jump";
public static final String TAG_MODE_SPEED = "speed";
public static final String TAG_MOD_OMNI = "omni";

public ItemBoots(ArmorMaterial par2EnumArmorMaterial, int par3, int par4) {
super(par2EnumArmorMaterial, par3, par4);
Expand All @@ -60,6 +62,7 @@ protected void setBootsData() {
visDiscount = 0;
runBonus = 0.165F;
jumpBonus = 0.0D;
omniMovement = false;
tier = 0;
steadyBonus = false; // this is the toggle for the longrunningbonus.
negateFall = true; // certain boots don't have fall damage in base.
Expand All @@ -72,6 +75,7 @@ protected void setBootsData() {

public double getJumpModifier() {
return jumpBonus;

}

public static double changeJump(double prevJump) {
Expand Down Expand Up @@ -122,6 +126,28 @@ public static void setModeSpeed(ItemStack stack, double state) {
stack.stackTagCompound.setDouble(TAG_MODE_SPEED, state);
}

public boolean getOmniState() {
return omniMovement;
}

public static boolean changeOmniState(boolean prevState) {
return !prevState;
}

public static boolean isOmniEnabled(final ItemStack stack) {
if (stack.stackTagCompound == null) {
return false;
}
return stack.stackTagCompound.getBoolean(TAG_MOD_OMNI);
}

public static void setModeOmni(ItemStack stack, boolean state) {
if (stack.stackTagCompound == null) {
stack.setTagCompound(new NBTTagCompound());
}
stack.stackTagCompound.setBoolean(TAG_MOD_OMNI, state);
}

// TODO: the part not from interfaces

@SideOnly(Side.CLIENT) // this method is important, it's what initializes the texture
Expand Down Expand Up @@ -174,17 +200,17 @@ public boolean getIsRepairable(ItemStack par1ItemStack, ItemStack par2ItemStack)

protected float computeBonus(ItemStack itemStack, EntityPlayer player) {
int ticks = player.inventory.armorItemInSlot(0).stackTagCompound.getInteger("runTicks");
float bonus = runBonus + ((ticks * 0.2F) * longrunningbonus);
return bonus;
return runBonus + ((ticks * 0.2F) * longrunningbonus);
}

@Override
public void onArmorTick(World world, EntityPlayer player, ItemStack itemStack) {
if (negateFall && player.fallDistance > 0.0F) {
player.fallDistance = 0.0F;
}

if (player.moveForward == 0F && player.moveStrafing == 0F) {
boolean omniMode = isOmniEnabled(itemStack);
if ((player.moveForward == 0F && player.moveStrafing == 0F && omniMode)
|| (player.moveForward <= 0F && !omniMode)) {
return;
}

Expand All @@ -199,8 +225,8 @@ public void onArmorTick(World world, EntityPlayer player, ItemStack itemStack) {
}

public void applyFinalBonus(float bonus, EntityPlayer player, ItemStack itemStack) {
bonus *= itemStack.stackTagCompound.getDouble(TAG_MODE_SPEED);
applyBonus(player, bonus);
bonus *= isSpeedEnabled(itemStack);
applyBonus(player, bonus, itemStack);
}

public void stepHeight(EntityPlayer player) {
Expand All @@ -222,15 +248,15 @@ public void runningTicks(EntityPlayer player) {
}
}

public void applyBonus(EntityPlayer player, float bonus) {
public void applyBonus(EntityPlayer player, float bonus, ItemStack itemStack) {
if (waterEffects && player.isInWater()) {
bonus *= 0.25F;
}
if (player.onGround || player.isOnLadder() || player.capabilities.isFlying) {
if (player.moveForward != 0.0) {
player.moveFlying(0.0F, player.moveForward, bonus);
}
if (player.moveStrafing != 0.0) {
if (player.moveStrafing != 0.0 && itemStack.stackTagCompound.getBoolean(TAG_MOD_OMNI)) {
player.moveFlying(player.moveStrafing, 0.0F, bonus);
}
} else if (Hover.getHover(player.getEntityId())) {
Expand Down Expand Up @@ -270,6 +296,23 @@ public static void renderHUDSpeedNotification() {
GTNHLib.proxy.printMessageAboveHotbar(text, 60, true, true);
}

@Optional.Method(modid = "gtnhlib")
@SideOnly(Side.CLIENT)
public static void renderHUDOmniNotification() {
Minecraft mc = Minecraft.getMinecraft();
String result = "thaumicboots.omniState" + getBoots(mc.thePlayer).stackTagCompound.getBoolean(TAG_MOD_OMNI);
String midResult, finalResult;
if (getBoots(mc.thePlayer).stackTagCompound.getBoolean(TAG_MOD_OMNI)) {
midResult = EnumChatFormatting.DARK_GREEN + StatCollector.translateToLocal(result);
} else {
midResult = EnumChatFormatting.DARK_RED + StatCollector.translateToLocal(result);
}
finalResult = EnumChatFormatting.GOLD + StatCollector.translateToLocal("thaumicboots.omniEffect")
+ " "
+ midResult;
GTNHLib.proxy.printMessageAboveHotbar(finalResult, 60, true, true);
}

@Optional.Method(modid = "gtnhlib")
public static String getModeText(String effect, double val) {
String endResult = (int) val + "%";
Expand All @@ -281,8 +324,6 @@ public static String getModeText(String effect, double val) {
case 100 -> EnumChatFormatting.AQUA + StatCollector.translateToLocal(endResult);
default -> EnumChatFormatting.DARK_GRAY + StatCollector.translateToLocal(endResult);
};

return EnumChatFormatting.GOLD + StatCollector.translateToLocal(effect) + " " + result;

}
}
2 changes: 1 addition & 1 deletion src/main/java/thaumicboots/api/ItemElectricBoots.java
Original file line number Diff line number Diff line change
Expand Up @@ -154,6 +154,6 @@ public void applyFinalBonus(float bonus, EntityPlayer player, ItemStack itemStac
bonus *= 0;
}
bonus *= itemStack.stackTagCompound.getDouble(TAG_MODE_SPEED);
applyBonus(player, bonus);
applyBonus(player, bonus, itemStack);
}
}
2 changes: 1 addition & 1 deletion src/main/java/thaumicboots/api/ItemVoidBoots.java
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public void onArmorTick(final World world, final EntityPlayer player, final Item
// speed boost
float bonus = getSpeedModifier() * sashEquiped(player);
bonus *= stack.stackTagCompound.getDouble(TAG_MODE_SPEED);
applyBonus(player, bonus);
applyBonus(player, bonus, stack);
}

public float sashEquiped(final EntityPlayer player) {
Expand Down
2 changes: 2 additions & 0 deletions src/main/java/thaumicboots/api/serverfiles/PacketHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,7 @@ public static void initPackets() {
INSTANCE.registerMessage(PacketJumpToggleAck.class, PacketJumpToggleAck.class, 2, Side.CLIENT);
INSTANCE.registerMessage(PacketSpeedToggle.class, PacketSpeedToggle.class, 3, Side.SERVER);
INSTANCE.registerMessage(PacketSpeedToggleAck.class, PacketSpeedToggleAck.class, 4, Side.CLIENT);
INSTANCE.registerMessage(PacketOmniToggle.class, PacketOmniToggle.class, 5, Side.SERVER);
INSTANCE.registerMessage(PacketOmniToggleAck.class, PacketOmniToggleAck.class, 6, Side.CLIENT);
}
}
35 changes: 35 additions & 0 deletions src/main/java/thaumicboots/api/serverfiles/PacketOmniToggle.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package thaumicboots.api.serverfiles;

import net.minecraft.entity.player.EntityPlayerMP;
import net.minecraft.item.ItemStack;

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 thaumicboots.api.ItemBoots;

public class PacketOmniToggle implements IMessage, IMessageHandler<PacketOmniToggle, IMessage> {

public void fromBytes(ByteBuf byteBuf) {
// not needed
}

public void toBytes(ByteBuf byteBuf) {
// not needed
}

@Override
public IMessage onMessage(PacketOmniToggle message, MessageContext ctx) {
EntityPlayerMP player = ctx.getServerHandler().playerEntity;
final ItemStack boots = ItemBoots.getBoots(player);
if (boots != null) {
boolean omniState = ItemBoots.changeOmniState(ItemBoots.isOmniEnabled(boots));
ItemBoots.setModeOmni(boots, omniState);
PacketOmniToggleAck ackMessage = new PacketOmniToggleAck();
ackMessage.state = omniState;
PacketHandler.INSTANCE.sendTo(ackMessage, player);
}
return null;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package thaumicboots.api.serverfiles;

import net.minecraft.client.Minecraft;
import net.minecraft.item.ItemStack;

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 thaumicboots.api.ItemBoots;
import thaumicboots.main.utils.compat.GTNHLibHelper;

public class PacketOmniToggleAck implements IMessage, IMessageHandler<PacketOmniToggleAck, IMessage> {

public boolean state;

@Override
public void fromBytes(ByteBuf byteBuf) {
state = byteBuf.readBoolean();
}

@Override
public void toBytes(ByteBuf byteBuf) {
byteBuf.writeBoolean(state);
}

@SideOnly(Side.CLIENT)
public IMessage onMessage(PacketOmniToggleAck message, MessageContext ctx) {
Minecraft mc = Minecraft.getMinecraft();
final ItemStack boots = ItemBoots.getBoots(mc.thePlayer);
if (boots != null) {
ItemBoots.setModeOmni(boots, message.state);
if (GTNHLibHelper.isActive()) {
ItemBoots.renderHUDOmniNotification();
}
}

return null;
}
}
23 changes: 23 additions & 0 deletions src/main/java/thaumicboots/item/boots/unique/ItemSlowBoots.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package thaumicboots.item.boots.unique;

import thaumicboots.api.ItemBoots;
import thaumicboots.main.utils.TabThaumicBoots;

public class ItemSlowBoots extends ItemBoots {

public ItemSlowBoots(ArmorMaterial par2EnumArmorMaterial, int par3, int par4) {
super(par2EnumArmorMaterial, par3, par4);
setCreativeTab(TabThaumicBoots.tabThaumicBoots);
setUnlocalizedName(unlocalisedName);
}

protected void setBootsData() {
super.setBootsData();
tier = 2;
runBonus = -0.035F;
negateFall = true;
unlocalisedName = "ItemSlowBoots";
iconResPath = "thaumicboots:bootsSlow_16x";
armorResPath = "thaumicboots:model/slowboots.png";
}
}
5 changes: 5 additions & 0 deletions src/main/java/thaumicboots/main/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import thaumcraft.api.ThaumcraftApi;
import thaumicboots.item.boots.unique.ItemChristmasBoots;
import thaumicboots.item.boots.unique.ItemSeasonBoots;
import thaumicboots.item.boots.unique.ItemSlowBoots;
import thaumicboots.item.tools.ItemThaumicInterfacer;
import thaumicboots.main.utils.VersionInfo;

Expand All @@ -30,6 +31,7 @@ public class Config {
public static Item arcaniumLens;
public static Item seasonBoots;
public static Item christmasBoots;
public static Item slowBoots;
// ----- Config State info ----------------------------------
public static Configuration configuration;
private static Config instance = null;
Expand Down Expand Up @@ -75,6 +77,9 @@ public static void setupItems() {

christmasBoots = new ItemChristmasBoots(ThaumcraftApi.armorMatSpecial, 4, 3);
GameRegistry.registerItem(christmasBoots, christmasBoots.getUnlocalizedName());

slowBoots = new ItemSlowBoots(ThaumcraftApi.armorMatSpecial, 4, 3);
GameRegistry.registerItem(slowBoots, slowBoots.getUnlocalizedName());
}

private static void processConfigFile() {
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/thaumicboots/main/utils/BootKeys.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import cpw.mods.fml.relauncher.SideOnly;
import thaumicboots.api.serverfiles.PacketHandler;
import thaumicboots.api.serverfiles.PacketJumpToggle;
import thaumicboots.api.serverfiles.PacketOmniToggle;
import thaumicboots.api.serverfiles.PacketSpeedToggle;

public class BootKeys {
Expand All @@ -24,11 +25,16 @@ public class BootKeys {
"keybinding.speedtoggle",
Keyboard.KEY_NONE,
"Thaumic Boots");
private final KeyBinding keyOmniToggle = new KeyBinding(
"keybinding.omniToggle",
Keyboard.KEY_NONE,
"Thaumic Boots");

public BootKeys() {
FMLCommonHandler.instance().bus().register(this);
ClientRegistry.registerKeyBinding(keyJumpToggle);
ClientRegistry.registerKeyBinding(keySpeedToggle);
ClientRegistry.registerKeyBinding(keyOmniToggle);
}

@SideOnly(Side.CLIENT)
Expand All @@ -42,6 +48,8 @@ private void checkKeys() {
toggleJump();
} else if (keySpeedToggle.isPressed()) {
toggleSpeed();
} else if (keyOmniToggle.isPressed()) {
toggleOmni();
}
}

Expand All @@ -52,4 +60,8 @@ private static void toggleJump() {
private static void toggleSpeed() {
PacketHandler.INSTANCE.sendToServer(new PacketSpeedToggle());
}

private static void toggleOmni() {
PacketHandler.INSTANCE.sendToServer(new PacketOmniToggle());
}
}
28 changes: 25 additions & 3 deletions src/main/java/thaumicboots/main/utils/compat/ThaumcraftHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,7 @@ public static void getItems() {

public static InfusionRecipe seasonalBoot;
public static CrucibleRecipe seasonalToChristmas;
public static CrucibleRecipe slowBoot;

public static void setupCrafting() {
thaumaturgicCombinator = ThaumcraftApi.addCrucibleRecipe(
Expand All @@ -284,6 +285,12 @@ public static void setupCrafting() {
new ItemStack(Items.iron_sword), new ItemStack(Blocks.lit_pumpkin),
new ItemStack(ConfigItems.itemFocusFrost), new ItemStack(Blocks.sapling, 1, 1) });

slowBoot = ThaumcraftApi.addCrucibleRecipe(
"TB_Unique_Boots",
new ItemStack(Config.slowBoots),
new ItemStack(ConfigItems.itemBootsTraveller),
new AspectList().add(Aspect.TRAP, 25).add(TB_Aspect.BOOTS, 25).add(Aspect.EXCHANGE, 10));

if (CalendarHelper.isChristmas()) {
seasonalToChristmas = ThaumcraftApi.addCrucibleRecipe(
"TB_Seasonal_Boots",
Expand Down Expand Up @@ -374,9 +381,9 @@ public static void setupResearch() {
new ResourceLocation(VersionInfo.ModID, "textures/gui/research_bg1_b.png"));

ResearchItem coreResearch;
ResearchItem explorationsCore, taintedCore, seasonalCore, seasonalStabilized;
ResearchItem explorationsCore, taintedCore, seasonalCore, seasonalStabilized, uniqueCore;
ResearchPage core1, core2, explorationsCore1, explorationsCore2, taintedCore1, taintedCore2, seasonalCore1,
seasonalCore2, seasonalStabilized1, seasonalStabilized2;
seasonalCore2, seasonalStabilized1, seasonalStabilized2, uniqueCore1, uniqueCore2;
ResearchPage explorationsTainted1, explorationsTainted2, explorationsTainted3, explorationsCompat1,
explorationsCompat2, explorationsCompat3;

Expand Down Expand Up @@ -424,12 +431,27 @@ public static void setupResearch() {
if (CalendarHelper.isChristmas()) {
seasonalStabilized2 = new ResearchPage(seasonalToChristmas);
} else {
seasonalStabilized2 = new ResearchPage("seasonalStabilized2");
seasonalStabilized2 = new ResearchPage("seasonalStabilized.2");
}
seasonalStabilized.setPages(seasonalStabilized1, seasonalStabilized2);
seasonalStabilized.setParents("TB_Seasonal_Boots");
ResearchCategories.addResearch(seasonalStabilized);

uniqueCore = new ResearchItem(
"TB_Unique_Boots",
category,
new AspectList().add(TB_Aspect.BOOTS, 25).add(Aspect.EXCHANGE, 25).add(Aspect.TOOL, 25)
.add(Aspect.MAGIC, 25).add(Aspect.ENERGY, 25),
-2,
0,
0,
new ItemStack(Config.slowBoots));
uniqueCore1 = new ResearchPage("UniqueCore.1");
uniqueCore2 = new ResearchPage(slowBoot);
uniqueCore.setPages(uniqueCore1, uniqueCore2);
uniqueCore.setParents("TB_Core_Research");
ResearchCategories.addResearch(uniqueCore);

if (!EMTHelper.isActive() && !ExplorationsHelper.isActive() && !TaintedHelper.isActive()) {
return;
}
Expand Down
Loading