diff --git a/src/main/java/com/dannyandson/tinyredstone/Config.java b/src/main/java/com/dannyandson/tinyredstone/Config.java new file mode 100644 index 0000000..523f1bf --- /dev/null +++ b/src/main/java/com/dannyandson/tinyredstone/Config.java @@ -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(); + + + } + + +} diff --git a/src/main/java/com/dannyandson/tinyredstone/TinyRedstone.java b/src/main/java/com/dannyandson/tinyredstone/TinyRedstone.java index 145981a..2cf6805 100644 --- a/src/main/java/com/dannyandson/tinyredstone/TinyRedstone.java +++ b/src/main/java/com/dannyandson/tinyredstone/TinyRedstone.java @@ -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; @@ -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 iPanelCellClass, Item correspondingItem) diff --git a/src/main/java/com/dannyandson/tinyredstone/blocks/panelcells/RedstoneLamp.java b/src/main/java/com/dannyandson/tinyredstone/blocks/panelcells/RedstoneLamp.java index b3661d7..36db211 100644 --- a/src/main/java/com/dannyandson/tinyredstone/blocks/panelcells/RedstoneLamp.java +++ b/src/main/java/com/dannyandson/tinyredstone/blocks/panelcells/RedstoneLamp.java @@ -1,8 +1,6 @@ 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; @@ -10,18 +8,14 @@ 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 * @@ -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. * @@ -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"); - } } diff --git a/src/main/java/com/dannyandson/tinyredstone/blocks/panelcells/TinyBlock.java b/src/main/java/com/dannyandson/tinyredstone/blocks/panelcells/TinyBlock.java index b485fd6..7504e70 100644 --- a/src/main/java/com/dannyandson/tinyredstone/blocks/panelcells/TinyBlock.java +++ b/src/main/java/com/dannyandson/tinyredstone/blocks/panelcells/TinyBlock.java @@ -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(); /** @@ -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()); } diff --git a/src/main/java/com/dannyandson/tinyredstone/blocks/panelcells/Torch.java b/src/main/java/com/dannyandson/tinyredstone/blocks/panelcells/Torch.java index 0c33e39..715b16b 100644 --- a/src/main/java/com/dannyandson/tinyredstone/blocks/panelcells/Torch.java +++ b/src/main/java/com/dannyandson/tinyredstone/blocks/panelcells/Torch.java @@ -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; @@ -151,7 +152,7 @@ public boolean isPushable() { */ @Override public int lightOutput() { - return (output)?1:0; + return (output && Config.TORCH_LIGHT.get())?1:0; } /**