Jump to content

Scourrge

Members
  • Posts

    12
  • Joined

  • Last visited

Recent Profile Visitors

The recent visitors block is disabled and is not being shown to other users.

Scourrge's Achievements

Tree Puncher

Tree Puncher (2/8)

0

Reputation

  1. Seems like it. I tried to run further from spawn and it seems working. My bad. Spawn protection was last thing that came to my mind
  2. I don't think there is a problem with code. Because in Singleplayer everything works fine. On dedicated server for OP players everything works fine. The only case when modification doesn't behave as expected is when you are not OP and you try to place modification block it immediately disappears. And when you try to use modification block (when placed) to open GUI nothing happens (onBlockActivated method is not even called). So it seems like server is somehow blocking modification for non-OPed players. Biggest portion of my implementation is taken straight from this example https://github.com/TheGreyGhost/MinecraftByExample/tree/master/src/main/java/minecraftbyexample/mbe30_inventory_basic . Implementations like ContainerBlock, TileEntity, Container, Content, Registration events, Screen are all taken from this implementation.
  3. Hi, today I tried to run my modification on dedicated server and encountered an anomaly when Block's ContainerScreen displays only when player has administration rights (OP) otherwise nothing happens. Could you please point me where could be a problem? In singleplayer opening of Screens works fine. Also on dedicated server if player has OP rights. I don't check if player has OP rights anywhere in my code. EDIT: I debugged a little bit more and found out that when I am not OP I can't even place the block it immediatelly disappears. Moreover when trying to use block while I am not OP the method onBlockActivated is not called at all. Thank you in advance
  4. Hi, is it possible to prevent closing ContainerScreen on InventoryButton? Because I have a text field in my container screen and I need to be able to write characters from range a-z in it, but as soon as inventory button is pressed, the screen closes. Is it somehow possible to prevent this behavior? Thank you.
  5. Hi, I would like to ask, what is the best way of creating global, world-scoped variables. In the official documentation is said something about WorldSavedData. But the documentation seems outdated and described instructions doesn't work anymore. Thanks for response.
  6. Hi, I would like to ask. Is it possible to create listbox within screen window? By listbox i mean scrollable area with selectable item(s). When I was exploring Minecraft's source codes I found some abstract classes like AbstractList and AbstractOptionsList etc. But since the code seems to be obfuscated it is hard to understand how exactly I should implement these classes and it is hard to understand it without comments. Don't somebody have some sample implementation of such GUI component?
  7. Hi, I would like to ask what is the best way to replace taken stack from container for a new one. I've tried to do it in 2 ways. 1. Implement it within removeStackFromSlot like this: @Override public ItemStack removeStackFromSlot(int index) { int maxPossibleItemStackSize = contents.getSlotLimit(index); ItemStack newStack = new ItemStack(CommonEvents.keysItem); CompoundNBT nbt = newStack.getOrCreateTag(); if(!KeysItem.hasKeysGenerated(nbt)){ KeysItem.generateKeys(nbt); } ItemStack takenStack = contents.extractItem(index, maxPossibleItemStackSize, false); this.setInventorySlotContents(index, newStack); return takenStack; } But this doesn't work at all. 2. Implement it within markDirty like this: @Override public void markDirty() { markDirtyNotification.invoke(); if(this.getStackInSlot(0) == ItemStack.EMPTY) { ItemStack newStack = new ItemStack(CommonEvents.keysItem); CompoundNBT nbt = newStack.getOrCreateTag(); if (!KeysItem.hasKeysGenerated(nbt)) { KeysItem.generateKeys(nbt); } this.setInventorySlotContents(0, newStack); } } This works, but somehow inconsistently, that even the taken stack with generated NBT properties gets replaced for a new one and that is not exactly what I want. I need to extract exactly the Item Stack that is currently in the container and after it was taken away generate a new one instead. Thank you in advance
  8. Hi, I would like to ask, is it possible to store custom data into item stack's nbt when the stack is created? Because currently I'm filling my custom data in addInformation method which if I understand correctly is called when tooltips should be displayed. This method works, but I don't find it that clean, so I would like to add these data the moment when the item stack is created. Is this possible somehow? Thank you.
  9. Hi I got textbox and button working. So I will post the code for future for people who would want to achieve something similar as I do. public class InventoryBlockScreen extends ContainerScreen<InventoryBlockContainer> { private static final ResourceLocation BACKGROUND_TEXTURE = new ResourceLocation("bitcoinmod", "textures/gui/inventory_block_gui.png"); private String test = "test"; TextFieldWidget textField; public InventoryBlockScreen(InventoryBlockContainer blockContainer, PlayerInventory playerInventory, ITextComponent title) { super(blockContainer, playerInventory, title); xSize = 176; ySize = 133; } @Override public void init(){ super.init(); int TEXTFIELD_X_COORDINATE = 8; int TEXTFIELD_Y_COORDINATE = InventoryBlockContainer.PLAYER_INVENTORY_YPOS - 12; textField = new TextFieldWidget(font, TEXTFIELD_X_COORDINATE + this.guiLeft, TEXTFIELD_Y_COORDINATE + this.guiTop, 100, 12, test); textField.setEnableBackgroundDrawing(false); textField.setVisible(true); textField.setText(test); textField.setFocused2(true); this.children.add(textField); this.setFocusedDefault(textField); int BUTTON_X_COORDINATE = 114; int BUTTON_Y_COORDINATE = 38; Button button = new Button(BUTTON_X_COORDINATE + this.guiLeft, BUTTON_Y_COORDINATE + this.guiTop, 100, 12, "PRESS ME", (btn) -> {BitcoinMod.LOGGER.debug(textField.getText());}); button.visible = true; button.active = true; this.addButton(button); } @Override public void render(int mouseX, int mouseY, float partialTicks) { this.renderBackground(); super.render(mouseX, mouseY, partialTicks); this.renderHoveredToolTip(mouseX, mouseY); this.textField.setFocused2(true); this.textField.render(mouseX, mouseY, partialTicks); for(Widget button : buttons){ button.render(mouseX, mouseY, partialTicks); } } @Override protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { final float LABEL_XPOS = 5; final float FONT_Y_SPACING = 12; final float CHEST_LABEL_YPOS = InventoryBlockContainer.TILE_INVENTORY_YPOS - FONT_Y_SPACING; font.drawString(this.title.getFormattedText(), LABEL_XPOS, CHEST_LABEL_YPOS, Color.darkGray.getRGB()); } @Override protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) { RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F); this.minecraft.getTextureManager().bindTexture(BACKGROUND_TEXTURE); int edgeSpacingX = (this.width - this.xSize) / 2; int edgeSpacingY = (this.height - this.ySize) / 2; this.blit(edgeSpacingX, edgeSpacingY, 0, 0, this.xSize, this.ySize); } }
  10. Okay, so after some digging I've managed to get textfield working, but the textfield is rendering in the bad position (outside of the GUI window). I know, that this is because rendering of the textfield uses global coordinates (from topleft of the MC window) and rendering of the GUI window foreground uses relative coordinates. But I don't know how to fix it at the moment. I would like to achieve this . This is what I managed to get so far: public class InventoryBlockScreen extends ContainerScreen<InventoryBlockContainer> { private static final ResourceLocation BACKGROUND_TEXTURE = new ResourceLocation("bitcoinmod", "textures/gui/inventory_block_gui.png"); private String test = "test"; TextFieldWidget widget; public InventoryBlockScreen(InventoryBlockContainer blockContainer, PlayerInventory playerInventory, ITextComponent title) { super(blockContainer, playerInventory, title); xSize = 176; ySize = 133; } @Override public void init(){ super.init(); int TEXTFIELD_X_COORDINATE = 8; int TEXTFIELD_Y_COORDINATE = InventoryBlockContainer.PLAYER_INVENTORY_YPOS - 12; widget = new TextFieldWidget(font, TEXTFIELD_X_COORDINATE, TEXTFIELD_Y_COORDINATE, 100, 12, test); widget.setEnableBackgroundDrawing(false); widget.setVisible(true); widget.setText(test); widget.setFocused2(true); this.children.add(widget); this.setFocusedDefault(widget); } @Override public void render(int mouseX, int mouseY, float partialTicks) { this.renderBackground(); super.render(mouseX, mouseY, partialTicks); this.renderHoveredToolTip(mouseX, mouseY); this.widget.setFocused2(true); this.widget.render(mouseX, mouseY, partialTicks); } @Override protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { final float LABEL_XPOS = 5; final float FONT_Y_SPACING = 12; final float CHEST_LABEL_YPOS = InventoryBlockContainer.TILE_INVENTORY_YPOS - FONT_Y_SPACING; font.drawString(this.title.getFormattedText(), LABEL_XPOS, CHEST_LABEL_YPOS, Color.darkGray.getRGB()); // final float PLAYER_INV_LABEL_YPOS = InventoryBlockContainer.PLAYER_INVENTORY_YPOS - FONT_Y_SPACING; // this.font.drawString(this.playerInventory.getDisplayName().getFormattedText(), // LABEL_XPOS, PLAYER_INV_LABEL_YPOS, Color.darkGray.getRGB()); } @Override protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) { RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F); this.minecraft.getTextureManager().bindTexture(BACKGROUND_TEXTURE); int edgeSpacingX = (this.width - this.xSize) / 2; int edgeSpacingY = (this.height - this.ySize) / 2; this.blit(edgeSpacingX, edgeSpacingY, 0, 0, this.xSize, this.ySize); } }
  11. public class InventoryBlockScreen extends ContainerScreen<InventoryBlockContainer> { private static final ResourceLocation BACKGROUND_TEXTURE = new ResourceLocation("bitcoinmod", "textures/gui/inventory_block_gui.png"); private String test = "test"; public InventoryBlockScreen(InventoryBlockContainer blockContainer, PlayerInventory playerInventory, ITextComponent title) { super(blockContainer, playerInventory, title); // Set the width and height of the gui. Should match the size of the texture! xSize = 176; ySize = 133; } public void render(int mouseX, int mouseY, float partialTicks) { this.renderBackground(); super.render(mouseX, mouseY, partialTicks); this.renderHoveredToolTip(mouseX, mouseY); } protected void drawGuiContainerForegroundLayer(int mouseX, int mouseY) { final float LABEL_XPOS = 5; final float FONT_Y_SPACING = 12; final float CHEST_LABEL_YPOS = InventoryBlockContainer.TILE_INVENTORY_YPOS - FONT_Y_SPACING; font.drawString(this.title.getFormattedText(), LABEL_XPOS, CHEST_LABEL_YPOS, Color.darkGray.getRGB()); TextFieldWidget widget = new TextFieldWidget(font, 8, 38, 100, 10, test); //Here // final float PLAYER_INV_LABEL_YPOS = InventoryBlockContainer.PLAYER_INVENTORY_YPOS - FONT_Y_SPACING; // this.font.drawString(this.playerInventory.getDisplayName().getFormattedText(), // LABEL_XPOS, PLAYER_INV_LABEL_YPOS, Color.darkGray.getRGB()); } protected void drawGuiContainerBackgroundLayer(float partialTicks, int mouseX, int mouseY) { RenderSystem.color4f(1.0F, 1.0F, 1.0F, 1.0F); this.minecraft.getTextureManager().bindTexture(BACKGROUND_TEXTURE); int edgeSpacingX = (this.width - this.xSize) / 2; int edgeSpacingY = (this.height - this.ySize) / 2; this.blit(edgeSpacingX, edgeSpacingY, 0, 0, this.xSize, this.ySize); } } I tried this. I know, that it won't be visible in the window, since the textbox is not added into the background texture. But I thought that it would add at least transparent highlightable line.
  12. Hi. I would like to ask if it is possible (and how if it is) to display textbox and button inside of ContainerScreen GUI window. Because I created demo based on this example on github. But I would like to extend it and try to add textbox and button. I tried to add textfieldwidget in ContainerScreen class constructor, but it didn't work. Thanks for responses in advance
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.