Better Block Entity IDs
All checks were successful
ScriptCraft/pipeline/head This commit looks good

This commit is contained in:
TheBrokenRail 2020-04-27 10:31:58 -04:00
parent 83968f2916
commit 9e9710653f

View File

@ -11,8 +11,11 @@ import net.minecraft.util.Tickable;
import net.minecraft.util.math.BlockPos; import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World; import net.minecraft.world.World;
import java.util.HashMap;
import java.util.Map;
public class CustomBlockEntity extends BlockEntity implements BlockEntityClientSerializable, Tickable { public class CustomBlockEntity extends BlockEntity implements BlockEntityClientSerializable, Tickable {
private static int newObjID = 0; private static final Map<Identifier, Integer> newObjID = new HashMap<>();
private final Identifier id; private final Identifier id;
private final int objID; private final int objID;
@ -20,7 +23,10 @@ public class CustomBlockEntity extends BlockEntity implements BlockEntityClientS
public CustomBlockEntity(BlockEntityType<?> type, Identifier id) { public CustomBlockEntity(BlockEntityType<?> type, Identifier id) {
super(type); super(type);
this.id = id; this.id = id;
objID = newObjID++;
newObjID.putIfAbsent(id, 0);
objID = newObjID.get(id);
newObjID.put(id, newObjID.get(id) + 1);
QuickJSManager.bridge("CustomBlockEntity.create", id.toString(), (double) objID); QuickJSManager.bridge("CustomBlockEntity.create", id.toString(), (double) objID);
} }