Skip to content

Commit

Permalink
Fix hammers going through bedrock, add oven gui, fix obfuscation errors
Browse files Browse the repository at this point in the history
  • Loading branch information
falkreon committed Apr 9, 2017
1 parent 4f50aa8 commit fe76a7f
Show file tree
Hide file tree
Showing 31 changed files with 871 additions and 1,360 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ dependencies {

group = "io.github.elytra"
archivesBaseName = "Thermionics"
version = "MC1.11.2_ver1.0.4"
version = "MC1.11.2_ver1.0.7"

sourceCompatibility = 1.8
targetCompatibility = 1.8
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.elytradev.thermionics.data;
package com.elytradev.concrete.gui;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

import com.elytradev.thermionics.client.gui.GuiTesting;
import com.elytradev.concrete.inventory.ValidatedSlot;
import com.elytradev.thermionics.gui.WPanel;

import net.minecraft.entity.player.EntityPlayer;
Expand All @@ -37,19 +37,19 @@
import net.minecraft.inventory.Slot;
import net.minecraft.item.ItemStack;

public class ContainerTesting extends Container {
/**
* "Container" is Minecraft's way of managing shared state for a block whose GUI is currently open.
*/
public class ConcreteContainer extends Container {

private IInventory player;
private IInventory playerInventory;
private IInventory container;
private WPanel rootPanel;

public ContainerTesting(@Nonnull IInventory player, @Nullable IInventory container) {
this.player = player;
public ConcreteContainer(@Nonnull IInventory player, @Nullable IInventory container) {
this.playerInventory = player;
this.container = container;
this.initPlayerInventory(GuiTesting.PADDING, GuiTesting.PADDING + (18*4));

initContainerSlot(0, 2,1);
initContainerSlot(1, 6,1);
}

@Override
Expand All @@ -60,19 +60,19 @@ public boolean canInteractWith(EntityPlayer playerIn) {


public void initContainerSlot(int slot, int x, int y) {
this.addSlotToContainer(new SlotTesting(container, slot, x*18 + 6, y*18 + 6));
this.addSlotToContainer(new ValidatedSlot(container, slot, x*18, y*18));
}

public void initPlayerInventory(int x, int y) {
for (int yi = 0; yi < 3; yi++) {
for (int xi = 0; xi < 9; xi++) {
addSlotToContainer(new Slot(player, xi + (yi * 9) + 9, x + (xi * 18), y + (yi * 18)));
addSlotToContainer(new Slot(playerInventory, xi + (yi * 9) + 9, x + (xi * 18), y + (yi * 18)));
}
}


for(int i=0; i<9; i++) {
addSlotToContainer(new Slot(player, i, x+(i*18), y + (3*18) + 4));
addSlotToContainer(new Slot(playerInventory, i, x+(i*18), y + (3*18) + 4));
}
}

Expand All @@ -95,8 +95,59 @@ public void detectAndSendChanges() {


public ItemStack transferStackInSlot(EntityPlayer playerIn, int index) {
System.out.println("transferStackInSlot:"+index);
return super.transferStackInSlot(playerIn, index);
//System.out.println("transferStackInSlot:"+index);

ItemStack srcStack = ItemStack.EMPTY;
Slot src = this.inventorySlots.get(index);
if (src != null && src.getHasStack()) {
srcStack = src.getStack();

if (src.inventory==playerInventory) {
//System.out.println("Transferring "+srcStack+" from playerInventory to container");
//Try to push the stack from the player-inventory to the container-inventory. If that's not possible,
//try to move it between the non-hotbar-inventory and the hotbar-inventory

ItemStack remaining = transferToInventory(srcStack, container);
//System.out.println("Remaining: "+remaining);
//this.detectAndSendChanges();
src.putStack(remaining);
return ItemStack.EMPTY;
//return remaining;


} else {
//Try to push the stack from the container-inventory to the player-inventory. Prefer non-hotbar if possible

//this.mergeItemStack(srcStack, 9, 27+9, false);
//Non-hotbar inventory
//System.out.println("Transferring "+srcStack+" from container to playerInventory");
ItemStack remaining = transferToInventory(srcStack, playerInventory);
//System.out.println("Remaining: "+remaining);
//this.detectAndSendChanges();
src.putStack(remaining);
return ItemStack.EMPTY;
//return remaining;
//

/*
for(int i=9; i<27+9; i++) {
if (playerInventory.isItemValidForSlot(index, srcStack)) {
//playerInventory.
}
}*/
}
} else {
//Shift-clicking on an invalid or empty slot does nothing.
}

src.putStack(srcStack);
return ItemStack.EMPTY;
//return srcStack;




//return super.transferStackInSlot(playerIn, index);

/*
ItemStack itemstack = ItemStack.EMPTY;
Expand Down Expand Up @@ -171,4 +222,61 @@ public WPanel getRootPanel() {
return this.rootPanel;
}

public ItemStack transferToInventory(ItemStack stack, IInventory inventory) {
ItemStack result = stack.copy();


//Prefer dropping on top of existing stacks
for(Slot s : this.inventorySlots) {
if (s.inventory==inventory && s.isItemValid(result)) {
if (s.getHasStack()) {
ItemStack dest = s.getStack();

//If the two items can stack together and the existing stack can hold more items...
if (canStackTogether(result, dest) && dest.getCount()<s.getItemStackLimit(dest)) {
int sum = dest.getCount() + result.getCount();
int toDeposit = Math.min(s.getItemStackLimit(dest), sum);
int remaining = sum - toDeposit;
dest.setCount(toDeposit);
result.setCount(remaining);
s.onSlotChanged();
}
if (result.isEmpty()) {
return ItemStack.EMPTY;
}
}

}
}

//No eligible existing stacks remain. Drop into the first available empty slots.
for(Slot s : this.inventorySlots) {
if (s.inventory==inventory && s.isItemValid(result)) {
if (!s.getHasStack()) {
s.putStack(result.splitStack(s.getSlotStackLimit()));
}
}

if (result.isEmpty()) {
return ItemStack.EMPTY;
}
}

return result;
}

public boolean canStackTogether(ItemStack src, ItemStack dest) {
if (src.isEmpty() || dest.isEmpty()) return false; //Don't stack using itemstack counts if one or the other is empty.

return
dest.isStackable() &&
dest.getItem()==src.getItem() &&
dest.getItemDamage()==src.getItemDamage() &&
dest.areCapsCompatible(src);
}

public String getLocalizedName() {

return container.getDisplayName().getUnformattedComponentText();
}
}
106 changes: 106 additions & 0 deletions src/main/java/com/elytradev/concrete/gui/GuiDrawing.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/**
* MIT License
*
* Copyright (c) 2017 Isaac Ellingson (Falkreon) and contributors
*
* 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 com.elytradev.concrete.gui;

import org.lwjgl.opengl.GL11;

import net.minecraft.client.renderer.GlStateManager;
import net.minecraft.client.renderer.Tessellator;
import net.minecraft.client.renderer.VertexBuffer;
import net.minecraft.client.renderer.vertex.DefaultVertexFormats;

public class GuiDrawing {

/**
* Draws an untextured rectangle of the specified RGB color. Alpha is always 1.0f.
*/
public static void rect(int left, int top, int width, int height, int color) {
if (width<=0) width=1;
if (height<=0) height=1;

float r = (float)(color >> 16 & 255) / 255.0F;
float g = (float)(color >> 8 & 255) / 255.0F;
float b = (float)(color & 255) / 255.0F;
Tessellator tessellator = Tessellator.getInstance();
VertexBuffer vertexbuffer = tessellator.getBuffer();
GlStateManager.enableBlend();
GlStateManager.disableTexture2D();
GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO);
GlStateManager.color(r, g, b, 1.0f);
vertexbuffer.begin(GL11.GL_QUADS, DefaultVertexFormats.POSITION); //I thought GL_QUADS was deprecated but okay, sure.
vertexbuffer.pos(left, top+height, 0.0D).endVertex();
vertexbuffer.pos(left+width, top+height, 0.0D).endVertex();
vertexbuffer.pos(left+width, top, 0.0D).endVertex();
vertexbuffer.pos(left, top, 0.0D).endVertex();
tessellator.draw();
GlStateManager.enableTexture2D();
GlStateManager.disableBlend();
}

/**
* Draws a beveled, round rectangle that is substantially similar to default Minecraft UI panels.
*/
public static void drawGuiPanel(int x, int y, int width, int height) {
drawGuiPanel(x, y, width, height, 0x555555, 0xC6C6C6, 0xFFFFFF, 0x000000);
}


public static void drawGuiPanel(int x, int y, int width, int height, int shadow, int panel, int hilight, int outline) {
rect(x+3, y+3, width-6, height-6, panel); //Main panel area

rect(x+2, y+1, width-4, 2, hilight); //Top hilight
rect(x+2, y+height-3, width-4, 2, shadow); //Bottom shadow
rect(x+1, y+2, 2, height-4, hilight); //Left hilight
rect(x+width-3, y+2, 2, height-4, shadow); //Right shadow
rect(x+width-3, y+2, 1, 1, panel); //Topright non-hilight/non-shadow transition pixel
rect(x+2, y+height-3, 1, 1, panel); //Bottomleft non-hilight/non-shadow transition pixel
rect(x+3, y+3, 1, 1, hilight); //Topleft round hilight pixel
rect(x+width-4, y+height-4, 1, 1, shadow); //Bottomright round shadow pixel

rect(x+2, y, width-4, 1, outline); //Top outline
rect(x, y+2, 1, height-4, outline); //Left outline
rect(x+width-1, y+2, 1, height-4, outline); //Right outline
rect(x+2, y+height-1, width-4, 1, outline); //Bottom outline
rect(x+1, y+1, 1, 1, outline); //Topleft round pixel
rect(x+1, y+height-2, 1, 1, outline); //Bottomleft round pixel
rect(x+width-2, y+1, 1, 1, outline); //Topright round pixel
rect(x+width-2, y+height-2, 1, 1, outline); //Bottomright round pixel
}

public static void drawItemSlot(int x, int y) {
rect(x, y, 18, 18, 0x8b8b8b); //Center panel
rect(x, y, 17, 1, 0x373737); //Top shadow
rect(x, y+1, 1, 16, 0x373737); //Left shadow
rect(x+17, y+1, 1, 17, 0xFFFFFF); //Right hilight
rect(x+1, y+17, 17, 1, 0xFFFFFF); //Bottom hilight
}

public static void drawBigItemSlot(int x, int y) {
rect(x-4, y-4, 18+8, 18+8, 0x8b8b8b); //Center panel
rect(x-4, y-4, 17+8, 1-4, 0x373737); //Top shadow
rect(x-4, y+1-4, 1-4, 16+8, 0x373737); //Left shadow
rect(x+17+4, y+1-4, 1-4, 17+8, 0xFFFFFF); //Right hilight
rect(x+1-4, y+17+4, 17+8, 1-4, 0xFFFFFF); //Bottom hilight
}
}
Loading

0 comments on commit fe76a7f

Please sign in to comment.