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

More redstone components #914

Open
wants to merge 86 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 14 commits
Commits
Show all changes
86 commits
Select commit Hold shift + click to select a range
fc376ca
Basic dispenser functionality
Creeperface01 Aug 11, 2019
ebd0365
Merge remote-tracking branch 'origin/master' into redstone
Creeperface01 Aug 11, 2019
538c819
Broken pistons implementation
Creeperface01 Aug 16, 2019
69ea148
fixed piston input power, plugin unknown dependency message
Creeperface01 Aug 18, 2019
079f47e
plugin unknown dependency message
Creeperface01 Aug 18, 2019
2aaa64d
fix build
Creeperface01 Aug 18, 2019
f608942
update
Creeperface01 Sep 17, 2019
e38921e
fixes
Creeperface01 Sep 18, 2019
4fc454d
update
Creeperface01 Oct 5, 2019
6318c0e
Fix slimeblocks
Creeperface01 Oct 12, 2019
55e12a1
Implement entity collision
Creeperface01 Oct 13, 2019
f2969ac
Dropper
Creeperface01 Oct 13, 2019
25b57ed
merge master
Creeperface01 Oct 13, 2019
c9d3a55
Bumb API version
Creeperface01 Oct 13, 2019
b0a1d5f
allow more digits in the API version
Creeperface01 Oct 15, 2019
717d44b
Add option to disable redstone
Creeperface01 Oct 16, 2019
b679e70
fix submodule
Creeperface01 Oct 20, 2019
38820ae
test
Creeperface01 Oct 20, 2019
3d7e846
test
Creeperface01 Oct 21, 2019
9004211
Fix submodule
Creeperface01 Oct 21, 2019
9a38c49
Fix duplication bug
Creeperface01 Oct 22, 2019
9ab951f
Fix dispenser duplication
Creeperface01 Oct 22, 2019
d323b52
Fix compatibility
Creeperface01 Oct 22, 2019
64de485
Prevent NPE
Creeperface01 Oct 22, 2019
bd2d2ba
Add BlockPistonEvent
Creeperface01 Oct 23, 2019
f1360be
Fix comparator updates
Creeperface01 Oct 24, 2019
23adeaa
Fix hopper disabled behavior
Creeperface01 Oct 24, 2019
4f2b31c
Fix default facing
Creeperface01 Oct 29, 2019
3a210f7
Add sounds and particles
Creeperface01 Oct 31, 2019
f2085eb
Merge remote-tracking branch 'origin/redstone' into redstone
Creeperface01 Oct 31, 2019
56c0840
Merge 1.13
Creeperface01 Nov 3, 2019
4923c51
Fix piston retracting
Creeperface01 Nov 3, 2019
ae01cd3
Merge remote-tracking branch 'origin/bedrock-1.13' into redstone
Creeperface01 Nov 23, 2019
3a96364
ops
Creeperface01 Nov 23, 2019
d02f415
Static access
Creeperface01 Nov 23, 2019
78e98f7
Fix palette
Creeperface01 Nov 24, 2019
405f23c
Merge remote-tracking branch 'remotes/origin/master' into redstone
Creeperface01 Nov 30, 2019
bd8f5bc
ops
Creeperface01 Nov 30, 2019
b9dd554
Remove debug message left by @Creeperface01 :)
SupremeMortal Nov 30, 2019
334fef0
Merge branch 'master' of https://github.com/NukkitX/Nukkit into redstone
SupremeMortal Nov 30, 2019
9511c34
Merge remote-tracking branch 'origin/redstone' into redstone
SupremeMortal Nov 30, 2019
ae2e7b9
Merge remote-tracking branch 'remotes/origin/master' into redstone
Creeperface01 Dec 9, 2019
d53a270
Merge remote-tracking branch 'origin/redstone' into redstone
Creeperface01 Dec 9, 2019
180fefe
Fix redstone wire placement
Creeperface01 Dec 9, 2019
7bab7c7
Fix block names
Creeperface01 Dec 9, 2019
a79a861
ops
Creeperface01 Dec 9, 2019
294d397
Bump protocol version to 389
SupremeMortal Dec 10, 2019
bb3aad2
Support 1.13 and 1.14
SupremeMortal Dec 10, 2019
eb68985
Merge branch 'master' of https://github.com/NukkitX/Nukkit into redstone
SupremeMortal Dec 10, 2019
f3ab3af
Merge remote-tracking branch 'remotes/origin/bedrock-1.14' into redstone
Creeperface01 Dec 11, 2019
66bf314
Merge remote-tracking branch 'origin/redstone' into redstone
Creeperface01 Dec 12, 2019
a488f71
Merge remote-tracking branch 'remotes/origin/master' into redstone
Creeperface01 Dec 13, 2019
288724c
Fix comparator immediate update
Creeperface01 Dec 15, 2019
8e8d63b
Fix block updates
Creeperface01 Dec 15, 2019
65d96c6
don't push extended pistons
Creeperface01 Dec 15, 2019
7f9086d
Fix pistons behavior
Creeperface01 Dec 21, 2019
02ac8a3
Merge remote-tracking branch 'remotes/origin/master' into redstone
Creeperface01 Dec 21, 2019
a6f99d5
Drop painting when pushed
Creeperface01 Dec 24, 2019
73fb1a2
Merge remote-tracking branch 'remotes/origin/master' into redstone
Creeperface01 Dec 30, 2019
5be10a9
Don't create new BlockEntityPiston instance directly
Creeperface01 Dec 30, 2019
bd3efa1
Fix buttons
Creeperface01 Jan 2, 2020
e2407f2
Merge remote-tracking branch 'origin/redstone' into redstone
Creeperface01 Jan 2, 2020
d7de1ef
Fixed piston bug
Creeperface01 Jan 2, 2020
8a3c56e
Fix piston placement
Creeperface01 Jan 2, 2020
6211594
Merge remote-tracking branch 'remotes/origin/master' into redstone
Creeperface01 Jan 4, 2020
d46a4d7
Don't use player instance in async event
Creeperface01 Jan 4, 2020
d72138b
merge
Creeperface01 Jan 9, 2020
d5193af
Merge branch 'master' of https://github.com/NukkitX/Nukkit into redstone
SupremeMortal Jan 10, 2020
aa12ad7
Merge remote-tracking branch 'remotes/origin/master' into redstone
Creeperface01 Jan 11, 2020
5931d91
Fix redstone torch and piston update
Creeperface01 Jan 12, 2020
a9e676d
Merge branches 'master' and 'redstone' of https://github.com/NukkitX/…
SupremeMortal Feb 12, 2020
ad292d8
Merge branch 'master' of https://github.com/NukkitX/Nukkit into redstone
SupremeMortal Mar 16, 2020
066244e
Merge branches 'master' and 'redstone' of https://github.com/NukkitX/…
SupremeMortal Apr 5, 2020
925f472
Merge branch 'master' of https://github.com/NukkitX/Nukkit into redstone
SupremeMortal Apr 5, 2020
714317c
Merge branch 'master' of https://github.com/NukkitX/Nukkit into redstone
SupremeMortal Apr 6, 2020
bfcfde9
Merge branch 'master' of https://github.com/NukkitX/Nukkit into redstone
SupremeMortal Apr 16, 2020
2cdd822
Merge branch 'master' of https://github.com/NukkitX/Nukkit into redstone
SupremeMortal Apr 16, 2020
4f24a4e
Merge branch 'master' of https://github.com/NukkitX/Nukkit into redstone
SupremeMortal Apr 29, 2020
fa2db54
Merge branch 'master' of https://github.com/NukkitX/Nukkit into redstone
SupremeMortal Apr 30, 2020
8344d9f
[Redstone] Updates from master branch (#1419)
AlicanCopur May 10, 2020
701f543
Merge pull request #1480 from NukkitX/master
SupremeMortal Jun 5, 2020
5b70933
Merge branch 'master' into redstone
Sleepybear Jul 14, 2020
b5b5af0
Merge branch 'master' into redstone
Sleepybear Sep 26, 2020
15da21f
merge master into redstone - fix build
Sleepybear Sep 26, 2020
9e6612d
Redstone 1.16.210 Support (#1817)
FlamingKnight Mar 28, 2021
cc74955
Redstone update for 1.16.221 (#1837)
FlamingKnight May 11, 2021
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
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -232,3 +232,4 @@ creativeitems.json
recipes.json
data/
data/*
/src/main/resources/rebel.xml
2 changes: 1 addition & 1 deletion src/main/java/cn/nukkit/Nukkit.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class Nukkit {

public final static Properties GIT_INFO = getGitInfo();
public final static String VERSION = getVersion();
public final static String API_VERSION = "1.0.9";
public final static String API_VERSION = "1.0.10";
public final static String CODENAME = "";
@Deprecated
public final static String MINECRAFT_VERSION = ProtocolInfo.MINECRAFT_VERSION;
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/cn/nukkit/Player.java
Original file line number Diff line number Diff line change
Expand Up @@ -1022,7 +1022,7 @@ public boolean batchDataPacket(DataPacket packet) {
return false;
}

try (Timing timing = Timings.getSendDataPacketTiming(packet)) {
try (Timing ignored = Timings.getSendDataPacketTiming(packet)) {
DataPacketSendEvent event = new DataPacketSendEvent(this, packet);
this.server.getPluginManager().callEvent(event);
if (event.isCancelled()) {
Expand Down Expand Up @@ -1064,7 +1064,7 @@ public int dataPacket(DataPacket packet, boolean needACK) {
Integer identifier = this.interfaz.putPacket(this, packet, needACK, false);

if (needACK && identifier != null) {
this.needACK.put(identifier, Boolean.FALSE);
this.needACK.put(identifier.intValue(), Boolean.FALSE);
return identifier;
}
}
Expand Down
10 changes: 9 additions & 1 deletion src/main/java/cn/nukkit/Server.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import cn.nukkit.blockentity.*;
import cn.nukkit.command.*;
import cn.nukkit.console.NukkitConsole;
import cn.nukkit.dispenser.DispenseBehaviorRegister;
import cn.nukkit.entity.Attribute;
import cn.nukkit.entity.Entity;
import cn.nukkit.entity.EntityHuman;
Expand Down Expand Up @@ -453,6 +454,7 @@ public Level remove(Object key) {
Effect.init();
Potion.init();
Attribute.init();
DispenseBehaviorRegister.init();
GlobalBlockPalette.getOrCreateRuntimeId(0, 0); //Force it to load

// Convert legacy data before plugins get the chance to mess with it.
Expand Down Expand Up @@ -742,8 +744,11 @@ public boolean dispatchCommand(CommandSender sender, String commandLine) throws
if (!this.isPrimaryThread()) {
getLogger().warning("Command Dispatched Async: " + commandLine);
getLogger().warning("Please notify author of plugin causing this execution to fix this bug!", new Throwable());
// TODO: We should sync the command to the main thread too!

this.scheduler.scheduleTask(null, () -> dispatchCommand(sender, commandLine));
return true;
}

if (sender == null) {
throw new ServerException("CommandSender is not valid");
}
Expand Down Expand Up @@ -2329,6 +2334,9 @@ private void registerBlockEntities() {
BlockEntity.registerBlockEntity(BlockEntity.SHULKER_BOX, BlockEntityShulkerBox.class);
BlockEntity.registerBlockEntity(BlockEntity.BANNER, BlockEntityBanner.class);
BlockEntity.registerBlockEntity(BlockEntity.MUSIC, BlockEntityMusic.class);
BlockEntity.registerBlockEntity(BlockEntity.DISPENSER, BlockEntityDispenser.class);
BlockEntity.registerBlockEntity(BlockEntity.DROPPER, BlockEntityDropper.class);
BlockEntity.registerBlockEntity(BlockEntity.MOVING_BLOCK, BlockEntityMovingBlock.class);
}

public boolean isNetherAllowed() {
Expand Down
9 changes: 6 additions & 3 deletions src/main/java/cn/nukkit/block/Block.java
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ public static void init() {
list[DRAGON_EGG] = BlockDragonEgg.class; //122
list[REDSTONE_LAMP] = BlockRedstoneLamp.class; //123
list[LIT_REDSTONE_LAMP] = BlockRedstoneLampLit.class; //124
//TODO: list[DROPPER] = BlockDropper.class; //125
list[DROPPER] = BlockDropper.class; //125
list[ACTIVATOR_RAIL] = BlockRailActivator.class; //126
list[COCOA] = BlockCocoa.class; //127
list[SANDSTONE_STAIRS] = BlockStairsSandstone.class; //128
Expand Down Expand Up @@ -296,8 +296,7 @@ public static void init() {
list[GLOWING_OBSIDIAN] = BlockObsidianGlowing.class; //246
//list[NETHER_REACTOR] = BlockNetherReactor.class; //247 Should not be removed

//TODO: list[PISTON_EXTENSION] = BlockPistonExtension.class; //250

list[MOVING_BLOCK] = BlockMoving.class; //250
list[OBSERVER] = BlockObserver.class; //251

for (int id = 0; id < 256; id++) {
Expand Down Expand Up @@ -691,6 +690,10 @@ public Block getSide(BlockFace face) {
}

public Block getSide(BlockFace face, int step) {
if (step == 0) {
return this;
}

if (this.isValid()) {
if (step == 1) {
return this.getLevel().getBlock((int) x + face.getXOffset(), (int) y + face.getYOffset(), (int) z + face.getZOffset());
Expand Down
182 changes: 166 additions & 16 deletions src/main/java/cn/nukkit/block/BlockDispenser.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,24 @@
package cn.nukkit.block;

import cn.nukkit.Player;
import cn.nukkit.blockentity.BlockEntity;
import cn.nukkit.blockentity.BlockEntityDispenser;
import cn.nukkit.dispenser.DispenseBehavior;
import cn.nukkit.dispenser.DispenseBehaviorRegister;
import cn.nukkit.inventory.ContainerInventory;
import cn.nukkit.inventory.Inventory;
import cn.nukkit.inventory.InventoryHolder;
import cn.nukkit.item.Item;
import cn.nukkit.item.ItemBlock;
import cn.nukkit.level.Level;
import cn.nukkit.math.BlockFace;
import cn.nukkit.math.Vector3;
import cn.nukkit.utils.Faceable;

import java.util.Map.Entry;
import java.util.Random;
import java.util.concurrent.ThreadLocalRandom;

/**
* Created by CreeperFace on 15.4.2017.
*/
Expand Down Expand Up @@ -41,17 +54,13 @@ public Item toItem() {

@Override
public int getComparatorInputOverride() {
/*BlockEntity blockEntity = this.level.getBlockEntity(this);

if(blockEntity instanceof BlockEntityDispenser) {
//return ContainerInventory.calculateRedstone(((BlockEntityDispenser) blockEntity).getInventory()); TODO: dispenser
}*/
BlockEntity blockEntity = this.level.getBlockEntity(this);

return super.getComparatorInputOverride();
}
if (blockEntity instanceof BlockEntityDispenser) {
return ContainerInventory.calculateRedstone(((BlockEntityDispenser) blockEntity).getInventory());
}

public BlockFace getFacing() {
return BlockFace.fromIndex(this.getDamage() & 7);
return 0;
}

public boolean isTriggered() {
Expand All @@ -60,7 +69,7 @@ public boolean isTriggered() {

public void setTriggered(boolean value) {
int i = 0;
i |= getFacing().getIndex();
i |= getBlockFace().getIndex();

if (value) {
i |= 8;
Expand All @@ -69,21 +78,162 @@ public void setTriggered(boolean value) {
this.setDamage(i);
}

@Override
public boolean canBeActivated() {
return true;
}

@Override
public boolean onActivate(Item item, Player player) {
if (player == null) {
return false;
}

InventoryHolder blockEntity = getBlockEntity();

if (blockEntity == null) {
return false;
}

player.addWindow(blockEntity.getInventory());
return true;
}

@Override
public boolean place(Item item, Block block, Block target, BlockFace face, double fx, double fy, double fz, Player player) {
if (player != null) {
if (Math.abs(player.x - this.x) < 2 && Math.abs(player.z - this.z) < 2) {
double y = player.y + player.getEyeHeight();

if (y - this.y > 2) {
this.setDamage(BlockFace.UP.getIndex());
} else if (this.y - y > 0) {
this.setDamage(BlockFace.DOWN.getIndex());
} else {
this.setDamage(player.getHorizontalFacing().getOpposite().getIndex());
}
} else {
this.setDamage(player.getHorizontalFacing().getOpposite().getIndex());
}
}

this.getLevel().setBlock(block, this, true);

createBlockEntity();
return true;
}

protected void createBlockEntity() {
new BlockEntityDispenser(this.level.getChunk(getChunkX(), getChunkZ()),
BlockEntity.getDefaultCompound(this, BlockEntity.DISPENSER));
}

protected InventoryHolder getBlockEntity() {
BlockEntity blockEntity = this.level.getBlockEntity(this);

if (!(blockEntity instanceof BlockEntityDispenser)) {
return null;
}

return (InventoryHolder) blockEntity;
}

@Override
public int onUpdate(int type) {
if (type == Level.BLOCK_UPDATE_SCHEDULED) {
this.setTriggered(false);
this.level.setBlock(this, this, false, false);

dispense();
return type;
} else if (type == Level.BLOCK_UPDATE_REDSTONE) {
Vector3 pos = this.add(0);

boolean powered = level.isBlockPowered(pos) || level.isBlockPowered(pos.up());
boolean triggered = isTriggered();

if (powered && !triggered) {
this.setTriggered(true);
this.level.setBlock(this, this, false, false);
level.scheduleUpdate(this, this, 4);
}

return type;
}

return 0;
}

public void dispense() {
InventoryHolder blockEntity = getBlockEntity();

if (blockEntity == null) {
return;
}

Random rand = ThreadLocalRandom.current();
int r = 1;
int slot = -1;
Item target = null;

Inventory inv = blockEntity.getInventory();
for (Entry<Integer, Item> entry : inv.getContents().entrySet()) {
Item item = entry.getValue();

if (!item.isNull() && rand.nextInt(r++) == 0) {
target = item;
slot = entry.getKey();
}
}

if (target == null) {
// this.level.addLevelSoundEvent(this); //TODO: sound
return;
}
Item origin = target;
target = target.clone();

DispenseBehavior behavior = getDispenseBehavior(target);
Item result = behavior.dispense(this, getBlockFace(), target);

if (result == null) {
target.count--;
inv.setItem(slot, target);
} else {
if (result.getId() != origin.getId() || result.getDamage() != origin.getDamage()) {
Item[] fit = inv.addItem(result);

if (fit.length > 0) {
for (Item drop : fit) {
this.level.dropItem(this, drop);
}
}
} else {
inv.setItem(slot, result);
}
}
}

protected DispenseBehavior getDispenseBehavior(Item item) {
return DispenseBehaviorRegister.getBehavior(item.getId());
}

@Override
public boolean canHarvestWithHand() {
return false;
}

public Vector3 getDispensePosition() {
BlockFace facing = getFacing();
double x = this.getX() + 0.7 * facing.getXOffset();
double y = this.getY() + 0.7 * facing.getYOffset();
double z = this.getZ() + 0.7 * facing.getZOffset();
return new Vector3(x, y, z);
BlockFace facing = getBlockFace();
return this.add(
0.5 + 0.7 * facing.getXOffset(),
0.5 + 0.7 * facing.getYOffset(),
0.5 + 0.7 * facing.getZOffset()
);
}

@Override
public BlockFace getBlockFace() {
return BlockFace.fromHorizontalIndex(this.getDamage() & 0x07);
return BlockFace.fromIndex(this.getDamage() & 0x07);
}
}
56 changes: 56 additions & 0 deletions src/main/java/cn/nukkit/block/BlockDropper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
package cn.nukkit.block;

import cn.nukkit.blockentity.BlockEntity;
import cn.nukkit.blockentity.BlockEntityDropper;
import cn.nukkit.dispenser.DefaultDispenseBehavior;
import cn.nukkit.dispenser.DispenseBehavior;
import cn.nukkit.inventory.InventoryHolder;
import cn.nukkit.item.Item;

public class BlockDropper extends BlockDispenser {

public BlockDropper() {
this(0);
}

public BlockDropper(int meta) {
super(meta);
}

@Override
public String getName() {
return "Dropper";
}

@Override
public int getId() {
return DROPPER;
}

@Override
public void dispense() {
super.dispense();
}

@Override
protected void createBlockEntity() {
new BlockEntityDropper(this.level.getChunk(getChunkX(), getChunkZ()),
BlockEntity.getDefaultCompound(this, BlockEntity.DROPPER));
}

@Override
protected InventoryHolder getBlockEntity() {
BlockEntity blockEntity = this.level.getBlockEntity(this);

if (!(blockEntity instanceof BlockEntityDropper)) {
return null;
}

return (InventoryHolder) blockEntity;
}

@Override
protected DispenseBehavior getDispenseBehavior(Item item) {
return new DefaultDispenseBehavior();
}
}
2 changes: 1 addition & 1 deletion src/main/java/cn/nukkit/block/BlockEndPortalFrame.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ public boolean canBeActivated() {

@Override
public boolean onActivate(Item item, Player player) {
if((this.getDamage() & 0x04) == 0 && player != null && item.getId() == Item.ENDER_EYE) {
if ((this.getDamage() & 0x04) == 0 && player != null && item.getId() == Item.ENDER_EYE) {
this.setDamage(this.getDamage() + 4);
this.getLevel().setBlock(this, this, true, true);
this.getLevel().addLevelSoundEvent(this, LevelSoundEventPacket.SOUND_BLOCK_END_PORTAL_FRAME_FILL);
Expand Down
Loading