added renaming feature with quartz cutting knife
This commit is contained in:
@@ -25,6 +25,9 @@ import java.util.List;
|
||||
import javax.annotation.Nonnull;
|
||||
import javax.annotation.Nullable;
|
||||
|
||||
import appeng.api.util.AEPartLocation;
|
||||
import appeng.core.sync.GuiBridge;
|
||||
import appeng.items.tools.quartz.ToolQuartzCuttingKnife;
|
||||
import com.google.common.collect.Lists;
|
||||
|
||||
import net.minecraft.block.Block;
|
||||
@@ -46,6 +49,7 @@ import net.minecraft.world.World;
|
||||
import net.minecraftforge.common.property.ExtendedBlockState;
|
||||
import net.minecraftforge.common.property.IExtendedBlockState;
|
||||
import net.minecraftforge.common.property.IUnlistedProperty;
|
||||
import net.minecraftforge.event.ForgeEventFactory;
|
||||
import net.minecraftforge.items.ItemHandlerHelper;
|
||||
|
||||
import appeng.api.implementations.items.IMemoryCard;
|
||||
@@ -367,6 +371,14 @@ public abstract class AEBaseTileBlock extends AEBaseBlock implements ITileEntity
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
if (heldItem.getItem() instanceof ToolQuartzCuttingKnife && !(this instanceof BlockCableBus)) {
|
||||
if (ForgeEventFactory.onItemUseStart(player, heldItem, 1) <= 0) return false;
|
||||
final AEBaseTile tile = this.getTileEntity(world, pos);
|
||||
if (tile == null) return false;
|
||||
Platform.openGUI(player, tile, AEPartLocation.fromFacing(facing), GuiBridge.GUI_RENAMER);
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
return this.onActivated( world, pos, player, hand, player.getHeldItem( hand ), facing, hitX, hitY, hitZ );
|
||||
|
||||
@@ -30,7 +30,7 @@ import appeng.core.AELog;
|
||||
import appeng.core.localization.GuiText;
|
||||
import appeng.core.sync.network.NetworkHandler;
|
||||
import appeng.core.sync.packets.PacketValueConfig;
|
||||
import appeng.items.contents.QuartzKnifeObj;
|
||||
import appeng.bootstrap.contents.QuartzKnifeObj;
|
||||
|
||||
|
||||
public class GuiQuartzKnife extends AEBaseGui
|
||||
|
||||
@@ -0,0 +1,108 @@
|
||||
package appeng.client.gui.implementations;
|
||||
|
||||
import appeng.client.gui.AEBaseGui;
|
||||
import appeng.client.gui.widgets.MEGuiTextField;
|
||||
import appeng.container.implementations.ContainerRenamer;
|
||||
import appeng.core.AELog;
|
||||
import appeng.core.localization.GuiText;
|
||||
import appeng.core.sync.network.NetworkHandler;
|
||||
import appeng.core.sync.packets.PacketValueConfig;
|
||||
import appeng.helpers.ICustomNameObject;
|
||||
import net.minecraft.client.Minecraft;
|
||||
import net.minecraft.client.gui.GuiButton;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.item.ItemStack;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
public class GuiRenamer extends AEBaseGui {
|
||||
private MEGuiTextField textField;
|
||||
private GuiButton confirmButton;
|
||||
|
||||
public GuiRenamer(InventoryPlayer ip, ICustomNameObject obj) {
|
||||
super(new ContainerRenamer(ip, obj));
|
||||
this.xSize = 256;
|
||||
|
||||
this.textField = new MEGuiTextField(Minecraft.getMinecraft().fontRenderer, 0, 0, 230, 12) {
|
||||
@Override
|
||||
public void onTextChange(final String oldText) {
|
||||
final String text = getText();
|
||||
|
||||
if (!text.equals(oldText)) {
|
||||
((ContainerRenamer) inventorySlots).setCustomName(text);
|
||||
}
|
||||
}
|
||||
};
|
||||
this.textField.setEnableBackgroundDrawing(false);
|
||||
this.textField.setMaxStringLength(32);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void initGui() {
|
||||
super.initGui();
|
||||
|
||||
this.textField.x = this.guiLeft + 12;
|
||||
this.textField.y = this.guiTop + 35;
|
||||
this.textField.setFocused(true);
|
||||
|
||||
this.buttonList.add(this.confirmButton = new GuiButton(0, this.guiLeft + 238, this.guiTop + 33, 12, 12, "↵"));
|
||||
|
||||
((ContainerRenamer) this.inventorySlots).setTextField(this.textField);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawFG(int offsetX, int offsetY, int mouseX, int mouseY) {
|
||||
this.fontRenderer.drawString(this.getGuiDisplayName(GuiText.Renamer.getLocal()), 12, 8, 4210752);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawBG(int offsetX, int offsetY, int mouseX, int mouseY) {
|
||||
this.bindTexture("guis/renamer.png");
|
||||
this.drawTexturedModalRect(offsetX, offsetY, 0, 0, this.xSize, this.ySize);
|
||||
this.textField.drawTextBox();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void mouseClicked(final int xCoord, final int yCoord, final int btn) throws IOException{
|
||||
this.textField.mouseClicked(xCoord, yCoord, btn);
|
||||
super.mouseClicked(xCoord, yCoord, btn);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void keyTyped(final char character, final int key) throws IOException {
|
||||
if (key == 28) { // Enter
|
||||
try {
|
||||
NetworkHandler.instance().sendToServer(
|
||||
new PacketValueConfig("QuartzKnife.ReName", this.textField.getText()));
|
||||
} catch (IOException e) {
|
||||
AELog.debug(e);
|
||||
}
|
||||
this.mc.player.closeScreen();
|
||||
} else if (!this.textField.textboxKeyTyped(character, key)) {
|
||||
super.keyTyped(character, key);
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void actionPerformed(final GuiButton btn) throws IOException {
|
||||
super.actionPerformed(btn);
|
||||
|
||||
if(btn == this.confirmButton) {
|
||||
try {
|
||||
NetworkHandler.instance().sendToServer(
|
||||
new PacketValueConfig("QuartzKnife.ReName", this.textField.getText()));
|
||||
this.mc.player.closeScreen();
|
||||
} catch (IOException e) {
|
||||
AELog.debug(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public boolean isOverTextField(final int mousex, final int mousey) {
|
||||
return textField.isMouseIn(mousex, mousey);
|
||||
}
|
||||
|
||||
public void setTextFieldValue(final String displayName, final int mousex, final int mousey, final ItemStack stack) {
|
||||
textField.setText(displayName);
|
||||
}
|
||||
}
|
||||
@@ -25,6 +25,7 @@ import net.minecraft.client.renderer.BufferBuilder;
|
||||
import net.minecraft.client.renderer.GlStateManager;
|
||||
import net.minecraft.client.renderer.Tessellator;
|
||||
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;
|
||||
import org.lwjgl.input.Keyboard;
|
||||
|
||||
|
||||
/**
|
||||
@@ -67,6 +68,8 @@ public class MEGuiTextField extends GuiTextField
|
||||
this._height = height;
|
||||
}
|
||||
|
||||
public void onTextChange(final String oldText) {}
|
||||
|
||||
@Override
|
||||
public boolean mouseClicked( final int xPos, final int yPos, final int button )
|
||||
{
|
||||
@@ -97,6 +100,28 @@ public class MEGuiTextField extends GuiTextField
|
||||
return withinXRange && withinYRange;
|
||||
}
|
||||
|
||||
public boolean textboxKeyTyped(final char keyChar, final int keyID) {
|
||||
if (!isFocused()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
final String oldText = getText();
|
||||
boolean handled = super.textboxKeyTyped(keyChar, keyID);
|
||||
|
||||
if (!handled
|
||||
&& (keyID == Keyboard.KEY_RETURN
|
||||
|| keyID == Keyboard.KEY_NUMPADENTER
|
||||
|| keyID == Keyboard.KEY_ESCAPE)) {
|
||||
setFocused(false);
|
||||
}
|
||||
|
||||
if (handled) {
|
||||
onTextChange(oldText);
|
||||
}
|
||||
|
||||
return handled;
|
||||
}
|
||||
|
||||
public void selectAll()
|
||||
{
|
||||
this.setCursorPosition( 0 );
|
||||
@@ -127,6 +152,21 @@ public class MEGuiTextField extends GuiTextField
|
||||
}
|
||||
}
|
||||
|
||||
public void setText(String text, boolean ignoreTrigger) {
|
||||
final String oldText = getText();
|
||||
|
||||
super.setText(text);
|
||||
super.setCursorPositionEnd();
|
||||
|
||||
if (!ignoreTrigger) {
|
||||
onTextChange(oldText);
|
||||
}
|
||||
}
|
||||
|
||||
public void setText(String text) {
|
||||
setText(text, false);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void drawSelectionBox( int startX, int startY, int endX, int endY )
|
||||
{
|
||||
|
||||
@@ -33,7 +33,7 @@ import appeng.api.AEApi;
|
||||
import appeng.container.AEBaseContainer;
|
||||
import appeng.container.slot.SlotOutput;
|
||||
import appeng.container.slot.SlotRestrictedInput;
|
||||
import appeng.items.contents.QuartzKnifeObj;
|
||||
import appeng.bootstrap.contents.QuartzKnifeObj;
|
||||
import appeng.tile.inventory.AppEngInternalInventory;
|
||||
import appeng.util.Platform;
|
||||
|
||||
|
||||
@@ -0,0 +1,48 @@
|
||||
package appeng.container.implementations;
|
||||
|
||||
import appeng.api.config.SecurityPermissions;
|
||||
import appeng.api.parts.IPart;
|
||||
import appeng.client.gui.widgets.MEGuiTextField;
|
||||
import appeng.container.AEBaseContainer;
|
||||
import appeng.helpers.ICustomNameObject;
|
||||
import appeng.util.Platform;
|
||||
import net.minecraft.entity.player.InventoryPlayer;
|
||||
import net.minecraft.tileentity.TileEntity;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
|
||||
public class ContainerRenamer extends AEBaseContainer {
|
||||
private final ICustomNameObject namedObject;
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
private MEGuiTextField textField;
|
||||
|
||||
public ContainerRenamer(InventoryPlayer ip, ICustomNameObject obj) {
|
||||
super(ip, obj instanceof TileEntity ? (TileEntity) obj : null, obj instanceof IPart ? (IPart) obj : null);
|
||||
namedObject = obj;
|
||||
}
|
||||
|
||||
@SideOnly(Side.CLIENT)
|
||||
public void setTextField(final MEGuiTextField name) {
|
||||
this.textField = name;
|
||||
if(getCustomName() != null) textField.setText(getCustomName());
|
||||
}
|
||||
|
||||
public void setNewName(String newValue) {
|
||||
this.namedObject.setCustomName(newValue);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCustomName(final String customName) {
|
||||
super.setCustomName(customName);
|
||||
if(!Platform.isServer() && customName != null) textField.setText(customName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void detectAndSendChanges() {
|
||||
verifyPermissions(SecurityPermissions.BUILD, false);
|
||||
super.detectAndSendChanges();
|
||||
if(!Platform.isServer() && getCustomName() != null) textField.setText(getCustomName());
|
||||
}
|
||||
}
|
||||
@@ -45,7 +45,7 @@ import appeng.container.slot.OptionalSlotFake;
|
||||
import appeng.container.slot.OptionalSlotFakeTypeOnly;
|
||||
import appeng.container.slot.SlotFakeTypeOnly;
|
||||
import appeng.container.slot.SlotRestrictedInput;
|
||||
import appeng.items.contents.NetworkToolViewer;
|
||||
import appeng.bootstrap.contents.NetworkToolViewer;
|
||||
import appeng.items.tools.ToolNetworkTool;
|
||||
import appeng.parts.automation.PartExportBus;
|
||||
import appeng.util.Platform;
|
||||
|
||||
@@ -90,6 +90,8 @@ public enum GuiText
|
||||
Inscriber,
|
||||
QuartzCuttingKnife,
|
||||
|
||||
Renamer,
|
||||
|
||||
// tunnel names
|
||||
METunnel,
|
||||
ItemTunnel,
|
||||
|
||||
@@ -22,6 +22,7 @@ package appeng.core.sync;
|
||||
import java.lang.reflect.Constructor;
|
||||
|
||||
import appeng.container.implementations.*;
|
||||
import appeng.helpers.ICustomNameObject;
|
||||
import appeng.parts.misc.PartOreDicStorageBus;
|
||||
import appeng.parts.reporting.*;
|
||||
import net.minecraft.entity.player.EntityPlayer;
|
||||
@@ -70,7 +71,7 @@ import appeng.fluids.parts.PartSharedFluidBus;
|
||||
import appeng.helpers.IInterfaceHost;
|
||||
import appeng.helpers.IPriorityHost;
|
||||
import appeng.helpers.WirelessTerminalGuiObject;
|
||||
import appeng.items.contents.QuartzKnifeObj;
|
||||
import appeng.bootstrap.contents.QuartzKnifeObj;
|
||||
import appeng.parts.automation.PartFormationPlane;
|
||||
import appeng.parts.automation.PartLevelEmitter;
|
||||
import appeng.parts.misc.PartStorageBus;
|
||||
@@ -181,6 +182,8 @@ public enum GuiBridge implements IGuiHandler
|
||||
|
||||
GUI_INTERFACE_CONFIGURATION_TERMINAL( ContainerInterfaceConfigurationTerminal.class, PartInterfaceConfigurationTerminal.class, GuiHostType.WORLD, SecurityPermissions.BUILD );
|
||||
|
||||
GUI_RENAMER(ContainerRenamer.class, ICustomNameObject.class, GuiHostType.WORLD, SecurityPermissions.BUILD);
|
||||
|
||||
private final Class tileClass;
|
||||
private final Class containerClass;
|
||||
private Class guiClass;
|
||||
|
||||
@@ -137,6 +137,11 @@ public class PacketValueConfig extends AppEngPacket
|
||||
final ContainerQuartzKnife qk = (ContainerQuartzKnife) c;
|
||||
qk.setName( this.Value );
|
||||
}
|
||||
else if( this.Name.equals( "QuartzKnife.ReName" ) && c instanceof ContainerRenamer)
|
||||
{
|
||||
final ContainerRenamer qk = (ContainerRenamer) c;
|
||||
qk.setNewName(this.Value);
|
||||
}
|
||||
else if( this.Name.equals( "TileSecurityStation.ToggleOption" ) && c instanceof ContainerSecurityStation )
|
||||
{
|
||||
final ContainerSecurityStation sc = (ContainerSecurityStation) c;
|
||||
|
||||
@@ -25,4 +25,6 @@ public interface ICustomNameObject
|
||||
String getCustomInventoryName();
|
||||
|
||||
boolean hasCustomInventoryName();
|
||||
|
||||
void setCustomName(String name);
|
||||
}
|
||||
|
||||
@@ -26,9 +26,11 @@ import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.Random;
|
||||
|
||||
import appeng.core.sync.GuiBridge;
|
||||
import appeng.fluids.helper.IConfigurableFluidInventory;
|
||||
import appeng.fluids.parts.PartFluidLevelEmitter;
|
||||
import appeng.fluids.util.AEFluidInventory;
|
||||
import appeng.items.tools.quartz.ToolQuartzCuttingKnife;
|
||||
import appeng.parts.automation.PartLevelEmitter;
|
||||
import com.google.common.base.Preconditions;
|
||||
|
||||
@@ -47,6 +49,7 @@ import net.minecraft.util.math.BlockPos;
|
||||
import net.minecraft.util.math.Vec3d;
|
||||
import net.minecraft.world.IBlockAccess;
|
||||
import net.minecraft.world.World;
|
||||
import net.minecraftforge.event.ForgeEventFactory;
|
||||
import net.minecraftforge.fluids.capability.IFluidHandler;
|
||||
import net.minecraftforge.fml.relauncher.Side;
|
||||
import net.minecraftforge.fml.relauncher.SideOnly;
|
||||
@@ -203,7 +206,12 @@ public abstract class AEBasePart implements IPart, IGridProxyable, IActionHost,
|
||||
return this.getItemStack().hasDisplayName();
|
||||
}
|
||||
|
||||
public void addEntityCrashInfo( final CrashReportCategory crashreportcategory )
|
||||
@Override
|
||||
public void setCustomName(String name) {
|
||||
this.getItemStack().setStackDisplayName(name);
|
||||
}
|
||||
|
||||
public void addEntityCrashInfo(final CrashReportCategory crashreportcategory )
|
||||
{
|
||||
crashreportcategory.addCrashSection( "Part Side", this.getSide() );
|
||||
}
|
||||
@@ -514,10 +522,20 @@ public abstract class AEBasePart implements IPart, IGridProxyable, IActionHost,
|
||||
return false;
|
||||
}
|
||||
|
||||
private boolean useRenamer(final EntityPlayer player) {
|
||||
final ItemStack stack = player.inventory.getCurrentItem();
|
||||
if(stack != null && stack.getItem() instanceof ToolQuartzCuttingKnife) {
|
||||
if(ForgeEventFactory.onItemUseStart(player, stack, 1) <= 0) return false;
|
||||
Platform.openGUI(player, tile, side, GuiBridge.GUI_RENAMER);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public final boolean onActivate( final EntityPlayer player, final EnumHand hand, final Vec3d pos )
|
||||
{
|
||||
if( this.useMemoryCard( player ) )
|
||||
if( this.useMemoryCard( player ) || useRenamer(player) )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
@@ -419,9 +419,6 @@ public class AEBaseTile extends TileEntity implements IOrientable, ICommonTile,
|
||||
* returns the contents of the tile entity, into the world, defaults to dropping everything in the inventory.
|
||||
*
|
||||
* @param w world
|
||||
* @param x x pos of tile entity
|
||||
* @param y y pos of tile entity
|
||||
* @param z z pos of tile entity
|
||||
* @param drops drops of tile entity
|
||||
*/
|
||||
@Override
|
||||
@@ -499,6 +496,11 @@ public class AEBaseTile extends TileEntity implements IOrientable, ICommonTile,
|
||||
return this.customName != null && this.customName.length() > 0;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setCustomName(@Nullable String customName) {
|
||||
setName(customName);
|
||||
}
|
||||
|
||||
public void securityBreak()
|
||||
{
|
||||
this.world.destroyBlock( this.pos, true );
|
||||
|
||||
Reference in New Issue
Block a user