Skip to content

Commit

Permalink
-Fixed an issue where tiny solid blocks and redstone lamps were passi…
Browse files Browse the repository at this point in the history
…ng signals between each other under certain edge conditions.

-Added server config to enable Tiny Redstone Torch light output: disabled by default. When disabled, torches will still glow when lit, but will not output light to the surrounding area.
  • Loading branch information
dannydjdk committed Mar 14, 2021
1 parent 9c5b074 commit 873891b
Show file tree
Hide file tree
Showing 5 changed files with 44 additions and 150 deletions.
30 changes: 30 additions & 0 deletions src/main/java/com/dannyandson/tinyredstone/Config.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.dannyandson.tinyredstone;

import net.minecraftforge.common.ForgeConfigSpec;
import net.minecraftforge.fml.common.Mod;

@Mod.EventBusSubscriber
public class Config {
public static ForgeConfigSpec SERVER_CONFIG;
public static final String CATEGORY_PERFORMANCE = "performance";
public static ForgeConfigSpec.BooleanValue TORCH_LIGHT;

static {

ForgeConfigSpec.Builder SERVER_BUILDER = new ForgeConfigSpec.Builder();


SERVER_BUILDER.comment("Performance Settings").push(CATEGORY_PERFORMANCE);

TORCH_LIGHT = SERVER_BUILDER.comment("Should redstone torches output light to the surrounding area? (default:false)")
.define("torch_light",false);

SERVER_BUILDER.pop();

SERVER_CONFIG = SERVER_BUILDER.build();


}


}
5 changes: 5 additions & 0 deletions src/main/java/com/dannyandson/tinyredstone/TinyRedstone.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,10 @@
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.event.entity.player.PlayerInteractEvent;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.ModLoadingContext;
import net.minecraftforge.fml.client.registry.ClientRegistry;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.config.ModConfig;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.fml.loading.FMLEnvironment;
Expand Down Expand Up @@ -41,6 +43,9 @@ public TinyRedstone() {

// Register ourselves for server and other game events we are interested in
MinecraftForge.EVENT_BUS.register(this);

//load configs
ModLoadingContext.get().registerConfig(ModConfig.Type.SERVER, Config.SERVER_CONFIG);
}

public static void registerPanelCell(Class<? extends IPanelCell> iPanelCellClass, Item correspondingItem)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,21 @@
package com.dannyandson.tinyredstone.blocks.panelcells;

import com.dannyandson.tinyredstone.blocks.IPanelCell;
import com.dannyandson.tinyredstone.blocks.PanelCellNeighbor;
import com.dannyandson.tinyredstone.blocks.PanelTile;
import com.mojang.blaze3d.matrix.MatrixStack;
import com.mojang.blaze3d.vertex.IVertexBuilder;
import net.minecraft.client.Minecraft;
import net.minecraft.client.renderer.IRenderTypeBuffer;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.client.renderer.texture.AtlasTexture;
import net.minecraft.client.renderer.texture.TextureAtlasSprite;
import net.minecraft.nbt.CompoundNBT;
import net.minecraft.util.ResourceLocation;
import net.minecraft.util.math.vector.Vector3f;

public class RedstoneLamp implements IPanelCell {
public class RedstoneLamp extends TinyBlock implements IPanelCell {

public static ResourceLocation TEXTURE_REDSTONE_LAMP = new ResourceLocation("minecraft","block/redstone_lamp");
public static ResourceLocation TEXTURE_REDSTONE_LAMP_ON = new ResourceLocation("minecraft","block/redstone_lamp_on");

private int weakSignalStrength = 0;
private int strongSignalStrength = 0;

/**
* Drawing the cell on the panel
*
Expand Down Expand Up @@ -86,106 +80,6 @@ private void add(IVertexBuilder renderer, MatrixStack stack, float x, float y, f
.endVertex();
}

/**
* Called when neighboring redstone signal output changes.
* This can be called multiple times in a tick.
* Passes PanelCellNeighbor objects - an object wrapping another IPanelCell or a BlockState
* WARNING! Check for null values!
*
* @param frontNeighbor object to access info about front neighbor or NULL if no neighbor exists
* @param rightNeighbor object to access info about right neighbor or NULL if no neighbor exists
* @param backNeighbor object to access info about back neighbor or NULL if no neighbor exists
* @param leftNeighbor object to access info about left neighbor or NULL if no neighbor exists
* @return boolean indicating whether redstone output of this cell has changed
*/
@Override
public boolean neighborChanged(PanelCellNeighbor frontNeighbor, PanelCellNeighbor rightNeighbor, PanelCellNeighbor backNeighbor, PanelCellNeighbor leftNeighbor) {

int weak=0,strong=0;
if (frontNeighbor!=null) {
if (frontNeighbor.powerDrops())
weak = frontNeighbor.getWeakRsOutput();
else if (!frontNeighbor.isPushable())
strong = frontNeighbor.getStrongRsOutput();
}
if (rightNeighbor!=null) {
if (rightNeighbor.powerDrops())
weak = Math.max(weak,rightNeighbor.getWeakRsOutput());
else if (!rightNeighbor.isPushable())
strong = Math.max(strong,rightNeighbor.getStrongRsOutput());
}
if (backNeighbor!=null) {
if (backNeighbor.powerDrops())
weak = Math.max(weak,backNeighbor.getWeakRsOutput());
else if (!backNeighbor.isPushable())
strong = Math.max(strong,backNeighbor.getStrongRsOutput());
}
if (leftNeighbor!=null) {
if (leftNeighbor.powerDrops())
weak = Math.max(weak,leftNeighbor.getWeakRsOutput());
else if (!leftNeighbor.isPushable())
strong = Math.max(strong,leftNeighbor.getStrongRsOutput());
}

weak=Math.max(weak,strong);

if (weak!=this.weakSignalStrength ||strong!=this.strongSignalStrength)
{
this.weakSignalStrength =weak;
this.strongSignalStrength=strong;
return true;
}

return false;
}


/**
* Gets redstone output of the given side of the cell
*
* @param outputDirection (1=Front,2=Right,3=Back,4=Left)
* @return integer 0-15 indicating the strength of redstone signal
*/
@Override
public int getWeakRsOutput(PanelCellSide outputDirection) {
return this.weakSignalStrength;
}

@Override
public int getStrongRsOutput(PanelCellSide outputDirection) {
return this.strongSignalStrength;
}

/**
* Does the power level drop when transmitting between these cells (such as with redstone dust)?
*
* @return true if power level should drop, false if not
*/
@Override
public boolean powerDrops() {
return false;
}

/**
* Is this a component that does not change state based on neighbors (such as a redstone block, or potentiometer)?
*
* @return true if this cell's state is unaffected by neighbors
*/
@Override
public boolean isIndependentState() {
return false;
}

/**
* Can this cell be pushed by a piston?
*
* @return true if a piston can push this block
*/
@Override
public boolean isPushable() {
return true;
}

/**
* If this cell outputs light, return the level here. Otherwise, return 0.
*
Expand All @@ -196,40 +90,4 @@ public int lightOutput() {
return (weakSignalStrength+strongSignalStrength>0)?1:0;
}

/**
* Called each each tick.
*
* @return boolean indicating whether redstone output of this cell has changed
*/
@Override
public boolean tick() {
return false;
}

/**
* Called when the cell is activated. i.e. player right clicked on the cell of the panel tile.
*
* @param panelTile the activated PanelTile tile entity that contains this cell
* @param cellIndex The index of the clicked IPanelCell within the panel (this IPanelCell)
* @param segmentClicked Which of nine segment within the cell were clicked. 0 through 8 where 0 is front-right and 8 is back-left;
* @return true if a change was made to the cell output
*/
@Override
public boolean onBlockActivated(PanelTile panelTile, Integer cellIndex, Integer segmentClicked) {
return false;
}

@Override
public CompoundNBT writeNBT() {
CompoundNBT nbt = new CompoundNBT();
nbt.putInt("strong",this.strongSignalStrength);
nbt.putInt("weak",this.weakSignalStrength);
return nbt;
}

@Override
public void readNBT(CompoundNBT compoundNBT) {
this.strongSignalStrength=compoundNBT.getInt("strong");
this.weakSignalStrength=compoundNBT.getInt("weak");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public class TinyBlock implements IPanelCell, IColorablePanelCell {

public static ResourceLocation TEXTURE_TINY_BLOCK = new ResourceLocation("minecraft","block/white_wool");

private int weakSignalStrength = 0;
private int strongSignalStrength = 0;
protected int weakSignalStrength = 0;
protected int strongSignalStrength = 0;
private int color= DyeColor.WHITE.getColorValue();

/**
Expand Down Expand Up @@ -107,25 +107,25 @@ public boolean neighborChanged(PanelCellNeighbor frontNeighbor, PanelCellNeighbo
if (frontNeighbor!=null) {
if (frontNeighbor.powerDrops())
weak = frontNeighbor.getWeakRsOutput();
else if (!frontNeighbor.isPushable())
else if (!(frontNeighbor.getNeighborIPanelCell() instanceof TinyBlock))
strong = frontNeighbor.getStrongRsOutput();
}
if (rightNeighbor!=null) {
if (rightNeighbor.powerDrops())
weak = Math.max(weak,rightNeighbor.getWeakRsOutput());
else if (!rightNeighbor.isPushable())
else if (!(rightNeighbor.getNeighborIPanelCell() instanceof TinyBlock))
strong = Math.max(strong,rightNeighbor.getStrongRsOutput());
}
if (backNeighbor!=null) {
if (backNeighbor.powerDrops())
weak = Math.max(weak,backNeighbor.getWeakRsOutput());
else if (!backNeighbor.isPushable())
else if (!(backNeighbor.getNeighborIPanelCell() instanceof TinyBlock))
strong = Math.max(strong,backNeighbor.getStrongRsOutput());
}
if (leftNeighbor!=null) {
if (leftNeighbor.powerDrops())
weak = Math.max(weak,leftNeighbor.getWeakRsOutput());
else if (!leftNeighbor.isPushable())
else if (!(leftNeighbor.getNeighborIPanelCell() instanceof TinyBlock))
strong = Math.max(strong,leftNeighbor.getStrongRsOutput());
}

Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.dannyandson.tinyredstone.blocks.panelcells;

import com.dannyandson.tinyredstone.Config;
import com.dannyandson.tinyredstone.TinyRedstone;
import com.dannyandson.tinyredstone.blocks.IPanelCell;
import com.dannyandson.tinyredstone.blocks.PanelCellNeighbor;
Expand Down Expand Up @@ -151,7 +152,7 @@ public boolean isPushable() {
*/
@Override
public int lightOutput() {
return (output)?1:0;
return (output && Config.TORCH_LIGHT.get())?1:0;
}

/**
Expand Down

0 comments on commit 873891b

Please sign in to comment.