Skip to content
Merged
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import net.minecraft.item.ItemBlock;
import net.minecraft.item.ItemStack;

import com.fouristhenumber.utilitiesinexcess.common.blocks.BlockAdvancedUpdateDetector;
import com.fouristhenumber.utilitiesinexcess.common.blocks.BlockBedrockium;
import com.fouristhenumber.utilitiesinexcess.common.blocks.BlockBlackoutCurtains;
import com.fouristhenumber.utilitiesinexcess.common.blocks.BlockColored;
Expand Down Expand Up @@ -139,6 +140,7 @@ public enum ModBlocks {
NETHER_STAR_GENERATOR_PLUS(GeneratorConfig.enableNetherStarGenerator, new BlockNetherStarGenerator("nether_star_generator_plus", 8), "nether_star_generator_plus"),
NETHER_STAR_GENERATOR_PLUSPLUS(GeneratorConfig.enableNetherStarGenerator, new BlockNetherStarGenerator("nether_star_generator_plusplus", 64), "nether_star_generator_plusplus"),
BLOCK_UPDATE_DETECTOR(BlockConfig.enableBlockUpdateDetector, new BlockUpdateDetector(), "block_update_detector"),
ADVANCED_BLOCK_UPDATE_DETECTOR(BlockConfig.enableBlockUpdateDetector, new BlockAdvancedUpdateDetector(), "advanced_block_update_detector"),
ENDER_LOTUS(EnderLotusConfig.enableEnderLotus, new BlockEnderLotus(), null, "ender_lotus"),
BLACKOUT_CURTAINS(BlockConfig.enableBlackoutCurtains, new BlockBlackoutCurtains(), "blackout_curtains"),
CONVEYOR(BlockConfig.enableConveyor, new BlockConveyor(), BlockConveyor.ItemBlockConveyor.class, "conveyor"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.fouristhenumber.utilitiesinexcess.common.renderers.BlackoutCurtainsRenderer;
import com.fouristhenumber.utilitiesinexcess.common.renderers.LapisAetheriusRenderer;
import com.fouristhenumber.utilitiesinexcess.common.renderers.SpikeRenderer;
import com.fouristhenumber.utilitiesinexcess.common.tileentities.TileEntityAdvancedBlockUpdateDetector;
import com.fouristhenumber.utilitiesinexcess.common.tileentities.TileEntityBlockUpdateDetector;
import com.fouristhenumber.utilitiesinexcess.common.tileentities.TileEntityConveyor;
import com.fouristhenumber.utilitiesinexcess.common.tileentities.TileEntityDrum;
Expand Down Expand Up @@ -125,6 +126,8 @@ public void init(FMLInitializationEvent event) {
GameRegistry.registerTileEntity(TileEntitySoundMuffler.class, "TileEntitySoundMufflerUIE");
GameRegistry.registerTileEntity(TileEntityRainMuffler.class, "TileEntityRainMufflerUIE");
GameRegistry.registerTileEntity(TileEntityBlockUpdateDetector.class, "TileEntityBlockUpdateDetector");
GameRegistry
.registerTileEntity(TileEntityAdvancedBlockUpdateDetector.class, "TileEntityAdvancedBlockUpdateDetector");
GameRegistry.registerTileEntity(TileEntityConveyor.class, "TileEntityConveyor");
GameRegistry.registerTileEntity(TileEntityPortalUnderWorld.class, "TileEntityPortalUnderWorld");
GameRegistry.registerTileEntity(TileEntityBlockUpdateDetector.class, "TileEntityBlockUpdateDetectorUIE");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,9 @@ public static void IMCSender() {
sendInfoPage("<utilitiesinexcess:drum>", "nei.infopage.uie.drum.1");

sendInfoPage("<utilitiesinexcess:block_update_detector>", "nei.infopage.uie.block_update_detector.1");
sendInfoPage(
"<utilitiesinexcess:advanced_block_update_detector>",
"nei.infopage.uie.advanced.block_update_detector.1");

sendInfoPage("<utilitiesinexcess:rain_muffler>", "nei.infopage.uie.rain_muffler.1");
sendInfoPage("<utilitiesinexcess:sound_muffler>", "nei.infopage.uie.sound_muffler.1");
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
package com.fouristhenumber.utilitiesinexcess.common.blocks;

import static net.minecraft.util.Facing.facings;

import net.minecraft.block.BlockContainer;
import net.minecraft.block.material.Material;
import net.minecraft.client.renderer.texture.IIconRegister;
import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.ChatComponentTranslation;
import net.minecraft.util.IIcon;
import net.minecraft.world.IBlockAccess;
import net.minecraft.world.World;

import com.fouristhenumber.utilitiesinexcess.common.tileentities.TileEntityAdvancedBlockUpdateDetector;

public class BlockAdvancedUpdateDetector extends BlockContainer {

private IIcon iconInactive;
private IIcon iconActive;

public BlockAdvancedUpdateDetector() {
super(Material.rock);
setBlockName("advanced_block_update_detector");
setHardness(1.0F);
setHarvestLevel("pickaxe", 0);
}

@Override
public void registerBlockIcons(IIconRegister reg) {
iconInactive = reg.registerIcon("utilitiesinexcess:advanced_block_update_detector_inactive");
iconActive = reg.registerIcon("utilitiesinexcess:advanced_block_update_detector_active");
}

@Override
public IIcon getIcon(int side, int meta) {
boolean active = (meta) == 1;
return active ? iconActive : iconInactive;
}

@Override
public TileEntity createNewTileEntity(World world, int meta) {
return new TileEntityAdvancedBlockUpdateDetector();
}

@Override
public boolean canProvidePower() {
return true;
}

@Override
public int isProvidingWeakPower(IBlockAccess world, int x, int y, int z, int side) {
TileEntity tileEntity = world.getTileEntity(x, y, z);
if (tileEntity instanceof TileEntityAdvancedBlockUpdateDetector tileABUD) {
return tileABUD.getOutputPower();
}
return 0;
}

@Override
public boolean isNormalCube(IBlockAccess world, int x, int y, int z) {
return true;
}

@Override
public boolean onBlockActivated(World world, int x, int y, int z, EntityPlayer player, int side, float subX,
float subY, float subZ) {
if (!player.isSneaking()) {
return false;
}
TileEntity tileEntity = world.getTileEntity(x, y, z);
if (tileEntity instanceof TileEntityAdvancedBlockUpdateDetector tileABUD) {
tileABUD.toggleFace(side);
player.addChatMessage(
new ChatComponentTranslation(
"chat.tile.advanced_block_update_detector.toggle",
facings[side],
tileABUD.getScanning(side)));
return true;
}
return false;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ public class BlockUpdateDetector extends BlockContainer {
public BlockUpdateDetector() {
super(Material.rock);
setBlockName("block_update_detector");
setBlockTextureName("utilitiesinexcess:block_update_detector_inactive");
setHardness(1.0F);
setHarvestLevel("pickaxe", 0);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,19 @@ public static void run() {
'p',
Blocks.sticky_piston);

// Advanced Block Update Detector
addShapedRecipe(
ModBlocks.ADVANCED_BLOCK_UPDATE_DETECTOR,
"srs",
"rbr",
"srs",
's',
Blocks.stone,
'r',
Blocks.redstone_block,
'b',
ModBlocks.BLOCK_UPDATE_DETECTOR);

// Trash Can (Items)
addShapedRecipe(
ModBlocks.TRASH_CAN_ITEM,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,145 @@
package com.fouristhenumber.utilitiesinexcess.common.tileentities;

import java.util.Objects;

import net.minecraft.block.Block;
import net.minecraft.init.Blocks;
import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.tileentity.TileEntity;
import net.minecraftforge.common.util.ForgeDirection;

public class TileEntityAdvancedBlockUpdateDetector extends TileEntity {

private boolean isProvidingPower = false;
private int pulseTimer = 0;
private final boolean[] scanningOnFace = { true, true, true, true, true, true };
private final Block[] blockOnPreviousTick = new Block[ForgeDirection.VALID_DIRECTIONS.length];
private final int[] blockMetadataOnPreviousTick = new int[ForgeDirection.VALID_DIRECTIONS.length];
private final NBTTagCompound[] tileEntityNBTCompoundOnPreviousTick = new NBTTagCompound[ForgeDirection.VALID_DIRECTIONS.length];

public void toggleFace(int face) {
scanningOnFace[face] = !scanningOnFace[face];
}

public boolean getScanning(int face) {
return scanningOnFace[face];
}

@Override
public void updateEntity() {
if (worldObj.isRemote) {
return;
}

if (isProvidingPower && pulseTimer > 0) {
pulseTimer--;
isProvidingPower = false;
updateBlockState();
worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord, getBlockType());
}

for (int i = 0; i < ForgeDirection.VALID_DIRECTIONS.length; i++) {
if (!scanningOnFace[i]) {
continue;
}
ForgeDirection neighborDirection = ForgeDirection.getOrientation(i);
Block blockOnCurrentTick = worldObj.getBlock(
xCoord + neighborDirection.offsetX,
yCoord + neighborDirection.offsetY,
zCoord + neighborDirection.offsetZ);
int blockMetadataOnCurrentTick = worldObj.getBlockMetadata(
xCoord + neighborDirection.offsetX,
yCoord + neighborDirection.offsetY,
zCoord + neighborDirection.offsetZ);
if (blockOnPreviousTick[i] == null) {
blockOnPreviousTick[i] = blockOnCurrentTick;
} else if (blockOnCurrentTick != blockOnPreviousTick[i] && !(blockOnCurrentTick == Blocks.redstone_wire)) {
sendRedstonePulse();
blockOnPreviousTick[i] = blockOnCurrentTick;
blockMetadataOnPreviousTick[i] = blockMetadataOnCurrentTick;
break;
} else {
if (blockMetadataOnCurrentTick != blockMetadataOnPreviousTick[i]) {
sendRedstonePulse();
blockOnPreviousTick[i] = blockOnCurrentTick;
blockMetadataOnPreviousTick[i] = blockMetadataOnCurrentTick;
break;
}
blockMetadataOnPreviousTick[i] = blockMetadataOnCurrentTick;
}
if (blockOnCurrentTick.hasTileEntity(blockMetadataOnPreviousTick[i])) {
if (!blockOnPreviousTick[i].hasTileEntity(blockMetadataOnPreviousTick[i])) {
sendRedstonePulse();
blockOnPreviousTick[i] = blockOnCurrentTick;
break;
}
NBTTagCompound tileEntityNBTCompoundOnCurrentTick = new NBTTagCompound();
worldObj
.getTileEntity(
xCoord + neighborDirection.offsetX,
yCoord + neighborDirection.offsetY,
zCoord + neighborDirection.offsetZ)
.writeToNBT(tileEntityNBTCompoundOnCurrentTick);
if (tileEntityNBTCompoundOnPreviousTick[i] == null) {
blockOnPreviousTick[i] = blockOnCurrentTick;
tileEntityNBTCompoundOnPreviousTick[i] = tileEntityNBTCompoundOnCurrentTick;
} else
if (!Objects.equals(tileEntityNBTCompoundOnCurrentTick, tileEntityNBTCompoundOnPreviousTick[i])) {
sendRedstonePulse();
blockOnPreviousTick[i] = blockOnCurrentTick;
tileEntityNBTCompoundOnPreviousTick[i] = tileEntityNBTCompoundOnCurrentTick;
break;
}
tileEntityNBTCompoundOnPreviousTick[i] = tileEntityNBTCompoundOnCurrentTick;
}
blockOnPreviousTick[i] = blockOnCurrentTick;
}
}

private void updateBlockState() {
int meta = worldObj.getBlockMetadata(xCoord, yCoord, zCoord);
int newMeta = isProvidingPower ? 1 : 0;

if (meta != newMeta) {
worldObj.setBlockMetadataWithNotify(xCoord, yCoord, zCoord, newMeta, 3);
worldObj.markBlockForUpdate(xCoord, yCoord, zCoord);
}
}

@Override
public void readFromNBT(NBTTagCompound compound) {
super.readFromNBT(compound);
byte scannedFaces = compound.getByte("faces");
for (int i = 0; i < ForgeDirection.VALID_DIRECTIONS.length; i++) {
scanningOnFace[i] = (scannedFaces >> i) > 0;
}
isProvidingPower = compound.getBoolean("powered");
pulseTimer = compound.getInteger("pulse");
}

@Override
public void writeToNBT(NBTTagCompound compound) {
super.writeToNBT(compound);
byte scannedFaces = 0;
for (int i = 0; i < ForgeDirection.VALID_DIRECTIONS.length; i++) {
scannedFaces += (byte) ((scanningOnFace[i] ? 1 : 0) << i);
}
compound.setByte("faces", scannedFaces);
compound.setBoolean("powered", isProvidingPower);
compound.setInteger("pulse", pulseTimer);
}

private void sendRedstonePulse() {
if (!isProvidingPower) {
isProvidingPower = true;
pulseTimer++;
updateBlockState();
worldObj.notifyBlocksOfNeighborChange(xCoord, yCoord, zCoord, getBlockType());
worldObj.scheduleBlockUpdate(xCoord, yCoord, zCoord, getBlockType(), 1);
}
}

public int getOutputPower() {
return isProvidingPower ? 15 : 0;
}
}
4 changes: 4 additions & 0 deletions src/main/resources/assets/utilitiesinexcess/lang/en_US.lang
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,10 @@ utilitiesinexcess.config.item.watering_can_flowering=Watering Can Flowering
tile.block_update_detector.name=Block Update Detector
nei.infopage.uie.block_update_detector.1=This mechanism keeps tabs on neighboring blocks and will emit a redstone pulse if any of them receive a block update.

tile.advanced_block_update_detector.name=Advanced Block Update Detector
nei.infopage.uie.advanced.block_update_detector.1=Like the standard Block Update Detector, this block will emit a redstone pulse on neighboring block updates. However, it also reacts to changes to tile-entity data or metadata even without a block update. Shift right click any face of the ABUD to toggle scanning on that side.
chat.tile.advanced_block_update_detector.toggle=Side %s set to redstone output %s.

tile.drum.name=Drum
tile.drum.desc=Holds %s buckets of fluid
tile.drum.desc.fluid=Currently holding %s %sL
Expand Down
Loading