Jump to content

[1.7.10] [Resolved] How to check Item in Slot - TileEntity Interface


Recommended Posts

  • 3 months later...
Posted

Hi, sorry for the delay, I've been searching for a way to do this, I think I found it:

public void updateEntity(){
          if(ItemStack.areItemStacksEqual(new ItemStack(Item.Cobblestone), slots))
          {
              power += 10;
          }
          else
          {

          }
}

I need to check the Item in slot, here is my ItemStack variable that stores the content:

private ItemStack[] slots = new ItemStack[2];

but It says that I am using a wrong type of ItemStack in the 2Nd variable of the Content, here is all my TileEntity Code:

package com.gpa.startrekmod.tileentities;

import java.util.List;

import com.gpa.startrekmod.blocks.STModBlocks;
import com.gpa.startrekmod.items.STModItems;

import cpw.mods.fml.relauncher.Side;
import cpw.mods.fml.relauncher.SideOnly;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.ISidedInventory;
import net.minecraft.inventory.Slot;
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.nbt.NBTTagList;
import net.minecraft.network.Packet;
import net.minecraft.network.play.server.S35PacketUpdateTileEntity;
import net.minecraft.tileentity.TileEntity;

public class TileEntityReplicatorBlock extends TileEntity implements ISidedInventory {
private ItemStack[] slots = new ItemStack[2];
private final String IventoryName = "Replicator";
private int facingDirection;
public int maxPower = 100000;
public float power;
public void updateEntity(){
if(ItemStack.areItemStacksEqual(new ItemStack(STModItems.EnergyCell), slots))
{
	power += 10;
}
else
{

}
if(power > maxPower) power = maxPower;
}
public int getPowerScaled(int scaled)
{
	return (int) (this.power * scaled / this.maxPower);
}
@Override
public void readFromNBT(NBTTagCompound nbt){
	super.readFromNBT(nbt);

	facingDirection = nbt.getInteger("facingDirection");
	NBTTagList list = nbt.getTagList("Slots", 10);
	this.slots = new ItemStack[getSizeInventory()];

	for(int i = 0; i < list.tagCount(); i++){
		NBTTagCompound  item = list.getCompoundTagAt(i);
		byte b = item.getByte("Item");

		if(b >= 0 && b < this.slots.length){
			this.slots[b] = ItemStack.loadItemStackFromNBT(item);
		}
	}

	this.power = nbt.getInteger("REPPower");

	if(nbt.hasKey("CustomName")){
		this.setInventoryName(nbt.getString("CustomName"));
	}
}
@Override
public void writeToNBT(NBTTagCompound nbt){
	super.writeToNBT(nbt);

	nbt.setFloat("REPPower", this.power);
	nbt.setInteger("facingDirection", facingDirection);
	NBTTagList list = new NBTTagList();

	for(int i = 0; i < this.slots.length; i++)
	{
		if(this.slots[i] != null){
			NBTTagCompound item = new NBTTagCompound();
			item.setByte("item", (byte)i);
			this.slots[i].writeToNBT(item);
			list.appendTag(item);
		}
	}
	nbt.setTag("Slots", list);

	if(this.hasCustomInventoryName()){
		nbt.setString("CustomName", this.getInventoryName());
	}
}

public int getSizeInventory() {
	return this.slots.length;
}
public ItemStack getStackInSlot(int i) {
	return this.slots[i];
}
public ItemStack decrStackSize(int i, int j) {
	if(this.slots[i] != null)
	{
		ItemStack itemstack;
		if(this.slots[i].stackSize <= j)
		{
			itemstack = this.slots[i];
			this.slots[i] = null;
			return itemstack;
		}else{
			itemstack = this.slots[i].splitStack(j);
			if(this.slots[i].stackSize == 0)
			{
				this.slots[i] = null;
			}
			return itemstack;
		}
	}
	return null;
}
public ItemStack getStackInSlotOnClosing(int i) {
	if(this.slots[i] != null)
	{
		ItemStack itemstack = this.slots[i];
		this.slots[i] = null;
		return itemstack;
	}
	return null;
}
public void setInventorySlotContents(int i, ItemStack itemstack) {
	this.slots[i] = itemstack;

	if(itemstack != null && itemstack.stackSize > this.getInventoryStackLimit()){
		itemstack.stackSize = this.getInventoryStackLimit();
	}
}
public String getInventoryName() {
	return null;
}
public void setInventoryName() {

}
public boolean hasCustomInventoryName() {
	return false;
}
public int getInventoryStackLimit() {
	return 64;
}
public void setInventoryName(String string){

}
public boolean isUseableByPlayer(EntityPlayer p_70300_1_) {
	return false;
}
public void openInventory() {
}
public void closeInventory() {
}
public boolean isItemValidForSlot(int p_94041_1_, ItemStack p_94041_2_) {
	return false;
}
public int[] getAccessibleSlotsFromSide(int p_94128_1_) {
	return null;
}
public boolean canInsertItem(int p_102007_1_, ItemStack p_102007_2_,
		int p_102007_3_) {
	return false;
}
public boolean canExtractItem(int p_102008_1_, ItemStack p_102008_2_,
		int p_102008_3_) {
	return false;
}
@Override
public Packet getDescriptionPacket() {
NBTTagCompound tag = new NBTTagCompound();
this.writeToNBT(tag);
return new S35PacketUpdateTileEntity(xCoord, yCoord, zCoord, 1, tag);
}
}

For some reason the spoiler tab is not working.

 

Thanks.

Posted

I used slots with the ID of the slot after it:

slots[1]

I got no error, but I am getting a minecraft crash Report, It's about the ticking:

 

 

---- Minecraft Crash Report ----

// You should try our sister game, Minceraft!

 

Time: 13/02/15 19:10

Description: Ticking block entity

 

java.lang.ArrayIndexOutOfBoundsException: 3

at com.gpa.startrekmod.tileentities.TileEntityReplicatorBlock.updateEntity(TileEntityReplicatorBlock.java:28)

at net.minecraft.world.World.updateEntities(World.java:2160)

at net.minecraft.world.WorldServer.updateEntities(WorldServer.java:515)

at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:703)

at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:614)

at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:118)

at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:485)

at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:752)

 

 

A detailed walkthrough of the error, its code path and all known details is as follows:

---------------------------------------------------------------------------------------

 

-- Head --

Stacktrace:

at com.gpa.startrekmod.tileentities.TileEntityReplicatorBlock.updateEntity(TileEntityReplicatorBlock.java:28)

 

-- Block entity being ticked --

Details:

Name: TileEntityReplicatorBlock // com.gpa.startrekmod.tileentities.TileEntityReplicatorBlock

Block type: ID #165 (tile.Replicator // com.gpa.startrekmod.blocks.STReplicator)

Block data value: 0 / 0x0 / 0b0000

Block location: World: (-30,70,276), Chunk: (at 2,4,4 in -2,17; contains blocks -32,0,272 to -17,255,287), Region: (-1,0; contains chunks -32,0 to -1,31, blocks -512,0,0 to -1,255,511)

Actual block type: ID #165 (tile.Replicator // com.gpa.startrekmod.blocks.STReplicator)

Actual block data value: 0 / 0x0 / 0b0000

Stacktrace:

at net.minecraft.world.World.updateEntities(World.java:2160)

at net.minecraft.world.WorldServer.updateEntities(WorldServer.java:515)

 

-- Affected level --

Details:

Level name: ST

All players: 0 total; []

Chunk stats: ServerChunkCache: 625 Drop: 0

Level seed: -4128128808810088779

Level generator: ID 00 - default, ver 1. Features enabled: true

Level generator options:

Level spawn location: World: (-32,64,251), Chunk: (at 0,4,11 in -2,15; contains blocks -32,0,240 to -17,255,255), Region: (-1,0; contains chunks -32,0 to -1,31, blocks -512,0,0 to -1,255,511)

Level time: 28892 game time, 717 day time

Level dimension: 0

Level storage version: 0x04ABD - Anvil

Level weather: Rain time: 11822 (now: false), thunder time: 37238 (now: false)

Level game mode: Game mode: creative (ID 1). Hardcore: false. Cheats: true

Stacktrace:

at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(MinecraftServer.java:703)

at net.minecraft.server.MinecraftServer.tick(MinecraftServer.java:614)

at net.minecraft.server.integrated.IntegratedServer.tick(IntegratedServer.java:118)

at net.minecraft.server.MinecraftServer.run(MinecraftServer.java:485)

at net.minecraft.server.MinecraftServer$2.run(MinecraftServer.java:752)

 

-- System Details --

Details:

Minecraft Version: 1.7.10

Operating System: Windows 8.1 (amd64) version 6.3

Java Version: 1.8.0_11, Oracle Corporation

Java VM Version: Java HotSpot 64-Bit Server VM (mixed mode), Oracle Corporation

Memory: 738745824 bytes (704 MB) / 1037959168 bytes (989 MB) up to 1037959168 bytes (989 MB)

JVM Flags: 3 total; -Xincgc -Xmx1024M -Xms1024M

AABB Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used

IntCache: cache: 0, tcache: 0, allocated: 12, tallocated: 94

FML: MCP v9.05 FML v7.10.85.1291 Minecraft Forge 10.13.2.1291 4 mods loaded, 4 mods active

mcp{9.05} [Minecraft Coder Pack] (minecraft.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available

FML{7.10.85.1291} [Forge Mod Loader] (forgeSrc-1.7.10-10.13.2.1291.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available

Forge{10.13.2.1291} [Minecraft Forge] (forgeSrc-1.7.10-10.13.2.1291.jar) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available

gpa_startrekmod{0.1.2} [star Trek Mod] (bin) Unloaded->Constructed->Pre-initialized->Initialized->Post-initialized->Available->Available->Available->Available

Profiler Position: N/A (disabled)

Vec3 Pool Size: 0 (0 bytes; 0 MB) allocated, 0 (0 bytes; 0 MB) used

Player Count: 0 / 8; []

Type: Integrated Server (map_client.txt)

Is Modded: Definitely; Client brand changed to 'fml,forge')

 

 

Thanks!

Posted

I've tried accessing these arrays: 1 and 2.

It is still now working.

private ItemStack[] slots = new ItemStack[2];

2 elements, meaning indices 0 and 1.

Don't PM me with questions. They will be ignored! Make a thread on the appropriate board for support.

 

1.12 -> 1.13 primer by williewillus.

 

1.7.10 and older versions of Minecraft are no longer supported due to it's age! Update to the latest version for support.

 

http://www.howoldisminecraft1710.today/

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Unfortunately, your content contains terms that we do not allow. Please edit your content to remove the highlighted words below.
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Announcements



  • Recently Browsing

    • No registered users viewing this page.
  • Posts

    • Reach Out To Rapid Digital: What sapp Info: +1 41 4 80 7 14 85 Email INFO: rap iddi gita lrecov ery @ exe cs. com Hello, my name is Jayson, and I’m 35 years old from the United Kingdom. My family and I recently endured an incredibly challenging experience that I wouldn’t wish on anyone. We became victims of a cryptocurrency investment fraud scheme that saw us lose a staggering $807,000 in USDT and Bitcoins. The fraudsters had created a convincing facade, and we were lured into investing, only to discover later that the platform was a complete scam. We were left devastated, not just financially, but emotionally, as we had trusted these people and believed in the legitimacy of the investment. After the initial shock wore off, we desperately searched for ways to recover the lost funds. It seemed like an impossible task, and we felt as though there was no hope. That’s when, by sheer luck, we stumbled across a post about Rapid Digital Recovery, a cryptocurrency and funds recovery organization with a proven track record in cybersecurity and fraud recovery. We decided to reach out to them, and from the first interaction, we were impressed with their professionalism and transparency. They explained the recovery process in detail and reassured us that they had the skills and expertise to track down the perpetrators and recover our funds. This gave us a renewed sense of hope, something we hadn’t felt in months. What truly stood out during our experience with Rapid Digital Recovery was their dedication to the recovery process. The team went above and beyond, using sophisticated tracking tools and cyber forensics to gather critical information. Within a matter of weeks, they had successfully located the funds and traced the scam back to the fraudsters responsible. They worked with the authorities to ensure the criminals were held accountable for their actions. To our relief, the team at Rapid Digital Recovery was able to recover every single penny we had lost. The funds were returned in full, and the sense of closure we felt was invaluable. We couldn’t have imagined such a positive outcome in the early stages of our recovery journey, and we are deeply grateful for the work they did. If you ever find yourself in a similar situation, I highly recommend contacting Rapid Digital Recovery. Their expertise, transparency, and dedication to their clients make them the go-to choice for anyone seeking to recover lost cryptocurrency or funds. They truly gave us back our financial future.  
    • This is my first time modding anything, so maybe just skill issue. I'm using Forge 54.0.12 and Temurin 21.0.5+11-LTS I wanted to create a custom keybind and to check whether it works I'd like to send a chat message. I tried using Minecraft.getInstance().player.sendSystemMessage(Component.literal("test")); but IntelliJ couldnt resolve sendSystemMessage(...). Since I saw people using it in earlier versions, I tried the same thing with 1.20.6(- 50.1.0), where it works fine, now I can't figure out if this is intentional and whether there are other options for sending chat messages. On that note, is there more documentation than https://docs.minecraftforge.net/en/1.21.x/? It seems very incomplete compared to something like the Oracle Java docs
    • Hi, i'm having this error and I wanna fix it. we try: -Reload drivers -Eliminate .minecraft -Eliminate Java -Restart launcher -Verify if minecraft is using gpu -Mods  in .minecraft is empty -Install the latest and recomended version of forge idk what i have to do, help me pls. the lastest log is: https://mclo.gs/WAMao8x  
    • Read the FAQ, Rule #2. (https://forums.minecraftforge.net/topic/125488-rules-and-frequently-asked-questions-faq/)  
  • Topics

×
×
  • Create New...

Important Information

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