I've been trying to mod in a new redstone component similar to the piston. I've searched high and low on forums and YouTube, trying to figure out how to get this to work, but I can't seem to get any proper updates or read redstone signals like I'm expecting. In all cases, it has either has ignored all redstone signals, or it doesn't function like it should (I've tested it with onBlockActivated. it does work) Is there something I'm missing? Do I need a TileEntity? Am I overriding the wrong methods? I should also mention that I'm just setting blocks in the world to test whether code is running, and it doesn't ever seem to.
package com.willtgd.testmod.blocks;
import java.util.Random;
import net.minecraft.block.Block;
import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;
public class Teleporter extends Block {
public Teleporter() {} // not important to the question at hand (i think)
@Override
public void updateTick(World world, BlockPos pos, IBlockState state, Random rand) {
if (world.isBlockPowered(pos.add(0, 0, 1))) {
world.setBlockState(pos.add(1, 0, 0), Block.getBlockFromName("minecraft:stone").getDefaultState());
}
}
@Override
public void onNeighborChange(IBlockAccess access, BlockPos pos, BlockPos neighbor) {
World world = Minecraft.getMinecraft().world;
if (world.isBlockPowered(neighbor)) {
world.setBlockState(neighbor, Block.getBlockFromName("minecraft:dirt").getDefaultState());
}
}
@Override
public void observedNeighborChange(IBlockState state, World world, BlockPos observerPos, Block changedBlock, BlockPos changePos) {
if (world.isBlockPowered(changePos)) {
world.setBlockState(changePos, Block.getBlockFromName("minecraft:dirt").getDefaultState());
}
}
private void swapBlocks(World world, BlockPos pos) {
BlockPos up = pos.add(0, 1, 0);
BlockPos down = pos.add(0, -1, 0);
IBlockState temp = world.getBlockState(up);
world.setBlockState(up, world.getBlockState(down));
world.setBlockState(down, temp);
}
}