diff --git a/src/main/java/techreborn/Core.java b/src/main/java/techreborn/Core.java index 730ea982b..5eab5943e 100644 --- a/src/main/java/techreborn/Core.java +++ b/src/main/java/techreborn/Core.java @@ -216,6 +216,7 @@ public class Core { event.registerPacket(PacketRollingMachineLock.class, Side.SERVER); event.registerPacket(PacketFusionControlSize.class, Side.SERVER); event.registerPacket(PacketAutoCraftingTableLock.class, Side.SERVER); + event.registerPacket(PacketRefund.class, Side.SERVER); } @Mod.EventHandler diff --git a/src/main/java/techreborn/client/gui/GuiManual.java b/src/main/java/techreborn/client/gui/GuiManual.java index 629cf9f05..f4ff2d868 100644 --- a/src/main/java/techreborn/client/gui/GuiManual.java +++ b/src/main/java/techreborn/client/gui/GuiManual.java @@ -30,10 +30,13 @@ import net.minecraft.client.gui.GuiScreen; import net.minecraft.client.resources.I18n; import net.minecraft.entity.player.EntityPlayer; import net.minecraft.util.ResourceLocation; +import reborncore.common.network.NetworkManager; import techreborn.items.ItemTechManual; +import techreborn.packets.PacketRefund; import java.awt.*; + public class GuiManual extends GuiScreen { ItemTechManual manual; @@ -44,7 +47,7 @@ public class GuiManual extends GuiScreen { int guiHeight = 195; private static final String text1 = I18n.format("techreborn.manual.wiki"); private static final String text2 = I18n.format("techreborn.manual.discord"); - + private static final String text3 = I18n.format("techreborn.manual.refund"); public GuiManual(EntityPlayer player) { this.player = player; @@ -57,8 +60,12 @@ public class GuiManual extends GuiScreen { @Override public void initGui() { - buttonList.add(new GuiButton(1, (width / 2 - 30), (height / 2 - (guiHeight / 4)) + 17, 60, 20, I18n.format("techreborn.manual.wikibtn"))); - buttonList.add(new GuiButton(2, (width / 2 - 30), (height / 2) + 22, 60, 20, I18n.format("techreborn.manual.discordbtn"))); + int y = height / 4; + buttonList.add(new GuiButton(1, (width / 2 - 30), y + 10, 60, 20, I18n.format("techreborn.manual.wikibtn"))); + buttonList.add(new GuiButton(2, (width / 2 - 30), y + 60, 60, 20, I18n.format("techreborn.manual.discordbtn"))); + if(PacketRefund.allowRefund){ + buttonList.add(new GuiButton(3, (width / 2 - 30), y + 110, 60, 20, I18n.format("techreborn.manual.refundbtn"))); + } } @Override @@ -68,8 +75,12 @@ public class GuiManual extends GuiScreen { int centerX = (width / 2) - guiWidth / 2; int centerY = (height / 2) - guiHeight / 2; drawTexturedModalRect(centerX, centerY, 0, 0, guiWidth, guiHeight); - fontRenderer.drawString(text1, ((width / 2) - fontRenderer.getStringWidth(text1) / 2), height / 2 - (guiHeight / 4), 4210752); - fontRenderer.drawString(text2, ((width / 2) - fontRenderer.getStringWidth(text2) / 2), height / 2 + 5, 4210752); + int y = height / 4; + fontRenderer.drawString(text1, ((width / 2) - fontRenderer.getStringWidth(text1) / 2), y, 4210752); + fontRenderer.drawString(text2, ((width / 2) - fontRenderer.getStringWidth(text2) / 2), y + 50, 4210752); + if(PacketRefund.allowRefund){ + fontRenderer.drawString(text3, ((width / 2) - fontRenderer.getStringWidth(text3) / 2), y + 100, 4210752); + } super.drawScreen(mouseX, mouseY, partialTicks); } @@ -80,7 +91,11 @@ public class GuiManual extends GuiScreen { mc.displayGuiScreen(new GuiConfirmOpenLink(this, "http://wiki.techreborn.ovh", 1, false)); break; case 2: - mc.displayGuiScreen(new GuiConfirmOpenLink(this, "http://discord.gg/0tCDWb77cvetwm0e", 2, false)); + mc.displayGuiScreen(new GuiConfirmOpenLink(this, "https://discord.gg/teamreborn", 2, false)); + break; + case 3: + mc.displayGuiScreen(null); + NetworkManager.sendToServer(new PacketRefund()); break; } } diff --git a/src/main/java/techreborn/packets/PacketRefund.java b/src/main/java/techreborn/packets/PacketRefund.java new file mode 100644 index 000000000..1d4cb39cc --- /dev/null +++ b/src/main/java/techreborn/packets/PacketRefund.java @@ -0,0 +1,73 @@ +/* + * This file is part of TechReborn, licensed under the MIT License (MIT). + * + * Copyright (c) 2018 TechReborn + * + * Permission is hereby granted, free of charge, to any person obtaining a copy + * of this software and associated documentation files (the "Software"), to deal + * in the Software without restriction, including without limitation the rights + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell + * copies of the Software, and to permit persons to whom the Software is + * furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all + * copies or substantial portions of the Software. + * + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE + * SOFTWARE. + */ + +package techreborn.packets; + +import net.minecraft.entity.player.EntityPlayerMP; +import net.minecraft.init.Items; +import net.minecraft.item.ItemStack; +import net.minecraftforge.fml.common.network.simpleimpl.MessageContext; +import reborncore.common.network.ExtendedPacketBuffer; +import reborncore.common.network.INetworkPacket; +import reborncore.common.registration.RebornRegistry; +import reborncore.common.registration.impl.ConfigRegistry; +import reborncore.common.util.OreUtil; +import techreborn.init.ModItems; +import techreborn.lib.ModInfo; + +import java.io.IOException; + +@RebornRegistry(modID = ModInfo.MOD_ID) +public class PacketRefund implements INetworkPacket { + + @ConfigRegistry(config = "misc", category = "general", key = "manualRefund", comment = "Allow refunding items used to craft the manual") + public static boolean allowRefund = true; + + @Override + public void writeData(ExtendedPacketBuffer buffer) throws IOException { + + } + + @Override + public void readData(ExtendedPacketBuffer buffer) throws IOException { + + } + + @Override + public void processData(PacketRefund message, MessageContext context) { + if (allowRefund) { + EntityPlayerMP playerMP = context.getServerHandler().player; + for (int i = 0; i < playerMP.inventory.getSizeInventory(); i++) { + ItemStack stack = playerMP.inventory.getStackInSlot(i); + if (stack.getItem() == ModItems.MANUAL) { + playerMP.inventory.removeStackFromSlot(i); + playerMP.inventory.addItemStackToInventory(new ItemStack(Items.BOOK)); + playerMP.inventory.addItemStackToInventory(OreUtil.getStackFromName("ingotRefinedIron")); + return; + } + } + } + + } +} diff --git a/src/main/resources/assets/techreborn/lang/en_us.lang b/src/main/resources/assets/techreborn/lang/en_us.lang index 9d3a0ea7a..3835fb467 100644 --- a/src/main/resources/assets/techreborn/lang/en_us.lang +++ b/src/main/resources/assets/techreborn/lang/en_us.lang @@ -627,8 +627,10 @@ techreborn.tooltip.alarm=Shift rightclick to change sound #ManualUI techreborn.manual.wiki=Online wiki techreborn.manual.discord=Our discord +techreborn.manual.refund=I want a refund techreborn.manual.wikibtn=Open techreborn.manual.discordbtn=Join +techreborn.manual.refundbtn=Refund #Advancements advancements.techreborn.root.desc=Now that you have acquired Tech Reborn ore, you might find a tree tap usefull.