mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-14 18:05:51 -04:00
block actions
This commit is contained in:
parent
d6370aff07
commit
bad0b12652
@ -0,0 +1,17 @@
|
||||
/*
|
||||
* Codename Minosoft
|
||||
* Copyright (C) 2020 Moritz Zwerger
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||
*/
|
||||
|
||||
package de.bixilon.minosoft.game.datatypes.blocks.actions;
|
||||
|
||||
public interface BlockAction {
|
||||
}
|
@ -0,0 +1,27 @@
|
||||
/*
|
||||
* Codename Minosoft
|
||||
* Copyright (C) 2020 Moritz Zwerger
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||
*/
|
||||
|
||||
package de.bixilon.minosoft.game.datatypes.blocks.actions;
|
||||
|
||||
public class ChestAction implements BlockAction {
|
||||
final byte playersLookingInChest;
|
||||
|
||||
public ChestAction(byte unused, byte playersLookingInChest) {
|
||||
this.playersLookingInChest = playersLookingInChest;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return playersLookingInChest > 0 ? String.format("CHEST_OPEN (%d)", playersLookingInChest) : "CHEST_CLOSE";
|
||||
}
|
||||
}
|
@ -0,0 +1,56 @@
|
||||
/*
|
||||
* Codename Minosoft
|
||||
* Copyright (C) 2020 Moritz Zwerger
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||
*/
|
||||
|
||||
package de.bixilon.minosoft.game.datatypes.blocks.actions;
|
||||
|
||||
public class NoteBlockAction implements BlockAction {
|
||||
final Instruments instrument;
|
||||
final byte pitch;
|
||||
|
||||
public NoteBlockAction(byte instrument, byte pitch) {
|
||||
this.instrument = Instruments.byId(instrument);
|
||||
this.pitch = pitch;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("NOTEBLOCK_%s:%d", instrument.name(), pitch);
|
||||
}
|
||||
|
||||
public enum Instruments {
|
||||
HARP(0),
|
||||
DOUBLE_BASS(1),
|
||||
SNARE_DRUM(2),
|
||||
CLICKS_STICKS(3),
|
||||
BASS_DRUM(4);
|
||||
|
||||
final byte id;
|
||||
|
||||
Instruments(int id) {
|
||||
this.id = (byte) id;
|
||||
}
|
||||
|
||||
public static Instruments byId(int id) {
|
||||
for (Instruments i : values()) {
|
||||
if (i.getId() == id) {
|
||||
return i;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public byte getId() {
|
||||
return id;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,55 @@
|
||||
/*
|
||||
* Codename Minosoft
|
||||
* Copyright (C) 2020 Moritz Zwerger
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||
*/
|
||||
|
||||
package de.bixilon.minosoft.game.datatypes.blocks.actions;
|
||||
|
||||
import de.bixilon.minosoft.game.datatypes.Direction;
|
||||
|
||||
public class PistonAction implements BlockAction {
|
||||
final PistonStates status;
|
||||
final Direction direction;
|
||||
|
||||
public PistonAction(byte status, byte direction) {
|
||||
this.status = PistonStates.byId(status);
|
||||
this.direction = Direction.byId(direction);
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("PISTON_%s:%s", status.name(), direction.name());
|
||||
}
|
||||
|
||||
public enum PistonStates {
|
||||
PUSH(0),
|
||||
PULL(1);
|
||||
|
||||
final byte id;
|
||||
|
||||
PistonStates(int id) {
|
||||
this.id = (byte) id;
|
||||
}
|
||||
|
||||
public static PistonStates byId(int id) {
|
||||
for (PistonStates s : values()) {
|
||||
if (s.getId() == id) {
|
||||
return s;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public byte getId() {
|
||||
return id;
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,81 @@
|
||||
/*
|
||||
* Codename Minosoft
|
||||
* Copyright (C) 2020 Moritz Zwerger
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License along with this program. If not, see <https://www.gnu.org/licenses/>.
|
||||
*
|
||||
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||
*/
|
||||
|
||||
package de.bixilon.minosoft.protocol.packets.clientbound.play;
|
||||
|
||||
import de.bixilon.minosoft.game.datatypes.blocks.actions.BlockAction;
|
||||
import de.bixilon.minosoft.game.datatypes.blocks.actions.ChestAction;
|
||||
import de.bixilon.minosoft.game.datatypes.blocks.actions.NoteBlockAction;
|
||||
import de.bixilon.minosoft.game.datatypes.blocks.actions.PistonAction;
|
||||
import de.bixilon.minosoft.game.datatypes.world.BlockPosition;
|
||||
import de.bixilon.minosoft.logging.Log;
|
||||
import de.bixilon.minosoft.protocol.packets.ClientboundPacket;
|
||||
import de.bixilon.minosoft.protocol.protocol.InPacketBuffer;
|
||||
import de.bixilon.minosoft.protocol.protocol.PacketHandler;
|
||||
import de.bixilon.minosoft.protocol.protocol.ProtocolVersion;
|
||||
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
|
||||
public class PacketBlockAction implements ClientboundPacket {
|
||||
BlockPosition position;
|
||||
BlockAction data;
|
||||
|
||||
|
||||
@Override
|
||||
public void read(InPacketBuffer buffer, ProtocolVersion v) {
|
||||
switch (v) {
|
||||
case VERSION_1_7_10:
|
||||
position = buffer.readBlockPositionShort();
|
||||
byte byte1 = buffer.readByte();
|
||||
byte byte2 = buffer.readByte();
|
||||
Class<? extends BlockAction> clazz;
|
||||
switch (buffer.readVarInt()) {
|
||||
case 25:
|
||||
// noteblock
|
||||
clazz = NoteBlockAction.class;
|
||||
break;
|
||||
case 29:
|
||||
case 33:
|
||||
// piston
|
||||
clazz = PistonAction.class;
|
||||
break;
|
||||
case 54:
|
||||
case 130:
|
||||
case 146:
|
||||
// chest
|
||||
clazz = ChestAction.class;
|
||||
break;
|
||||
default:
|
||||
throw new IllegalStateException("Unexpected value: " + buffer.readVarInt());
|
||||
}
|
||||
try {
|
||||
data = clazz.getConstructor(byte.class, byte.class).newInstance(byte1, byte2);
|
||||
} catch (InstantiationException | IllegalAccessException | NoSuchMethodException | InvocationTargetException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void log() {
|
||||
Log.protocol(String.format("Block action received %s at %s", data.toString(), position.toString()));
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(PacketHandler h) {
|
||||
h.handle(this);
|
||||
}
|
||||
|
||||
}
|
@ -298,4 +298,8 @@ public class PacketHandler {
|
||||
public void handle(PacketBlockBreakAnimation pkg) {
|
||||
// ToDo
|
||||
}
|
||||
|
||||
public void handle(PacketBlockAction pkg) {
|
||||
// ToDo
|
||||
}
|
||||
}
|
||||
|
@ -85,6 +85,7 @@ public interface Protocol {
|
||||
packetClassMapping.put(Packets.Clientbound.PLAY_USE_BED, PacketUseBed.class);
|
||||
packetClassMapping.put(Packets.Clientbound.PLAY_BLOCK_ENTITY_DATA, PacketBlockEntityMetadata.class);
|
||||
packetClassMapping.put(Packets.Clientbound.PLAY_BLOCK_BREAK_ANIMATION, PacketBlockBreakAnimation.class);
|
||||
packetClassMapping.put(Packets.Clientbound.PLAY_BLOCK_ACTION, PacketBlockAction.class);
|
||||
}
|
||||
|
||||
int getProtocolVersion();
|
||||
|
Loading…
x
Reference in New Issue
Block a user