Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Started working on knapping infrastructure
- Loading branch information
1 parent
6def05a
commit 1288272
Showing
13 changed files
with
322 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
73 changes: 73 additions & 0 deletions
73
src/main/java/net/dries007/tfc/api/types/KnappingRecipe.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
/* | ||
* Work under Copyright. Licensed under the EUPL. | ||
* See the project README.md and LICENSE.txt for more information. | ||
*/ | ||
|
||
package net.dries007.tfc.api.types; | ||
|
||
import net.minecraft.item.ItemStack; | ||
import net.minecraftforge.registries.IForgeRegistryEntry; | ||
|
||
public class KnappingRecipe extends IForgeRegistryEntry.Impl<KnappingRecipe> | ||
{ | ||
private final int width; | ||
private final int height; | ||
private final boolean[] pattern; | ||
private final ItemStack output; | ||
|
||
public KnappingRecipe(ItemStack output, String... pattern) | ||
{ | ||
if (pattern.length == 0 || pattern.length > 5) | ||
throw new IllegalArgumentException("Pattern length is invalid"); | ||
|
||
this.width = pattern[0].length(); | ||
this.height = pattern.length; | ||
this.output = output; | ||
this.pattern = new boolean[width * height]; | ||
|
||
for (int i = 0; i < height; i++) | ||
{ | ||
String line = pattern[i]; | ||
if (line.length() != width) | ||
throw new IllegalArgumentException("Line " + i + " in the pattern has the incorrect length"); | ||
for (int c = 0; c < width; c++) | ||
this.pattern[i * height + c] = (line.charAt(c) == ' '); | ||
} | ||
} | ||
|
||
// This will check if it matches a 5x5 boolean matrix, from a GuiContainerKnapping | ||
public boolean matches(boolean[] matrix) | ||
{ | ||
// Check all possible shifted positions | ||
for (int xShift = 0; xShift <= 5 - width; xShift++) | ||
{ | ||
for (int yShift = 0; yShift <= 5 - height; yShift++) | ||
{ | ||
boolean flag = true; | ||
// check if the matrix matches this orientation | ||
for (int x = 0; x < width; x++) | ||
{ | ||
for (int y = 0; y < height; y++) | ||
{ | ||
// Check the individual position | ||
int matrixIdx = (yShift + y) * 5 + xShift + x; | ||
int patternIdx = (yShift + y) * width + xShift + x; | ||
if (matrix[matrixIdx] != pattern[patternIdx]) | ||
{ | ||
flag = false; | ||
break; | ||
} | ||
} | ||
} | ||
if (flag) | ||
return true; | ||
} | ||
} | ||
return false; | ||
} | ||
|
||
public ItemStack getOutput() | ||
{ | ||
return output.copy(); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
59 changes: 59 additions & 0 deletions
59
src/main/java/net/dries007/tfc/client/button/GuiButtonKnapping.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,59 @@ | ||
/* | ||
* Work under Copyright. Licensed under the EUPL. | ||
* See the project README.md and LICENSE.txt for more information. | ||
*/ | ||
|
||
package net.dries007.tfc.client.button; | ||
|
||
import javax.annotation.Nonnull; | ||
|
||
import net.minecraft.client.Minecraft; | ||
import net.minecraft.client.gui.GuiButton; | ||
import net.minecraft.client.renderer.GlStateManager; | ||
import net.minecraft.util.ResourceLocation; | ||
import net.minecraftforge.fml.relauncher.Side; | ||
import net.minecraftforge.fml.relauncher.SideOnly; | ||
|
||
import net.dries007.tfc.api.types.Rock; | ||
|
||
import static net.dries007.tfc.api.util.TFCConstants.MOD_ID; | ||
|
||
@SideOnly(Side.CLIENT) | ||
public class GuiButtonKnapping extends GuiButton | ||
{ | ||
private final ResourceLocation BG_TEXTURE; | ||
|
||
public GuiButtonKnapping(int id, int x, int y, int width, int height, Rock rockType) | ||
{ | ||
super(id, x, y, width, height, ""); | ||
|
||
BG_TEXTURE = new ResourceLocation(MOD_ID, "textures/blocks/stonetypes/raw/" + rockType.getRegistryName().getPath() + ".png"); | ||
} | ||
|
||
public void onClick() | ||
{ | ||
this.visible = false; | ||
} | ||
|
||
@Override | ||
public void drawButton(@Nonnull Minecraft mc, int mouseX, int mouseY, float partialTicks) | ||
{ | ||
if (this.visible) | ||
{ | ||
GlStateManager.color(1, 1, 1, 1); | ||
mc.getTextureManager().bindTexture(BG_TEXTURE); | ||
|
||
hovered = mouseX >= this.x && mouseY >= this.y && mouseX < this.x + this.width && mouseY < this.y + this.height; | ||
|
||
//int i = this.getHoverState(this.hovered); | ||
//GlStateManager.enableBlend(); | ||
//GlStateManager.tryBlendFuncSeparate(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA, GlStateManager.SourceFactor.ONE, GlStateManager.DestFactor.ZERO); | ||
//GlStateManager.blendFunc(GlStateManager.SourceFactor.SRC_ALPHA, GlStateManager.DestFactor.ONE_MINUS_SRC_ALPHA); | ||
|
||
drawTexturedModalRect(x, y, 0, 0, width, height); | ||
//drawTexturedModalRect(this.x, this.y, 0, 46 + i * 20, this.width / 2, this.height); | ||
//drawTexturedModalRect(this.x + this.width / 2, this.y, 200 - this.width / 2, 46 + i * 20, this.width / 2, this.height); | ||
mouseDragged(mc, mouseX, mouseY); | ||
} | ||
} | ||
} |
103 changes: 103 additions & 0 deletions
103
src/main/java/net/dries007/tfc/client/gui/GuiContainerKnapping.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
/* | ||
* Work under Copyright. Licensed under the EUPL. | ||
* See the project README.md and LICENSE.txt for more information. | ||
*/ | ||
|
||
package net.dries007.tfc.client.gui; | ||
|
||
import net.minecraft.client.gui.GuiButton; | ||
import net.minecraft.entity.player.EntityPlayer; | ||
import net.minecraft.inventory.Container; | ||
import net.minecraft.inventory.Slot; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.util.ResourceLocation; | ||
|
||
import net.dries007.tfc.TerraFirmaCraft; | ||
import net.dries007.tfc.api.types.Rock; | ||
import net.dries007.tfc.api.util.TFCConstants; | ||
import net.dries007.tfc.client.button.GuiButtonKnapping; | ||
import net.dries007.tfc.objects.items.ItemsTFC; | ||
import net.dries007.tfc.objects.items.rock.ItemRock; | ||
import net.dries007.tfc.util.Helpers; | ||
|
||
public class GuiContainerKnapping extends GuiContainerTFC | ||
{ | ||
private static final ResourceLocation BG_TEXTURE = new ResourceLocation(TFCConstants.MOD_ID, "textures/gui/knapping.png"); | ||
private final int slotIdx; | ||
private final Rock rock; | ||
|
||
private final boolean[] matrix; // true = clicked away | ||
private boolean hasBeenModified; | ||
|
||
public GuiContainerKnapping(Container container, EntityPlayer player) | ||
{ | ||
super(container, player.inventory, BG_TEXTURE, ""); | ||
ItemStack stack = player.getHeldItemMainhand(); | ||
if (stack.getItem() instanceof ItemRock) | ||
{ | ||
slotIdx = playerInv.currentItem; | ||
} | ||
else | ||
{ | ||
stack = player.getHeldItemOffhand(); | ||
slotIdx = 40; | ||
} | ||
rock = ((ItemRock) stack.getItem()).ore; | ||
matrix = new boolean[25]; | ||
hasBeenModified = false; | ||
|
||
ySize = 184; // Bigger than normal gui | ||
} | ||
|
||
@Override | ||
public void initGui() | ||
{ | ||
super.initGui(); | ||
for (int x = 0; x < 5; x++) | ||
{ | ||
for (int y = 0; y < 5; y++) | ||
{ | ||
int bx = (width - xSize) / 2 + 12 + 16 * x; | ||
int by = (height - ySize) / 2 + 12 + 16 * y; | ||
addButton(new GuiButtonKnapping(x + 5 * y, bx, by, 16, 16, rock)); | ||
} | ||
} | ||
} | ||
|
||
@Override | ||
protected void actionPerformed(GuiButton button) | ||
{ | ||
// do something with the buttons | ||
// todo: this needs to all happen on serverside: look up AbstractPacker or some gib | ||
TerraFirmaCraft.getLog().debug("Pressed button of id: {}", button.id); | ||
if (button instanceof GuiButtonKnapping) | ||
{ | ||
((GuiButtonKnapping) button).onClick(); | ||
matrix[button.id] = true; | ||
|
||
if (!hasBeenModified) | ||
{ | ||
ItemStack stack = playerInv.getStackInSlot(slotIdx); | ||
playerInv.setInventorySlotContents(slotIdx, Helpers.consumeItem(stack, 1)); | ||
hasBeenModified = true; | ||
} | ||
|
||
// check the pattern | ||
Slot slot = inventorySlots.getSlot(0); | ||
if (matches()) | ||
{ | ||
slot.putStack(new ItemStack(ItemsTFC.GOLDPAN)); // todo: make based on recipe | ||
} | ||
else | ||
{ | ||
slot.putStack(ItemStack.EMPTY); | ||
} | ||
} | ||
} | ||
|
||
private boolean matches() | ||
{ | ||
// todo: replace with an actual recipe type deal | ||
return matrix[0] && !matrix[1]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
src/main/java/net/dries007/tfc/objects/container/ContainerKnapping.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
/* | ||
* Work under Copyright. Licensed under the EUPL. | ||
* See the project README.md and LICENSE.txt for more information. | ||
*/ | ||
|
||
package net.dries007.tfc.objects.container; | ||
|
||
import net.minecraft.entity.player.InventoryPlayer; | ||
import net.minecraft.inventory.Slot; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraftforge.items.CapabilityItemHandler; | ||
import net.minecraftforge.items.IItemHandler; | ||
|
||
import net.dries007.tfc.objects.inventory.SlotOutput; | ||
|
||
public class ContainerKnapping extends ContainerItemStack | ||
{ | ||
public ContainerKnapping(InventoryPlayer playerInv, ItemStack stack) | ||
{ | ||
super(playerInv, stack); | ||
this.itemIndex += 1; | ||
} | ||
|
||
@Override | ||
protected void addContainerSlots() | ||
{ | ||
// todo: this needs to not come from an item capability; the item in question doesn't have that capability | ||
IItemHandler inventory = stack.getCapability(CapabilityItemHandler.ITEM_HANDLER_CAPABILITY, null); | ||
if (inventory != null) | ||
{ | ||
addSlotToContainer(new SlotOutput(inventory, 0, 128, 44)); | ||
} | ||
} | ||
|
||
@Override | ||
protected void addPlayerInventorySlots(InventoryPlayer playerInv) | ||
{ | ||
// Add Player Inventory Slots (lower down) | ||
for (int i = 0; i < 3; i++) | ||
{ | ||
for (int j = 0; j < 9; j++) | ||
{ | ||
addSlotToContainer(new Slot(playerInv, j + i * 9 + 9, 8 + j * 18, 84 + i * 18 + 18)); | ||
} | ||
} | ||
|
||
for (int k = 0; k < 9; k++) | ||
{ | ||
addSlotToContainer(new Slot(playerInv, k, 8 + k * 18, 142 + 18)); | ||
} | ||
} | ||
} |
Oops, something went wrong.