[1.7.2] Using recursion to find block in a cable system.

Recommended Posts

Hey guys, I am trying to find a block in a system of cables, the idea is simple:

Block 1 says "I need BlockLOL.class", Wire 1 says "I dont have it? Do you wire 2?", Wire 2 says "Its next to me! here!", and it goes back down the line. However right now I cant even get the nearby blocks, and when I was able to somehow, it wouldnt detect any cables and would stop. Heres my code:

General wire, BlockWire

package com.revereor.blocks;

import java.util.ArrayList;

import net.minecraft.block.Block;
import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;

import com.revereor.blocks.util.BlockHelper;
import com.revereor.tileentity.TileEntityWire;

public class BlockWire extends BlockContainer{

protected TileEntityWire tileEntity;

public BlockWire() {
super(Material.cloth);
this.setStepSound(soundTypeCloth);
this.setHardness(0.1F);
}

public BlockWire(Material material) {
super(material);
}

public BlockGeneral getBlockFromSystem(Class type, BlockWire last){
Block[] nearby = BlockHelper.getDirectNearbyBlocks(tileEntity);
for(Block bl : nearby){
if(type.isInstance(bl))
return (BlockGeneral) bl;
if(type.isInstance(this))
return (BlockGeneral) this;
ArrayList<BlockWire> nearbyWires = getNearbyWires();
for(BlockWire wire : nearbyWires){
BlockGeneral bg = wire.getBlockFromSystem(type, this);
if(bg != null)
return bg;
}
}
return null;
}

public ArrayList<BlockWire> getNearbyWires(){
ArrayList<BlockWire> wires = new ArrayList<BlockWire>();
Block[] nearby = BlockHelper.getDirectNearbyBlocks(tileEntity);
for(Block bl : nearby){
if(!Block.isEqualTo(bl, this)){
if(bl instanceof BlockWire){
}
}
}
return wires;
}

public void onBlockAdded(World world,int x, int y, int z){
tileEntity.x=x;
tileEntity.y=y;
tileEntity.z=z;
}

@Override
public TileEntity createNewTileEntity(World var1, int var2) {
tileEntity = new TileEntityWire();
return tileEntity;
}

}

BlockRemoteControlCenter, block thats trying to get control center.

package com.revereor.blocks;

import com.revereor.tileentity.TileEntityWire;

import net.minecraft.block.material.Material;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.world.World;

public class BlockRemoteControlCenter extends BlockGeneral {

public BlockRemoteControlCenter() {
super(Material.iron);
this.setStepSound(soundTypeMetal);
}

public boolean onBlockActivated(World par1World, int par2, int par3, int par4, EntityPlayer par5EntityPlayer, int par6, float par7, float par8, float par9)
{
BlockControlCenter con = this.getControlCenter();
if(con != null){
System.out.println(con);
} else System.out.println("no control center found");
return false;
}

@Override
public TileEntityWire setTileEntity() {
return new TileEntityWire();
}

}

Block Control center, The block we need.

package com.revereor.blocks;

import com.revereor.tileentity.TileEntityWire;

import net.minecraft.block.material.Material;

public class BlockControlCenter extends BlockGeneral{

public BlockControlCenter() {
super(Material.iron);
this.setStepSound(soundTypeMetal);
}

@Override
public TileEntityWire setTileEntity() {
return new TileEntityWire();
}

}

BlockGeneral, the abstract base of functional blocks, but not wires.

package com.revereor.blocks;

import java.util.ArrayList;

import net.minecraft.block.Block;
import net.minecraft.block.material.Material;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.world.World;

import com.revereor.blocks.util.BlockHelper;
import com.revereor.tileentity.TileEntityWire;

public abstract class BlockGeneral extends BlockWire{

protected BlockGeneral(Material p_i45394_1_) {
super(p_i45394_1_);
}

public BlockGeneral getBlock(Class type){
ArrayList<BlockWire> wires = getNearbyWires();
for(BlockWire wire : wires){
BlockGeneral bl = wire.getBlockFromSystem(type,this);
if(bl != null){
return bl;
}
}
return null;

}

public BlockControlCenter getControlCenter(){
return (BlockControlCenter) getBlock(BlockControlCenter.class);
}

public abstract TileEntityWire setTileEntity();

@Override
public TileEntity createNewTileEntity(World var1, int var2) {
tileEntity = setTileEntity();
return tileEntity;
}
}

BlockHelper, used to get blocks

package com.revereor.blocks.util;

import net.minecraft.block.Block;
import net.minecraft.tileentity.TileEntity;

import com.revereor.main.Main;

public class BlockHelper {

public static boolean isDirect(int x, int tx, int y, int ty, int z, int tz){
return     ((x == tx+1 || x == tx-1) && !(y == ty+1 || y == ty-1) && !(z == tz+1 || z == tz-1))
|| (!(x == tx+1 || x == tx-1) && (y == ty+1 || y == ty-1) && !(z == tz+1 || z == tz-1))
|| (!(x == tx+1 || x == tx-1) && !(y == ty+1 || y == ty-1) && (z == tz+1 || z == tz-1));
}

public static boolean isIndirect(int x, int tx, int y, int ty, int z, int tz){
return !isDirect(x, tx, y, ty, z, tz);
}

public static Block[] getDirectNearbyBlocks(TileEntity tileEntity){
Block[] blks = new Block[6];
for(int x = tileEntity.xCoord-1; x < tileEntity.xCoord+1; x++){
for(int y = tileEntity.yCoord-1; y < tileEntity.yCoord+1; y++){
for(int z = tileEntity.zCoord-1; z < tileEntity.zCoord+1; z++){
if(isDirect(x, tileEntity.xCoord, y, tileEntity.yCoord, z, tileEntity.zCoord)){
for(int i = 0; i < blks.length; i++){
if(blks[i] == null){
blks[i] = tileEntity.getWorldObj().getBlock(x, y, z);
} else if(i == blks.length){
Main.print("Exceeded maximum blocks while getting nearby blocks.");
}
}
}
}
}
}
return blks;
}

}

Open to any other ideas to get this!

Share on other sites

One of your main problems is the field tileEntity declared in your BlockWire class. You cannot do that as every wire in the game will share the same tileEntity. That's not what you want and it will cause crashes.

-S- (if I helped, please click Thank and applaud)

Share on other sites

One of your main problems is the field tileEntity declared in your BlockWire class. You cannot do that as every wire in the game will share the same tileEntity. That's not what you want and it will cause crashes.

How should I go about this then? Previously it worked for me when I used onBlockAdded and saved x y and z but, yes, as your implying it all went down hill with the Tile Entity. How should I go about finding the x, y, and z correctly?

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.

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

×   Pasted as rich text.   Restore formatting

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

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

• Posts

• DAFTAR SLOT GACOR DISINI DAFTAR SLOT GACOR DISINI DAFTAR SLOT GACOR DISINI Slot pulsa telkomsel & xl link gacor slot deposit pulsa 10k tanpa potongan gampang menang maxwin. Situs slot deposit pulsa memberikan kenyamanan bagi semua pemain slot online dan mampu memberikan maksimal taruhan judi online khususnya permainan slot online gacor. TAG : Slot Pulsa Telkomsel Slot Pulsa Telkomsel Slot Pulsa Telkomsel Slot Pulsa Telkomsel Slot Pulsa Slot Pulsa Slot Pulsa Slot Pulsa
• DAFTAR DI >>SINI<< DAFTAR DI >>SINI<< DAFTAR DI >>SINI<<  adalah salah satu pelopor situs slot gacor hari ini yang paling banyak dikunjungi pecandu slot online paling gacor. Terpercaya bisa memberikan keuntungan besar dengan permainan slot gacor gampang menang maxwin menjadi yang terbaik ditahun 2024.
• I cannot express my gratitude enough for the exceptional service provided by the Legendary Fastfund Recovery. I was a victim of an online romance scam, losing a huge amount of my hard-earned money \$258k worth of Bitcoin, this made me devastated. However, this team of reliable funds recovery experts swiftly came to my aid, demonstrating their expertise in crypto recovery. Within a surprisingly short time frame, they successfully retrieved my lost funds. Their commitment to client satisfaction and relentless efforts truly saved me from financial ruin. I highly recommend them to anyone in a similar predicament. Their outstanding service and ability to recover substantial amounts of cryptocurrency are unmatched. Contact information below. Email – Fastfundrecovery8 (AT) Gmail dot com What's App – 19037176241 Telegram -- (AT)fastfundsrecovery
• Hello, today I wanted to upload a datapack to the server for new biomes, but it worked incorrectly in the world, so I decided to delete it, but after restarting the server gives the error "Failed to load datapacks, can't proceed with server load. You can either fix your datapacks or reset to vanilla with --safeMode". Help me, I need to restore this world, it is very important both for me and for a lot of my friends.
• DAFTAR SCATTER HITAM MAXWIN DISINI DAFTAR SCATTER HITAM MAXWIN DISINI DAFTAR SCATTER HITAM MAXWIN DISINI Jangan ragu untuk download apk cheat slot hacker Scatter Hitam Maxwin Mahjong Ways Bonus 5 Juta super gacor gampang maxwin, link apk tersebut sudah di stel untuk membobol game slot online agar mendapatkan kemenangan jackpot maxwin perkalian x500. TAG : Cheat Slot Cheat Slot Cheat Slot Cheat Slot Cheat Slot Cheat Slot Cheat Slot Cheat Slot

• Who's Online (See full list)

×

• Activity

×
• Create New...