Jump to content

Recommended Posts

Posted

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){
				wires.add((BlockWire)bl);
			}
		}			
	}
	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!

Posted

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.

Posted
  On 5/23/2014 at 5:24 AM, sequituri said:

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.

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

    • Add the crash-report or latest.log (logs-folder) with sites like https://mclo.gs/ and paste the link to it here  
    • I removed yetanotherchance booster and now it says Invalid player identity
    • Cracked Launchers are not supported
    • After some time minecraft crashes with an error. Here is the log https://drive.google.com/file/d/1o-2R6KZaC8sxjtLaw5qj0A-GkG_SuoB5/view?usp=sharing
    • The specific issue is that items in my inventory wont stack properly. For instance, if I punch a tree down to collect wood, the first block I collected goes to my hand. So when I punch the second block of wood to collect it, it drops, but instead of stacking with the piece of wood already in my hand, it goes to the second slot in my hotbar instead. Another example is that I'll get some dirt, and then when I'm placing it down later I'll accidentally place a block where I don't want it. When I harvest it again, it doesn't go back to the stack that it came from on my hotbar, where it should have gone, but rather into my inventory. That means that if my inventory is full, then the dirt wont be picked up even though there should be space available in the stack I'm holding. The forge version I'm using is 40.3.0, for java 1.18.2. I'll leave the mods I'm using here, and I'd appreciate it if anybody can point me in the right direction in regards to figuring out how to fix this. I forgot to mention that I think it only happens on my server but I&#39;m not entirely sure. PLEASE HELP ME! LIST OF THE MODS. aaa_particles Adorn AdvancementPlaques AI-Improvements AkashicTome alexsdelight alexsmobs AmbientSounds amwplushies Animalistic another_furniture AppleSkin Aquaculture aquamirae architectury artifacts Atlas-Lib AutoLeveling AutoRegLib auudio balm betterfpsdist biggerstacks biomancy BiomesOPlenty blockui blueprint Bookshelf born_in_chaos Botania braincell BrassAmberBattleTowers brutalbosses camera CasinoCraft cfm (MrCrayfish’s Furniture Mod) chat_heads citadel cloth-config Clumps CMDCam CNB cobweb collective comforts convenientcurioscontainer cookingforblockheads coroutil CosmeticArmorReworked CozyHome CrabbersDelight crashexploitfixer crashutilities Create CreativeCore creeperoverhaul cristellib crittersandcompanions Croptopia CroptopiaAdditions CullLessLeaves curios curiouslanterns curiouslights Curses' Naturals CustomNPCs CyclopsCore dannys_expansion decocraft Decoration Mod DecorationDelightRefurbished Decorative Blocks Disenchanting DistantHorizons doubledoors DramaticDoors drippyloadingscreen durabilitytooltip dynamic-fps dynamiclights DynamicTrees DynamicTreesBOP DynamicTreesPlus Easy Dungeons EasyAnvils EasyMagic easy_npc eatinganimation ecologics effective_fg elevatorid embeddium emotecraft enchantlimiter EnchantmentDescriptions EnderMail engineersdecor entityculling entity_model_features entity_texture_features epicfight EvilCraft exlinefurniture expandability explosiveenhancement factory-blocks fairylights fancymenu FancyVideo FarmersDelight fast-ip-ping FastSuite ferritecore finsandtails FixMySpawnR Forge Middle Ages fossil FpsReducer2 furnish GamingDeco geckolib goblintraders goldenfood goodall H.e.b habitat harvest-with-ease hexerei hole_filler huge-structure-blocks HunterIllager iammusicplayer Iceberg illuminations immersive_paintings incubation infinitybuttons inventoryhud InventoryProfilesNext invocore ItemBorders itemzoom Jade jei (Just Enough Items) JetAndEliasArmors journeymap JRFTL justzoom kiwiboi Kobolds konkrete kotlinforforge lazydfu LegendaryTooltips libIPN lightspeed lmft lodestone LongNbtKiller LuckPerms Lucky77 MagmaMonsters malum ManyIdeasCore ManyIdeasDoors marbledsarsenal marg mcw-furniture mcw-lights mcw-paths mcw-stairs mcw-trapdoors mcw-windows meetyourfight melody memoryleakfix Mimic minecraft-comes-alive MineTraps minibosses MmmMmmMmmMmm MOAdecor (ART, BATH, COOKERY, GARDEN, HOLIDAYS, LIGHTS, SCIENCE) MobCatcher modonomicon mods_optimizer morehitboxes mowziesmobs MutantMonsters mysticalworld naturalist NaturesAura neapolitan NekosEnchantedBooks neoncraft2 nerb nifty NightConfigFixes nightlights nocube's_villagers_sell_animals NoSeeNoTick notenoughanimations obscure_api oculus oresabovediamonds otyacraftengine Paraglider Patchouli physics-mod Pillagers Gun PizzaCraft placeableitems Placebo player-animation-lib pneumaticcraft-repressurized polymorph PrettyPipes Prism projectbrazier Psychadelic-Chemistry PuzzlesLib realmrpg_imps_and_demons RecipesLibrary reeves-furniture RegionsUnexplored restrictedportals revive-me Scary_Mobs_And_Bosses selene shetiphiancore ShoulderSurfing smoothboot
  • Topics

×
×
  • Create New...

Important Information

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