Skip to content

Commit a587095

Browse files
author
BastouP411
committed
Tunak tunak tunak tun
1 parent f9987b1 commit a587095

File tree

10 files changed

+30
-12
lines changed

10 files changed

+30
-12
lines changed

src/main/java/fr/bastoup/bperipherals/init/ModItems.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,8 @@
77
import java.util.List;
88

99
public class ModItems {
10-
public static final List<Item> ITEMS = new ArrayList<Item>();
10+
public static final List<Item> ITEMS = new ArrayList<>();
1111

1212
public static final Item DATABASE_DISK = new ItemBase("database_disk", 1);
13+
public static final Item MAG_CARD = new ItemBase("mag_card", 1);
1314
}

src/main/java/fr/bastoup/bperipherals/peripherals/database/TileDatabase.java

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package fr.bastoup.bperipherals.peripherals.database;
22

3+
import dan200.computercraft.api.peripheral.IComputerAccess;
34
import fr.bastoup.bperipherals.init.ModItems;
45
import fr.bastoup.bperipherals.init.ModTileTypes;
56
import fr.bastoup.bperipherals.util.Util;
@@ -40,7 +41,7 @@ public class TileDatabase extends TilePeripheral implements INamedContainerProvi
4041
private final LazyOptional<InventoryDatabase> holderInv = LazyOptional.of(() -> databaseInventory);
4142

4243
private boolean lastDiskState = false;
43-
private int lastSize = 0;
44+
private final int lastSize = 0;
4445
private ITextComponent customName;
4546

4647
public TileDatabase() {
@@ -130,18 +131,22 @@ public CompoundNBT write(CompoundNBT nbt) {
130131
public void tick() {
131132
if (isDiskInserted() && !lastDiskState) {
132133
this.getWorld().setBlockState(this.getPos(), this.getBlockState().with(BlockDatabase.DISK_INSERTED, true));
134+
135+
synchronized (computers) {
136+
for (IComputerAccess c : computers) {
137+
c.queueEvent("database_attached", c.getAttachmentName(), getDatabaseId(), getDatabaseName());
138+
}
139+
}
133140
} else if (!isDiskInserted() && lastDiskState) {
134141
this.getWorld().setBlockState(this.getPos(), this.getBlockState().with(BlockDatabase.DISK_INSERTED, false));
135-
}
136-
lastDiskState = isDiskInserted();
137142

138-
synchronized (computers) {
139-
if(computers.size() != lastSize) {
140-
lastSize = computers.size();
141-
System.out.println("Connected: " + lastSize);
143+
synchronized (computers) {
144+
for (IComputerAccess c : computers) {
145+
c.queueEvent("database_detached", c.getAttachmentName());
146+
}
142147
}
143148
}
144-
149+
lastDiskState = isDiskInserted();
145150
}
146151

147152
@Nullable

src/main/java/fr/bastoup/bperipherals/util/tiles/TilePeripheral.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import net.minecraftforge.common.capabilities.Capability;
1010
import net.minecraftforge.common.util.LazyOptional;
1111

12+
import javax.annotation.Nonnull;
1213
import java.util.HashSet;
1314
import java.util.Set;
1415

@@ -31,19 +32,18 @@ public void addComputer(IComputerAccess computer) {
3132
synchronized (computers) {
3233
computers.add(computer);
3334
update();
34-
System.out.println("tic " + computers.size());
3535
}
3636
}
3737

3838
public void removeComputer(IComputerAccess computer) {
3939
synchronized (computers) {
4040
computers.remove(computer);
4141
update();
42-
System.out.println("tac " + computers.size());
4342
}
4443
}
4544

4645
@Override
46+
@Nonnull
4747
public <T> LazyOptional<T> getCapability(Capability<T> capability, Direction facing) {
4848
if (capability.equals(Capabilities.CAPABILITY_PERIPHERAL)) {
4949
return holderPeripheral.cast();
@@ -52,7 +52,7 @@ public <T> LazyOptional<T> getCapability(Capability<T> capability, Direction fac
5252
}
5353

5454
public void update() {
55-
if (computers.isEmpty()) {
55+
if (computers.isEmpty() && this.getWorld().getBlockState(this.getPos()).hasProperty(BlockPeripheral.SWITCHED_ON)) {
5656
this.getWorld().setBlockState(this.getPos(), this.getBlockState().with(BlockPeripheral.SWITCHED_ON, false));
5757
} else {
5858
this.getWorld().setBlockState(this.getPos(), this.getBlockState().with(BlockPeripheral.SWITCHED_ON, true));
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"parent": "item/generated",
3+
"textures": {
4+
"layer0": "bperipherals:items/mag_card/mag_card"
5+
}
6+
}
-20 Bytes
Loading
-2.48 KB
Loading
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"animation": {
3+
"interpolate": true,
4+
"frametime": 5
5+
}
6+
}
-7 Bytes
Loading
-7 Bytes
Loading
226 Bytes
Loading

0 commit comments

Comments
 (0)