mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-16 02:45:13 -04:00
fixes, particle parser
This commit is contained in:
parent
f1080fd6ac
commit
7f31dcaf21
@ -54,8 +54,8 @@ import java.util.UUID;
|
||||
|
||||
public final class Minosoft {
|
||||
public static final HashSet<EventManager> EVENT_MANAGERS = new HashSet<>();
|
||||
private static final CountUpAndDownLatch START_STATUS_LATCH = new CountUpAndDownLatch(1);
|
||||
public static final HashBiMap<Integer, Connection> CONNECTIONS = HashBiMap.create();
|
||||
private static final CountUpAndDownLatch START_STATUS_LATCH = new CountUpAndDownLatch(1);
|
||||
public static Configuration config;
|
||||
|
||||
public static void main(String[] args) {
|
||||
|
@ -67,13 +67,13 @@ public abstract class Account {
|
||||
return getId().equals(account.getId());
|
||||
}
|
||||
|
||||
public void saveToConfig() {
|
||||
Minosoft.getConfig().putAccount(this);
|
||||
Minosoft.getConfig().saveToFile();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getId();
|
||||
}
|
||||
|
||||
public void saveToConfig() {
|
||||
Minosoft.getConfig().putAccount(this);
|
||||
Minosoft.getConfig().saveToFile();
|
||||
}
|
||||
}
|
||||
|
@ -75,7 +75,7 @@ public class AssetsManager {
|
||||
return;
|
||||
}
|
||||
try {
|
||||
downloadAssetsIndex();
|
||||
downloadAssetsIndex();
|
||||
} catch (Exception e) {
|
||||
Log.printException(e, LogLevels.DEBUG);
|
||||
Log.warn("Could not download assets index. Please check your internet connection");
|
||||
|
@ -15,6 +15,7 @@ package de.bixilon.minosoft.data.commands.parser
|
||||
import de.bixilon.minosoft.data.commands.CommandStringReader
|
||||
import de.bixilon.minosoft.data.commands.parser.exceptions.*
|
||||
import de.bixilon.minosoft.data.commands.parser.properties.ParserProperties
|
||||
import de.bixilon.minosoft.data.mappings.blocks.Block
|
||||
import de.bixilon.minosoft.data.mappings.blocks.BlockProperties
|
||||
import de.bixilon.minosoft.data.mappings.blocks.BlockRotations
|
||||
import de.bixilon.minosoft.protocol.network.Connection
|
||||
@ -22,7 +23,7 @@ import de.bixilon.minosoft.protocol.network.Connection
|
||||
class BlockStateParser : CommandParser() {
|
||||
|
||||
@Throws(CommandParseException::class)
|
||||
override fun parse(connection: Connection, properties: ParserProperties?, stringReader: CommandStringReader): Any? {
|
||||
override fun parse(connection: Connection, properties: ParserProperties?, stringReader: CommandStringReader): Block? {
|
||||
if (this == BLOCK_PREDICATE_PARSER) {
|
||||
if (stringReader.peek() != '#') {
|
||||
throw InvalidBlockPredicateCommandParseException(stringReader, stringReader.read().toString())
|
||||
@ -30,6 +31,7 @@ class BlockStateParser : CommandParser() {
|
||||
stringReader.skip()
|
||||
}
|
||||
val identifier = stringReader.readModIdentifier() // ToDo: check tags
|
||||
var block = Block(identifier.value.mod, identifier.value.identifier)
|
||||
if (!connection.mapping.doesBlockExist(identifier.value)) {
|
||||
throw BlockNotFoundCommandParseException(stringReader, identifier.key)
|
||||
}
|
||||
@ -54,14 +56,16 @@ class BlockStateParser : CommandParser() {
|
||||
val blockProperty = blockPropertyKey[pair.value] ?: throw UnknownBlockPropertyCommandParseException(stringReader, pair.value)
|
||||
allProperties.add(blockProperty)
|
||||
}
|
||||
block = Block(identifier.value.mod, identifier.value.identifier, allProperties, rotation)
|
||||
}
|
||||
|
||||
if (this == BLOCK_PREDICATE_PARSER) {
|
||||
if (stringReader.canRead() && stringReader.peek() == '{') {
|
||||
stringReader.readNBTCompoundTag()
|
||||
}
|
||||
return null // ToDo
|
||||
}
|
||||
return null // ToDo
|
||||
return block
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
@ -40,11 +40,11 @@ object CommandParsers {
|
||||
ModIdentifier("component") to ComponentParser.COMPONENT_PARSER,
|
||||
ModIdentifier("message") to MessageParser.MESSAGE_PARSER,
|
||||
ModIdentifier("nbt") to NBTParser.NBT_PARSER,
|
||||
// nbt_path
|
||||
// ToDo: nbt_path
|
||||
ModIdentifier("objective") to ObjectiveParser.OBJECTIVE_PARSER,
|
||||
// objective_criteria
|
||||
// ToDo: objective_criteria
|
||||
ModIdentifier("operation") to OperationParser.OPERATION_PARSER,
|
||||
// particle
|
||||
ModIdentifier("particle") to ParticleParser.PARTICLE_PARSER,
|
||||
ModIdentifier("rotation") to RotationParser.ROTATION_PARSER,
|
||||
ModIdentifier("scoreboard_slot") to ScoreboardSlotParser.SCOREBOARD_SLOT_PARSER,
|
||||
ModIdentifier("score_holder") to ScoreHolderParser.SCORE_HOLDER_PARSER,
|
||||
@ -53,8 +53,8 @@ object CommandParsers {
|
||||
ModIdentifier("item_slot") to ItemSlotParser.ITEM_SLOT_PARSER,
|
||||
ModIdentifier("resource_location") to IdentifierParser.IDENTIFIER_PARSER,
|
||||
ModIdentifier("mob_effect") to IdentifierListParser.MOB_EFFECT_PARSER,
|
||||
// function
|
||||
// entity_anchor
|
||||
// ToDo: function
|
||||
// ToDo: entity_anchor
|
||||
ModIdentifier("range") to RangeParser.RANGE_PARSER,
|
||||
ModIdentifier("int_range") to IntRangeParser.INT_RANGE_PARSER,
|
||||
ModIdentifier("float_range") to FloatRangeParser.FLOAT_RANGE_PARSER,
|
||||
|
@ -21,7 +21,7 @@ import de.bixilon.minosoft.protocol.network.Connection
|
||||
class ItemSlotParser : CommandParser() {
|
||||
|
||||
@Throws(CommandParseException::class)
|
||||
override fun parse(connection: Connection, properties: ParserProperties?, stringReader: CommandStringReader): Any? {
|
||||
override fun parse(connection: Connection, properties: ParserProperties?, stringReader: CommandStringReader): Any {
|
||||
val slot = stringReader.readUnquotedString()
|
||||
|
||||
if (!SLOTS.contains(slot)) {
|
||||
|
@ -17,12 +17,15 @@ import de.bixilon.minosoft.data.commands.parser.exceptions.CommandParseException
|
||||
import de.bixilon.minosoft.data.commands.parser.exceptions.InvalidItemPredicateCommandParseException
|
||||
import de.bixilon.minosoft.data.commands.parser.exceptions.identifier.ItemNotFoundCommandParseException
|
||||
import de.bixilon.minosoft.data.commands.parser.properties.ParserProperties
|
||||
import de.bixilon.minosoft.data.inventory.Slot
|
||||
import de.bixilon.minosoft.data.mappings.Item
|
||||
import de.bixilon.minosoft.protocol.network.Connection
|
||||
import de.bixilon.minosoft.util.nbt.tag.CompoundTag
|
||||
|
||||
class ItemStackParser : CommandParser() {
|
||||
|
||||
@Throws(CommandParseException::class)
|
||||
override fun parse(connection: Connection, properties: ParserProperties?, stringReader: CommandStringReader): Any? {
|
||||
override fun parse(connection: Connection, properties: ParserProperties?, stringReader: CommandStringReader): Slot {
|
||||
if (this == ITEM_PREDICATE_PARSER) {
|
||||
if (stringReader.peek() != '#') {
|
||||
throw InvalidItemPredicateCommandParseException(stringReader, stringReader.read().toString())
|
||||
@ -33,10 +36,11 @@ class ItemStackParser : CommandParser() {
|
||||
if (!connection.mapping.doesItemExist(argument.value)) {
|
||||
throw ItemNotFoundCommandParseException(stringReader, argument.key)
|
||||
}
|
||||
var nbt: CompoundTag? = null
|
||||
if (stringReader.peek() == '{') {
|
||||
stringReader.readNBTCompoundTag()
|
||||
nbt = stringReader.readNBTCompoundTag()
|
||||
}
|
||||
return null // ToDo
|
||||
return Slot(connection.mapping, Item(argument.value.mod, argument.value.identifier), 1, nbt)
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
@ -0,0 +1,62 @@
|
||||
/*
|
||||
* 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.data.commands.parser
|
||||
|
||||
import de.bixilon.minosoft.data.commands.CommandStringReader
|
||||
import de.bixilon.minosoft.data.commands.parser.exceptions.CommandParseException
|
||||
import de.bixilon.minosoft.data.commands.parser.exceptions.identifier.ParticleNotFoundCommandParseException
|
||||
import de.bixilon.minosoft.data.commands.parser.properties.ParserProperties
|
||||
import de.bixilon.minosoft.data.mappings.particle.Particle
|
||||
import de.bixilon.minosoft.data.mappings.particle.data.BlockParticleData
|
||||
import de.bixilon.minosoft.data.mappings.particle.data.DustParticleData
|
||||
import de.bixilon.minosoft.data.mappings.particle.data.ItemParticleData
|
||||
import de.bixilon.minosoft.data.mappings.particle.data.ParticleData
|
||||
import de.bixilon.minosoft.protocol.network.Connection
|
||||
|
||||
class ParticleParser : CommandParser() {
|
||||
|
||||
@Throws(CommandParseException::class)
|
||||
override fun parse(connection: Connection, properties: ParserProperties?, stringReader: CommandStringReader): ParticleData {
|
||||
val identifier = stringReader.readModIdentifier()
|
||||
|
||||
if (!connection.mapping.doesParticleExist(identifier.value)) {
|
||||
throw ParticleNotFoundCommandParseException(stringReader, identifier.key)
|
||||
}
|
||||
val particle = Particle(identifier.value.fullIdentifier)
|
||||
|
||||
stringReader.skipWhitespaces()
|
||||
|
||||
return when (identifier.value.fullIdentifier) {
|
||||
"minecraft:block", "minecraft:falling_dust" -> BlockParticleData(BlockStateParser.BLOCK_STACK_PARSER.parse(connection, properties, stringReader), particle)
|
||||
"minecraft:dust" -> {
|
||||
val red = stringReader.readFloat()
|
||||
stringReader.skipWhitespaces()
|
||||
val green = stringReader.readFloat()
|
||||
stringReader.skipWhitespaces()
|
||||
val blue = stringReader.readFloat()
|
||||
stringReader.skipWhitespaces()
|
||||
val scale = stringReader.readFloat()
|
||||
|
||||
DustParticleData(red, green, blue, scale, particle)
|
||||
}
|
||||
"minecraft:item" -> {
|
||||
ItemParticleData(ItemStackParser.ITEM_STACK_PARSER.parse(connection, properties, stringReader), particle)
|
||||
}
|
||||
else -> ParticleData(particle)
|
||||
}
|
||||
}
|
||||
|
||||
companion object {
|
||||
val PARTICLE_PARSER = ParticleParser()
|
||||
}
|
||||
}
|
@ -0,0 +1,26 @@
|
||||
/*
|
||||
* 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.data.commands.parser.exceptions.identifier
|
||||
|
||||
import de.bixilon.minosoft.data.commands.CommandStringReader
|
||||
import de.bixilon.minosoft.data.commands.parser.exceptions.CommandParseException
|
||||
|
||||
class ParticleNotFoundCommandParseException : CommandParseException {
|
||||
constructor(command: CommandStringReader, currentArgument: String) : super(ERROR_MESSAGE, command, currentArgument)
|
||||
|
||||
constructor(command: CommandStringReader, currentArgument: String, cause: Throwable) : super(ERROR_MESSAGE, command, currentArgument, cause)
|
||||
|
||||
companion object {
|
||||
private const val ERROR_MESSAGE = "Particle not found!"
|
||||
}
|
||||
}
|
@ -163,6 +163,11 @@ public class Slot {
|
||||
return their.getItem().equals(getItem()) && their.getItemCount() == getItemCount() && their.getItemMetadata() == getItemMetadata();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getDisplayName();
|
||||
}
|
||||
|
||||
public Item getItem() {
|
||||
return this.item;
|
||||
}
|
||||
@ -184,11 +189,6 @@ public class Slot {
|
||||
this.itemMetadata = itemMetadata;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return getDisplayName();
|
||||
}
|
||||
|
||||
public String getDisplayName() {
|
||||
ChatComponent customName = getCustomDisplayName();
|
||||
if (customName != null) {
|
||||
|
@ -60,6 +60,28 @@ public class Block extends ModIdentifier {
|
||||
return this.properties;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(this.mod, this.identifier, this.properties, this.rotation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (hashCode() != obj.hashCode()) {
|
||||
return false;
|
||||
}
|
||||
if (obj instanceof Block their) {
|
||||
return getIdentifier().equals(their.getIdentifier()) && getRotation() == their.getRotation() && getProperties().equals(their.getProperties()) && getMod().equals(their.getMod());
|
||||
}
|
||||
if (obj instanceof ModIdentifier identifier) {
|
||||
return super.equals(identifier);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder out = new StringBuilder();
|
||||
@ -82,26 +104,4 @@ public class Block extends ModIdentifier {
|
||||
}
|
||||
return String.format("%s%s", getFullIdentifier(), out);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return Objects.hash(this.mod, this.identifier, this.properties, this.rotation);
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (this == obj) {
|
||||
return true;
|
||||
}
|
||||
if (hashCode() != obj.hashCode()) {
|
||||
return false;
|
||||
}
|
||||
if (obj instanceof Block their) {
|
||||
return getIdentifier().equals(their.getIdentifier()) && getRotation() == their.getRotation() && getProperties().equals(their.getProperties()) && getMod().equals(their.getMod());
|
||||
}
|
||||
if (obj instanceof ModIdentifier identifier) {
|
||||
return super.equals(identifier);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
@ -96,14 +96,6 @@ public class Version {
|
||||
return getVersionId();
|
||||
}
|
||||
|
||||
public int getProtocolId() {
|
||||
return this.protocolId;
|
||||
}
|
||||
|
||||
public boolean isLoaded() {
|
||||
return getMapping() != null && getMapping().isFullyLoaded();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (super.equals(obj)) {
|
||||
@ -122,4 +114,12 @@ public class Version {
|
||||
public String toString() {
|
||||
return getVersionName();
|
||||
}
|
||||
|
||||
public int getProtocolId() {
|
||||
return this.protocolId;
|
||||
}
|
||||
|
||||
public boolean isLoaded() {
|
||||
return getMapping() != null && getMapping().isFullyLoaded();
|
||||
}
|
||||
}
|
||||
|
@ -615,4 +615,13 @@ public class VersionMapping {
|
||||
return this.dimensionMap.containsValue(identifier);
|
||||
}
|
||||
|
||||
public boolean doesParticleExist(ModIdentifier identifier) {
|
||||
if (this.parentMapping != null) {
|
||||
if (this.parentMapping.doesParticleExist(identifier)) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return this.particleIdMap.containsValue(identifier);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -52,6 +52,14 @@ public class PacketBlockAction extends ClientboundPacket {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(Connection connection) {
|
||||
BlockActionEvent event = new BlockActionEvent(connection, this);
|
||||
if (connection.fireEvent(event)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
public BlockPosition getPosition() {
|
||||
return this.position;
|
||||
}
|
||||
@ -60,14 +68,6 @@ public class PacketBlockAction extends ClientboundPacket {
|
||||
return this.data;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void handle(Connection connection) {
|
||||
BlockActionEvent event = new BlockActionEvent(connection, this);
|
||||
if (connection.fireEvent(event)) {
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void log() {
|
||||
Log.protocol(String.format("[IN] Block action received %s at %s", this.data, this.position));
|
||||
|
@ -182,7 +182,7 @@ public class InByteBuffer {
|
||||
return this.bytes[this.position++];
|
||||
}
|
||||
|
||||
@IntRange(from = 0, to = ((int) Byte.MAX_VALUE) * 2)
|
||||
@IntRange(from = 0, to = ((int) Byte.MAX_VALUE) * 2 + 1)
|
||||
public short readUnsignedByte() {
|
||||
return (short) (this.bytes[this.position++] & 0xFF);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user