Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[2.0] Add DaylightDetector block entity (#1337) #1345

Merged
merged 2 commits into from
Apr 17, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package cn.nukkit.blockentity.impl;

import cn.nukkit.block.BlockDaylightDetector;
import cn.nukkit.block.BlockIds;
import cn.nukkit.blockentity.BlockEntityType;
import cn.nukkit.blockentity.DaylightDetector;
import cn.nukkit.level.chunk.Chunk;
import cn.nukkit.utils.Identifier;
import com.nukkitx.math.vector.Vector3i;
import com.nukkitx.nbt.CompoundTagBuilder;
import com.nukkitx.nbt.tag.CompoundTag;

public class DaylightDetectorBlockEntity extends BaseBlockEntity implements DaylightDetector {

private int redstoneSignal;

public DaylightDetectorBlockEntity(BlockEntityType<?> type, Chunk chunk, Vector3i position) {
super(type, chunk, position);
}

@Override
public boolean isValid() {
Identifier blockId = getBlock().getId();
return blockId == BlockIds.DAYLIGHT_DETECTOR || blockId == BlockIds.DAYLIGHT_DETECTOR_INVERTED;
}

@Override
public void loadAdditionalData(CompoundTag tag) {
super.loadAdditionalData(tag);

tag.listenForInt("redstone_signal", this::setRedstoneSignal);
}

@Override
public void saveAdditionalData(CompoundTagBuilder tag) {
super.saveAdditionalData(tag);

tag.intTag("redstone_signal", this.getRedstoneSignal());
CiviledCode marked this conversation as resolved.
Show resolved Hide resolved
}

public int getRedstoneSignal() {
return redstoneSignal;
}

public void setRedstoneSignal(int redstoneSignal) {
this.redstoneSignal = redstoneSignal;
}
}
2 changes: 1 addition & 1 deletion src/main/java/cn/nukkit/registry/BlockEntityRegistry.java
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ private void registerVanillaEntities() {
registerVanilla(SKULL, SkullBlockEntity::new, "Skull");
registerVanilla(FLOWER_POT, FlowerPotBlockEntity::new, "FlowerPot");
registerVanilla(BREWING_STAND, BrewingStandBlockEntity::new, "BrewingStand");
//registerVanilla(DAYLIGHT_DETECTOR, DaylightDetectorBlockEntity::new, "DaylightDetector");
registerVanilla(DAYLIGHT_DETECTOR, DaylightDetectorBlockEntity::new, "DaylightDetector");
registerVanilla(NOTEBLOCK, MusicBlockEntity::new, "Music");
registerVanilla(ITEM_FRAME, ItemFrameBlockEntity::new, "ItemFrame");
registerVanilla(CAULDRON, CauldronBlockEntity::new, "Cauldron");
Expand Down