Skip to content

Commit 64b559b

Browse files
committed
more redstone
1 parent 5e9c423 commit 64b559b

File tree

12 files changed

+203
-98
lines changed

12 files changed

+203
-98
lines changed

src/MiNET/MiNET.sln

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Other", "Other", "{DFC6A100
77
ProjectSection(SolutionItems) = preProject
88
..\..\.editorconfig = ..\..\.editorconfig
99
..\..\README.md = ..\..\README.md
10+
Redstone.md = Redstone.md
1011
EndProjectSection
1112
EndProject
1213
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "MiNET", "MiNET\MiNET.csproj", "{A40D7181-E216-4C45-AEF8-AB66B42B1D2D}"

src/MiNET/MiNET/Blocks/Button.cs

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -54,28 +54,24 @@ public override bool PlaceBlock(Level world, Player player, BlockCoordinates blo
5454
return true;
5555
}
5656

57-
public override bool Interact(Level world, Player player, BlockCoordinates blockCoordinates, BlockFace face, Vector3 faceCoord)
57+
public override bool Interact(Level level, Player player, BlockCoordinates blockCoordinates, BlockFace face, Vector3 faceCoord)
5858
{
59-
world.BroadcastSound(blockCoordinates, LevelSoundEventType.ButtonOn);
59+
level.BroadcastSound(blockCoordinates, LevelSoundEventType.ButtonOn);
6060
ButtonPressedBit = true;
6161
FacingDirection = Direction;
62-
world.SetBlock(this);
63-
world.ScheduleBlockTick(this, TickRate);
62+
level.SetBlock(this);
63+
level.ScheduleBlockTick(this, TickRate);
6464

65-
if (!world.RedstoneEnabled) { return true; }
65+
if (!level.RedstoneEnabled) { return true; }
6666

67-
cord = [ Coordinates.BlockNorth(), Coordinates.BlockSouth(), Coordinates.BlockEast(), Coordinates.BlockWest(), Coordinates.BlockUp(), Coordinates.BlockDown() ];
67+
cord = [Coordinates.BlockNorth(), Coordinates.BlockSouth(), Coordinates.BlockEast(), Coordinates.BlockWest(), Coordinates.BlockDown(), Coordinates.BlockNorthEast(), Coordinates.BlockNorthWest(), Coordinates.BlockSouthEast(), Coordinates.BlockSouthWest()];
6868

6969
if (ButtonPressedBit)
7070
{
7171
foreach (BlockCoordinates bCord in cord)
7272
{
73-
var blockk = world.GetBlock(bCord);
74-
if (blockk is RedstoneLamp)
75-
{
76-
world.SetBlock(new LitRedstoneLamp { Coordinates = new BlockCoordinates(bCord) });
77-
}
78-
TurnOff(world);
73+
RedstoneController.signal(level, bCord, true);
74+
TurnOff(level);
7975
}
8076
}
8177
return true;
@@ -89,16 +85,12 @@ public override void OnTick(Level level, bool isRandom)
8985
level.SetBlock(this);
9086
}
9187

92-
private async void TurnOff(Level world)
88+
private async void TurnOff(Level level)
9389
{
9490
await Task.Delay((TickRate / 2) * 100);
9591
foreach (BlockCoordinates bCord in cord)
9692
{
97-
var blockk = world.GetBlock(bCord);
98-
if (blockk is RedstoneLamp)
99-
{
100-
world.SetBlock(new RedstoneLamp { Coordinates = new BlockCoordinates(bCord) });
101-
}
93+
RedstoneController.signal(level, bCord, false);
10294
}
10395
}
10496
}

src/MiNET/MiNET/Blocks/FenceGateBlocks.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ namespace MiNET.Blocks
3535
public abstract class FenceGateBlocks : Block
3636
{
3737
[StateRange(0, 3)] public virtual int Direction { get; set; }
38+
[StateBit] public virtual bool OpenBit { get; set; } = false;
3839
public FenceGateBlocks(byte id) : base(id)
3940
{
4041
FuelEfficiency = 15;

src/MiNET/MiNET/Blocks/HeavyWeightedPressurePlate.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
namespace MiNET.Blocks
2727
{
28-
public partial class HeavyWeightedPressurePlate : Block
28+
public partial class HeavyWeightedPressurePlate : PressurePlateBase
2929
{
3030
public HeavyWeightedPressurePlate() : base(148)
3131
{

src/MiNET/MiNET/Blocks/Lever.cs

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ namespace MiNET.Blocks
3535
public partial class Lever : Block
3636
{
3737
public static string Direction { get; set; }
38+
private BlockCoordinates[] cord = [];
3839
private static readonly ILog Log = LogManager.GetLogger(typeof(Lever));
3940
public Lever() : base(69)
4041
{
@@ -106,14 +107,7 @@ public override void BreakBlock(Level level, BlockFace face, bool silent = false
106107
foreach (BlockCoordinates bCord in cord)
107108
{
108109
var blockk = level.GetBlock(bCord);
109-
if (blockk is LitRedstoneLamp)
110-
{
111-
level.SetBlock(new RedstoneLamp { Coordinates = new BlockCoordinates(bCord) });
112-
}
113-
if (blockk is RedstoneWire)
114-
{
115-
level.SetBlock(new RedstoneWire { Coordinates = new BlockCoordinates(bCord), RedstoneSignal = 0 });
116-
}
110+
RedstoneController.signal(level, bCord, false);
117111
}
118112
base.BreakBlock(level, face);
119113
}
@@ -126,27 +120,16 @@ public override void BlockAdded(Level level)
126120
public override void OnTick(Level level, bool isRandom)
127121
{
128122
if (isRandom) { return; }
129-
BlockCoordinates[] cord = { Coordinates.BlockNorth(), Coordinates.BlockSouth(), Coordinates.BlockEast(), Coordinates.BlockWest(), Coordinates.BlockUp(), Coordinates.BlockDown() };
123+
cord = [Coordinates.BlockNorth(), Coordinates.BlockSouth(), Coordinates.BlockEast(), Coordinates.BlockWest(), Coordinates.BlockDown(), Coordinates.BlockNorthEast(), Coordinates.BlockNorthWest(), Coordinates.BlockSouthEast(), Coordinates.BlockSouthWest()];
130124
foreach (BlockCoordinates bCord in cord)
131125
{
132-
var blockk = level.GetBlock(bCord);
133126
if (OpenBit)
134127
{
135-
if (blockk is RedstoneLamp)
136-
{
137-
level.SetBlock(new LitRedstoneLamp { Coordinates = new BlockCoordinates(bCord) });
138-
}
128+
RedstoneController.signal(level, bCord, true);
139129
}
140130
else
141131
{
142-
if (blockk is LitRedstoneLamp)
143-
{
144-
level.SetBlock(new RedstoneLamp { Coordinates = new BlockCoordinates(bCord) });
145-
}
146-
if (blockk is RedstoneWire)
147-
{
148-
level.ScheduleBlockTick(level.GetBlock(bCord), 10);
149-
}
132+
RedstoneController.signal(level, bCord, false);
150133
}
151134
}
152135
level.ScheduleBlockTick(this, 10);

src/MiNET/MiNET/Blocks/LightWeightedPressurePlate.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525

2626
namespace MiNET.Blocks
2727
{
28-
public partial class LightWeightedPressurePlate : Block
28+
public partial class LightWeightedPressurePlate : PressurePlateBase
2929
{
3030
public LightWeightedPressurePlate() : base(147)
3131
{

src/MiNET/MiNET/Blocks/PartialBlocks.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -779,7 +779,7 @@ public partial class AcaciaFenceGate // 187 typeof=AcaciaFenceGate
779779
{
780780
[StateRange(0, 3)] public override int Direction { get; set; } = 0;
781781
[StateBit] public bool InWallBit { get; set; } = false;
782-
[StateBit] public bool OpenBit { get; set; } = false;
782+
[StateBit] public override bool OpenBit { get; set; } = false;
783783

784784
public override void SetState(List<IBlockState> states)
785785
{
@@ -1548,7 +1548,7 @@ public partial class BirchFenceGate // 184 typeof=BirchFenceGate
15481548
{
15491549
[StateRange(0, 3)] public override int Direction { get; set; } = 0;
15501550
[StateBit] public bool InWallBit { get; set; } = false;
1551-
[StateBit] public bool OpenBit { get; set; } = false;
1551+
[StateBit] public override bool OpenBit { get; set; } = false;
15521552

15531553
public override void SetState(List<IBlockState> states)
15541554
{
@@ -3281,7 +3281,7 @@ public partial class DarkOakFenceGate // 186 typeof=DarkOakFenceGate
32813281
{
32823282
[StateRange(0, 3)] public override int Direction { get; set; } = 0;
32833283
[StateBit] public bool InWallBit { get; set; } = false;
3284-
[StateBit] public bool OpenBit { get; set; } = false;
3284+
[StateBit] public override bool OpenBit { get; set; } = false;
32853285

32863286
public override void SetState(List<IBlockState> states)
32873287
{
@@ -4246,7 +4246,7 @@ public partial class FenceGate // 107 typeof=FenceGate
42464246
{
42474247
[StateRange(0, 3)] public override int Direction { get; set; } = 0;
42484248
[StateBit] public bool InWallBit { get; set; } = false;
4249-
[StateBit] public bool OpenBit { get; set; } = false;
4249+
[StateBit] public override bool OpenBit { get; set; } = false;
42504250

42514251
public override void SetState(List<IBlockState> states)
42524252
{
@@ -5036,7 +5036,7 @@ public override BlockStateContainer GetState()
50365036

50375037
public partial class HeavyWeightedPressurePlate // 148 typeof=HeavyWeightedPressurePlate
50385038
{
5039-
[StateRange(0, 15)] public int RedstoneSignal { get; set; } = 0;
5039+
[StateRange(0, 15)] public override int RedstoneSignal { get; set; } = 0;
50405040

50415041
public override void SetState(List<IBlockState> states)
50425042
{
@@ -5514,7 +5514,7 @@ public partial class JungleFenceGate // 185 typeof=JungleFenceGate
55145514
{
55155515
[StateRange(0, 3)] public override int Direction { get; set; } = 0;
55165516
[StateBit] public bool InWallBit { get; set; } = false;
5517-
[StateBit] public bool OpenBit { get; set; } = false;
5517+
[StateBit] public override bool OpenBit { get; set; } = false;
55185518

55195519
public override void SetState(List<IBlockState> states)
55205520
{
@@ -6058,7 +6058,7 @@ public override BlockStateContainer GetState()
60586058

60596059
public partial class LightWeightedPressurePlate // 147 typeof=LightWeightedPressurePlate
60606060
{
6061-
[StateRange(0, 15)] public int RedstoneSignal { get; set; } = 0;
6061+
[StateRange(0, 15)] public override int RedstoneSignal { get; set; } = 0;
60626062

60636063
public override void SetState(List<IBlockState> states)
60646064
{
@@ -8793,7 +8793,7 @@ public partial class SpruceFenceGate // 183 typeof=SpruceFenceGate
87938793
{
87948794
[StateRange(0, 3)] public override int Direction { get; set; } = 0;
87958795
[StateBit] public bool InWallBit { get; set; } = false;
8796-
[StateBit] public bool OpenBit { get; set; } = false;
8796+
[StateBit] public override bool OpenBit { get; set; } = false;
87978797

87988798
public override void SetState(List<IBlockState> states)
87998799
{

src/MiNET/MiNET/Blocks/PressurePlateBase.cs

Lines changed: 8 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
1-
using MiNET.Sounds;
2-
using MiNET.Utils.Vectors;
1+
using MiNET.Utils.Vectors;
32
using MiNET.Worlds;
43

54
namespace MiNET.Blocks
65
{
76
public abstract class PressurePlateBase : Block
87
{
98
public virtual int RedstoneSignal { get; set; }
9+
private BlockCoordinates[] cord = [];
1010

1111
protected PressurePlateBase(int id) : base(id)
1212
{
@@ -30,33 +30,20 @@ public override void BreakBlock(Level level, BlockFace face, bool silent = false
3030
public override void OnTick(Level level, bool isRandom)
3131
{
3232
if (isRandom) { return; }
33-
BlockCoordinates cord = Coordinates.BlockDown();
3433
var entities = level.GetSpawnedPlayers();
34+
cord = [Coordinates.BlockNorth(), Coordinates.BlockSouth(), Coordinates.BlockEast(), Coordinates.BlockWest(), Coordinates.BlockDown()];
3535
foreach (var entity in entities)
3636
{
37-
if ((int) entity.KnownPosition.X == Coordinates.X && (int) entity.KnownPosition.Y == Coordinates.Y && (int) entity.KnownPosition.Z == Coordinates.Z)
37+
if ((int) (entity.KnownPosition.X < 0 ? entity.KnownPosition.X - 1 : entity.KnownPosition.X) == Coordinates.X && (int) entity.KnownPosition.Y == Coordinates.Y && (int) (entity.KnownPosition.Z < 0 ? entity.KnownPosition.Z - 1 : entity.KnownPosition.Z) == Coordinates.Z)
3838
{
3939
if (RedstoneSignal == 0)
4040
{
4141
RedstoneSignal = 15;
4242
level.SetBlock(this);
4343
level.BroadcastSound(Coordinates, LevelSoundEventType.PressurePlateOn);
44-
for (int i = 0; i < 5; i++)
44+
foreach (BlockCoordinates bCord in cord)
4545
{
46-
if (i == 0) { cord = this.Coordinates.BlockNorth(); }
47-
if (i == 1) { cord = this.Coordinates.BlockSouth(); }
48-
if (i == 2) { cord = this.Coordinates.BlockWest(); }
49-
if (i == 3) { cord = this.Coordinates.BlockEast(); }
50-
if (i == 4) { cord = this.Coordinates.BlockDown(); }
51-
var blockk = level.GetBlock(cord);
52-
if (blockk is RedstoneLamp) { level.SetBlock(new LitRedstoneLamp { Coordinates = new BlockCoordinates(cord) }); }
53-
if (blockk is WoodenDoor) { level.SetBlock(new WoodenDoor { Direction = blockk.GetDirection(), Coordinates = new BlockCoordinates(cord), OpenBit = true }); var sound = new Sound((short) LevelEventType.SoundOpenDoor, Coordinates); sound.Spawn(level);}
54-
if (blockk is SpruceDoor) { level.SetBlock(new SpruceDoor { Direction = blockk.GetDirection(), Coordinates = new BlockCoordinates(cord), OpenBit = true }); var sound = new Sound((short) LevelEventType.SoundOpenDoor, Coordinates); sound.Spawn(level);}
55-
if (blockk is BirchDoor) { level.SetBlock(new BirchDoor { Direction = blockk.GetDirection(), Coordinates = new BlockCoordinates(cord), OpenBit = true }); var sound = new Sound((short) LevelEventType.SoundOpenDoor, Coordinates); sound.Spawn(level);}
56-
if (blockk is JungleDoor) { level.SetBlock(new JungleDoor { Direction = blockk.GetDirection(), Coordinates = new BlockCoordinates(cord), OpenBit = true }); var sound = new Sound((short) LevelEventType.SoundOpenDoor, Coordinates); sound.Spawn(level);}
57-
if (blockk is AcaciaDoor) { level.SetBlock(new AcaciaDoor { Direction = blockk.GetDirection(), Coordinates = new BlockCoordinates(cord), OpenBit = true }); var sound = new Sound((short) LevelEventType.SoundOpenDoor, Coordinates); sound.Spawn(level);}
58-
if (blockk is DarkOakDoor) { level.SetBlock(new DarkOakDoor { Direction = blockk.GetDirection(), Coordinates = new BlockCoordinates(cord), OpenBit = true }); var sound = new Sound((short) LevelEventType.SoundOpenDoor, Coordinates); sound.Spawn(level);}
59-
if (blockk is IronDoor) { level.SetBlock(new IronDoor { Direction = blockk.GetDirection(), Coordinates = new BlockCoordinates(cord), OpenBit = true }); var sound = new Sound((short) LevelEventType.SoundOpenDoor, Coordinates); sound.Spawn(level);}
46+
RedstoneController.signal(level, bCord, true);
6047
}
6148
}
6249
}
@@ -65,22 +52,9 @@ public override void OnTick(Level level, bool isRandom)
6552
RedstoneSignal = 0;
6653
level.SetBlock(this);
6754
level.BroadcastSound(Coordinates, LevelSoundEventType.PressurePlateOff);
68-
for (int i = 0; i < 5; i++)
55+
foreach (BlockCoordinates bCord in cord)
6956
{
70-
if (i == 0) { cord = this.Coordinates.BlockNorth(); }
71-
if (i == 1) { cord = this.Coordinates.BlockSouth(); }
72-
if (i == 2) { cord = this.Coordinates.BlockWest(); }
73-
if (i == 3) { cord = this.Coordinates.BlockEast(); }
74-
if (i == 4) { cord = this.Coordinates.BlockDown(); }
75-
var blockk = level.GetBlock(cord);
76-
if (blockk is LitRedstoneLamp) { level.SetBlock(new RedstoneLamp { Coordinates = new BlockCoordinates(cord) });}
77-
if (blockk is WoodenDoor) { level.SetBlock(new WoodenDoor { Direction = blockk.GetDirection(), Coordinates = new BlockCoordinates(cord), OpenBit = false }); var sound = new Sound((short) LevelEventType.SoundOpenDoor, Coordinates); sound.Spawn(level);}
78-
if (blockk is SpruceDoor) { level.SetBlock(new SpruceDoor { Direction = blockk.GetDirection(), Coordinates = new BlockCoordinates(cord), OpenBit = false }); var sound = new Sound((short) LevelEventType.SoundOpenDoor, Coordinates); sound.Spawn(level);}
79-
if (blockk is BirchDoor) { level.SetBlock(new BirchDoor { Direction = blockk.GetDirection(), Coordinates = new BlockCoordinates(cord), OpenBit = false }); var sound = new Sound((short) LevelEventType.SoundOpenDoor, Coordinates); sound.Spawn(level);}
80-
if (blockk is JungleDoor) { level.SetBlock(new JungleDoor { Direction = blockk.GetDirection(), Coordinates = new BlockCoordinates(cord), OpenBit = false }); var sound = new Sound((short) LevelEventType.SoundOpenDoor, Coordinates); sound.Spawn(level);}
81-
if (blockk is AcaciaDoor) { level.SetBlock(new AcaciaDoor { Direction = blockk.GetDirection(), Coordinates = new BlockCoordinates(cord), OpenBit = false }); var sound = new Sound((short) LevelEventType.SoundOpenDoor, Coordinates); sound.Spawn(level);}
82-
if (blockk is DarkOakDoor) { level.SetBlock(new DarkOakDoor { Direction = blockk.GetDirection(), Coordinates = new BlockCoordinates(cord), OpenBit = false }); var sound = new Sound((short) LevelEventType.SoundOpenDoor, Coordinates); sound.Spawn(level);}
83-
if (blockk is IronDoor) { level.SetBlock(new IronDoor { Direction = blockk.GetDirection(), Coordinates = new BlockCoordinates(cord), OpenBit = false }); var sound = new Sound((short) LevelEventType.SoundOpenDoor, Coordinates); sound.Spawn(level);}
57+
RedstoneController.signal(level, bCord, false);
8458
}
8559
}
8660
}

src/MiNET/MiNET/Blocks/RedstoneTorch.cs

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -70,11 +70,7 @@ public override void BreakBlock(Level level, BlockFace face, bool silent = false
7070
level.CancelBlockTick(this);
7171
foreach (BlockCoordinates bCord in cord)
7272
{
73-
var blockk = level.GetBlock(bCord);
74-
if (blockk is LitRedstoneLamp)
75-
{
76-
level.SetBlock(new RedstoneLamp { Coordinates = new BlockCoordinates(bCord) });
77-
}
73+
RedstoneController.signal(level, bCord, false);
7874
}
7975
base.BreakBlock(level, face);
8076
}
@@ -90,11 +86,7 @@ public override void OnTick(Level level, bool isRandom)
9086
BlockCoordinates[] cord = { Coordinates.BlockNorth(), Coordinates.BlockSouth(), Coordinates.BlockEast(), Coordinates.BlockWest(), Coordinates.BlockUp(), Coordinates.BlockDown() };
9187
foreach (BlockCoordinates bCord in cord)
9288
{
93-
var blockk = level.GetBlock(bCord);
94-
if (blockk is RedstoneLamp)
95-
{
96-
level.SetBlock(new LitRedstoneLamp { Coordinates = new BlockCoordinates(bCord) });
97-
}
89+
RedstoneController.signal(level, bCord, true);
9890
}
9991
level.ScheduleBlockTick(this, 10);
10092
}

src/MiNET/MiNET/Blocks/RedstoneWire.cs

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,19 @@ public override void OnTick(Level level, bool isRandom)
5555
currentSignal = 15;
5656
}
5757
}
58+
if (blockk is Button)
59+
{
60+
var button = blockk as Button;
61+
if (button.ButtonPressedBit == true)
62+
{
63+
currentSignal = 15;
64+
}
65+
}
66+
if (blockk is RedstoneTorch)
67+
{
68+
var button = blockk as RedstoneTorch;
69+
currentSignal = 15;
70+
}
5871
else if (blockk is RedstoneWire)
5972
{
6073
var wire = blockk as RedstoneWire;
@@ -71,16 +84,15 @@ public override void OnTick(Level level, bool isRandom)
7184
level.ScheduleBlockTick(blockk, 10);
7285
}
7386
}
74-
else if (blockk is RedstoneLamp)
87+
else
7588
{
7689
if ( RedstoneSignal > 0)
7790
{
78-
level.SetBlock(new LitRedstoneLamp { Coordinates = new BlockCoordinates(bCord) });
91+
RedstoneController.signal(level, bCord, true);
7992
}
8093
else
8194
{
82-
level.SetBlock(new RedstoneLamp { Coordinates = new BlockCoordinates(bCord) });
83-
95+
RedstoneController.signal(level, bCord, false);
8496
}
8597
}
8698
level.SetBlock(new RedstoneWire { Coordinates = new BlockCoordinates(Coordinates), RedstoneSignal = currentSignal == -1 ? 0 : currentSignal });

0 commit comments

Comments
 (0)