I'm trying to replace a block when it's right-clicked with a certain item and arranged in a certain structure. Multiple structures are possible, resulting in different block replacements. I'm doing this by setting a variable depending on the structure built around the block. The variable is then passed to the "assemble" method, which contains a switch for the variable. The variable is a string called "setup". I also print "setup" to the log, which always returns the correct result for the structure. However, the block always changes into the block for the structure "Generator".
/**
* Called upon block activation (right click on the block.)
*/
public boolean onBlockActivated(World p_149727_1_, int p_149727_2_, int p_149727_3_, int p_149727_4_, EntityPlayer p_149727_5_, int p_149727_6_, float p_149727_7_, float p_149727_8_, float p_149727_9_)
{
SCExtendedPlayer props = SCExtendedPlayer.get(p_149727_5_);
String setup = "Machine";//The default setup value
//Charger Setup - The comparation blocks
if ((p_149727_1_.getBlock(p_149727_2_ + 1, p_149727_3_, p_149727_4_ + 1) == SCBlocks.CompositeVintryteBlock) && (p_149727_1_.getBlock(p_149727_2_ + 1, p_149727_3_, p_149727_4_) == SCBlocks.VintryteBlock) && (p_149727_1_.getBlock(p_149727_2_ - 1, p_149727_3_, p_149727_4_ + 1) == SCBlocks.CompositeVintryteBlock) && (p_149727_1_.getBlock(p_149727_2_ - 1, p_149727_3_, p_149727_4_) == SCBlocks.VintryteBlock) && (p_149727_1_.getBlock(p_149727_2_, p_149727_3_, p_149727_4_ + 1) == SCBlocks.VintryteBlock) && (p_149727_1_.getBlock(p_149727_2_ - 1, p_149727_3_, p_149727_4_ - 1) == SCBlocks.CompositeVintryteBlock) && (p_149727_1_.getBlock(p_149727_2_, p_149727_3_, p_149727_4_ - 1) == SCBlocks.VintryteBlock) && (p_149727_1_.getBlock(p_149727_2_ + 1, p_149727_3_, p_149727_4_ - 1) == SCBlocks.CompositeVintryteBlock)){
setup = "Charger";
}
//Generator Setup
if ((p_149727_1_.getBlock(p_149727_2_ + 1, p_149727_3_ - 1, p_149727_4_ + 1) == SCBlocks.CompositeVintryteBlock) && (p_149727_1_.getBlock(p_149727_2_ + 1, p_149727_3_ - 1, p_149727_4_) == SCBlocks.VintryteBlock) && (p_149727_1_.getBlock(p_149727_2_, p_149727_3_ - 1, p_149727_4_ + 1) == Blocks.air) && (p_149727_1_.getBlock(p_149727_2_, p_149727_3_ - 1, p_149727_4_ - 1) == Blocks.air) && (p_149727_1_.getBlock(p_149727_2_ - 1, p_149727_3_ - 1, p_149727_4_ + 1) == SCBlocks.CompositeVintryteBlock) && (p_149727_1_.getBlock(p_149727_2_ - 1, p_149727_3_ - 1, p_149727_4_) == SCBlocks.VintryteBlock) && (p_149727_1_.getBlock(p_149727_2_, p_149727_3_ - 1, p_149727_4_) == SCBlocks.VintryteGenerator) && (p_149727_1_.getBlock(p_149727_2_ - 1, p_149727_3_ - 1, p_149727_4_ - 1) == SCBlocks.CompositeVintryteBlock) && (p_149727_1_.getBlock(p_149727_2_ + 1, p_149727_3_ - 1, p_149727_4_ - 1) == SCBlocks.CompositeVintryteBlock)){
setup = "Generator";
}
//Generator Setup
if ((p_149727_1_.getBlock(p_149727_2_ + 1, p_149727_3_ - 1, p_149727_4_ + 1) == SCBlocks.CompositeVintryteBlock) && (p_149727_1_.getBlock(p_149727_2_ + 1, p_149727_3_ - 1, p_149727_4_) == Blocks.air) && (p_149727_1_.getBlock(p_149727_2_, p_149727_3_ - 1, p_149727_4_ + 1) == SCBlocks.VintryteBlock) && (p_149727_1_.getBlock(p_149727_2_, p_149727_3_ - 1, p_149727_4_ - 1) == SCBlocks.VintryteBlock) && (p_149727_1_.getBlock(p_149727_2_ - 1, p_149727_3_ - 1, p_149727_4_ + 1) == SCBlocks.CompositeVintryteBlock) && (p_149727_1_.getBlock(p_149727_2_ - 1, p_149727_3_ - 1, p_149727_4_) == Blocks.air) && (p_149727_1_.getBlock(p_149727_2_, p_149727_3_ - 1, p_149727_4_) == SCBlocks.VintryteGenerator) && (p_149727_1_.getBlock(p_149727_2_ - 1, p_149727_3_ - 1, p_149727_4_ - 1) == SCBlocks.CompositeVintryteBlock) && (p_149727_1_.getBlock(p_149727_2_ + 1, p_149727_3_ - 1, p_149727_4_ - 1) == SCBlocks.CompositeVintryteBlock)){
setup = "Generator";
}
//Coil Setup
if ((p_149727_1_.getBlock(p_149727_2_, p_149727_3_ - 1, p_149727_4_) == SCBlocks.VintryteCoil) && (p_149727_1_.getBlock(p_149727_2_, p_149727_3_ - 2, p_149727_4_) == SCBlocks.VintryteCoil) && (p_149727_1_.getBlock(p_149727_2_, p_149727_3_ - 3, p_149727_4_) == SCBlocks.VintryteCoil)){
setup = "Coil";
}
if (setup.equals("Machine")){
p_149727_1_.setBlock(p_149727_2_, p_149727_3_, p_149727_4_, SCBlocks.VintryteMachine);
}
ModMainClass.log.info(setup);//Logging "setup"
if (p_149727_5_.inventory.getCurrentItem() != null)//Checking for the correct item, after checking if the player is holding an item
{
Item item = p_149727_5_.inventory.getCurrentItem().getItem();
if(item == SCItems.VintryteControllerT1){
if(((ItemVintryteControllerT1) item).mode == "Assemble")//Checking the item mode
{
assemble(p_149727_1_, p_149727_2_, p_149727_3_, p_149727_4_, p_149727_5_, setup);//Calling "assemble", passing the world, the coordinates, the player and the setup
}
}
if(item == SCItems.VintryteControllerT2){
if(((ItemVintryteControllerT2) item).mode == "Assemble")
{
assemble(p_149727_1_, p_149727_2_, p_149727_3_, p_149727_4_, p_149727_5_, setup);
}
}
if(item == SCItems.VintryteControllerT3){
if(((ItemVintryteControllerT3) item).mode == "Assemble")
{
assemble(p_149727_1_, p_149727_2_, p_149727_3_, p_149727_4_, p_149727_5_, setup);
}
}
}
if (p_149727_1_.isRemote)
{
return true;
} else {
return false;
}
}
void assemble(World p_149727_1_, int p_149727_2_, int p_149727_3_, int p_149727_4_, EntityPlayer p_149727_5_, String setup){//The "assemble" method
switch(setup) {
case "Machine":
p_149727_1_.setBlock(p_149727_2_, p_149727_3_, p_149727_4_, SCBlocks.VintryteMachine);
case "Charger":
p_149727_1_.setBlock(p_149727_2_, p_149727_3_, p_149727_4_, SCBlocks.VintryteCharger);
p_149727_1_.playSoundAtEntity(p_149727_5_, "sctechmod:assemble", 1.0F, 1.0F);
case "Coil":
p_149727_1_.setBlock(p_149727_2_, p_149727_3_, p_149727_4_, SCBlocks.VintryteCoilCore);
p_149727_1_.playSoundAtEntity(p_149727_5_, "sctechmod:assemble", 1.0F, 1.0F);
case "Generator":
p_149727_1_.setBlock(p_149727_2_, p_149727_3_, p_149727_4_, SCBlocks.VintryteGeneratorCore);//What always happens, no matter the setup
p_149727_1_.playSoundAtEntity(p_149727_5_, "sctechmod:assemble", 1.0F, 1.0F);
default:
}
}