mirror of
https://gitlab.bixilon.de/bixilon/minosoft.git
synced 2025-09-12 08:58:02 -04:00
MobEffects: flattening update
This commit is contained in:
parent
985c4b31a8
commit
60da329683
@ -16,6 +16,7 @@ package de.bixilon.minosoft.game.datatypes.entities;
|
||||
import de.bixilon.minosoft.game.datatypes.entities.meta.EntityMetaData;
|
||||
import de.bixilon.minosoft.game.datatypes.inventory.InventorySlots;
|
||||
import de.bixilon.minosoft.game.datatypes.inventory.Slot;
|
||||
import de.bixilon.minosoft.game.datatypes.objectLoader.effects.MobEffect;
|
||||
import de.bixilon.minosoft.game.datatypes.objectLoader.entities.Entities;
|
||||
|
||||
import java.util.ArrayList;
|
||||
@ -125,7 +126,7 @@ public abstract class Entity implements EntityInterface {
|
||||
effectList.add(effect);
|
||||
}
|
||||
|
||||
public void removeEffect(StatusEffects effect) {
|
||||
public void removeEffect(MobEffect effect) {
|
||||
effectList.removeIf(listEffect -> listEffect.getEffect() == effect);
|
||||
}
|
||||
|
||||
|
@ -13,18 +13,20 @@
|
||||
|
||||
package de.bixilon.minosoft.game.datatypes.entities;
|
||||
|
||||
import de.bixilon.minosoft.game.datatypes.objectLoader.effects.MobEffect;
|
||||
|
||||
public class StatusEffect {
|
||||
final StatusEffects effect;
|
||||
final byte amplifier;
|
||||
final MobEffect effect;
|
||||
final int amplifier;
|
||||
final int duration;
|
||||
|
||||
public StatusEffect(StatusEffects effect, byte amplifier, int duration) {
|
||||
public StatusEffect(MobEffect effect, int amplifier, int duration) {
|
||||
this.effect = effect;
|
||||
this.amplifier = amplifier;
|
||||
this.duration = duration;
|
||||
}
|
||||
|
||||
public byte getAmplifier() {
|
||||
public int getAmplifier() {
|
||||
return amplifier;
|
||||
}
|
||||
|
||||
@ -32,7 +34,7 @@ public class StatusEffect {
|
||||
return duration;
|
||||
}
|
||||
|
||||
public StatusEffects getEffect() {
|
||||
public MobEffect getEffect() {
|
||||
return effect;
|
||||
}
|
||||
|
||||
|
@ -1,90 +0,0 @@
|
||||
/*
|
||||
* 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.entities;
|
||||
|
||||
public enum StatusEffects {
|
||||
SPEED("speed", 1, Impact.POSITIVE),
|
||||
SLOWNESS("slowness", 2, Impact.NEGATIVE),
|
||||
HASTE("haste", 3, Impact.POSITIVE),
|
||||
MINING_FATIGUE("mining_fatigue", 4, Impact.NEGATIVE),
|
||||
STRENGTH("strength", 5, Impact.POSITIVE),
|
||||
INSTANT_HEALTH("instant_health", 6, Impact.POSITIVE),
|
||||
INSTANT_DAMAGE("instant_damage", 7, Impact.POSITIVE),
|
||||
JUMP_BOOST("jump_boost", 8, Impact.POSITIVE),
|
||||
NAUSEA("nausea", 9, Impact.NEGATIVE),
|
||||
REGENERATION("regeneration", 10, Impact.POSITIVE),
|
||||
RESISTANCE("resistance", 11, Impact.POSITIVE),
|
||||
FIRE_RESISTANCE("fire_resistance", 12, Impact.POSITIVE),
|
||||
WATER_BREATHING("water_breathing", 13, Impact.POSITIVE),
|
||||
INVISIBILITY("invisibility", 14, Impact.POSITIVE),
|
||||
BLINDNESS("blindness", 15, Impact.NEGATIVE),
|
||||
NIGHT_VISION("night_vision", 16, Impact.POSITIVE),
|
||||
HUNGER("hunger", 17, Impact.NEGATIVE),
|
||||
WEAKNESS("weakness", 18, Impact.NEGATIVE),
|
||||
POISON("poison", 19, Impact.NEGATIVE),
|
||||
WITHER("wither", 20, Impact.NEGATIVE),
|
||||
HEALTH_BOOST("health_boost", 21, Impact.POSITIVE),
|
||||
ABSORPTION("absorption", 22, Impact.POSITIVE),
|
||||
SATURATION("saturation", 23, Impact.POSITIVE),
|
||||
GLOWING("glowing", 24, Impact.NEGATIVE),
|
||||
LEVITATION("levitation", 25, Impact.NEGATIVE),
|
||||
LUCK("luck", 26, Impact.POSITIVE),
|
||||
UNLUCK("unluck", 27, Impact.NEGATIVE),
|
||||
SLOW_FALLING("slow_falling", 28, Impact.POSITIVE),
|
||||
CONDUIT_POWER("conduit_power", 29, Impact.POSITIVE),
|
||||
DOLPHINS_GRACE("dolphins_grace", 30, Impact.POSITIVE),
|
||||
BAD_OMEN("bad_omen", 31, Impact.NEGATIVE),
|
||||
HERO_OF_THE_VILLAGE("hero_of_the_village", 32, Impact.POSITIVE);
|
||||
|
||||
final String name;
|
||||
final int id;
|
||||
final Impact impact;
|
||||
|
||||
StatusEffects(String name, int id, Impact impact) {
|
||||
this.name = name;
|
||||
this.id = id;
|
||||
this.impact = impact;
|
||||
}
|
||||
|
||||
public static StatusEffects byId(int id) {
|
||||
for (StatusEffects s : values()) {
|
||||
if (s.getId() == id) {
|
||||
return s;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public static StatusEffects byName(String name) {
|
||||
for (StatusEffects s : values()) {
|
||||
if (s.getName().equals(name)) {
|
||||
return s;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return name;
|
||||
}
|
||||
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
public enum Impact {
|
||||
POSITIVE,
|
||||
NEGATIVE
|
||||
}
|
||||
}
|
@ -11,8 +11,10 @@
|
||||
* This software is not affiliated with Mojang AB, the original developer of Minecraft.
|
||||
*/
|
||||
|
||||
package de.bixilon.minosoft.game.datatypes.entities;
|
||||
package de.bixilon.minosoft.game.datatypes.entities.objects;
|
||||
|
||||
import de.bixilon.minosoft.game.datatypes.entities.Entity;
|
||||
import de.bixilon.minosoft.game.datatypes.entities.Location;
|
||||
import de.bixilon.minosoft.game.datatypes.entities.meta.EntityMetaData;
|
||||
|
||||
public class ExperienceOrb extends Entity {
|
@ -13,30 +13,34 @@
|
||||
|
||||
package de.bixilon.minosoft.game.datatypes.entities.objects;
|
||||
|
||||
import de.bixilon.minosoft.game.datatypes.entities.*;
|
||||
import de.bixilon.minosoft.game.datatypes.entities.EntityObject;
|
||||
import de.bixilon.minosoft.game.datatypes.entities.Location;
|
||||
import de.bixilon.minosoft.game.datatypes.entities.ObjectInterface;
|
||||
import de.bixilon.minosoft.game.datatypes.entities.Velocity;
|
||||
import de.bixilon.minosoft.game.datatypes.entities.meta.EntityMetaData;
|
||||
import de.bixilon.minosoft.game.datatypes.entities.meta.PotionMetaData;
|
||||
import de.bixilon.minosoft.game.datatypes.objectLoader.effects.MobEffect;
|
||||
import de.bixilon.minosoft.game.datatypes.objectLoader.effects.MobEffects;
|
||||
import de.bixilon.minosoft.protocol.protocol.ProtocolVersion;
|
||||
|
||||
public class ThrownPotion extends EntityObject implements ObjectInterface {
|
||||
PotionMetaData metaData;
|
||||
StatusEffects potion; // ToDo
|
||||
MobEffect potion;
|
||||
|
||||
public ThrownPotion(int entityId, Location location, short yaw, short pitch, int additionalInt) {
|
||||
super(entityId, location, yaw, pitch, null);
|
||||
// objects do not spawn with metadata... reading additional info from the following int
|
||||
this.potion = StatusEffects.byId(additionalInt);
|
||||
this.potion = MobEffects.byId(additionalInt, ProtocolVersion.VERSION_1_12_2);
|
||||
}
|
||||
|
||||
public ThrownPotion(int entityId, Location location, short yaw, short pitch, int additionalInt, Velocity velocity) {
|
||||
super(entityId, location, yaw, pitch, velocity);
|
||||
this.potion = StatusEffects.byId(additionalInt);
|
||||
this.potion = MobEffects.byId(additionalInt, ProtocolVersion.VERSION_1_12_2);
|
||||
}
|
||||
|
||||
public ThrownPotion(int entityId, Location location, short yaw, short pitch, Velocity velocity, EntityMetaData.MetaDataHashMap sets, ProtocolVersion version) {
|
||||
super(entityId, location, yaw, pitch, velocity);
|
||||
this.metaData = new PotionMetaData(sets, version);
|
||||
this.potion = StatusEffects.byId(0); // ToDo
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -19,6 +19,7 @@ import de.bixilon.minosoft.game.datatypes.Mappings;
|
||||
import de.bixilon.minosoft.game.datatypes.objectLoader.blockIds.BlockIds;
|
||||
import de.bixilon.minosoft.game.datatypes.objectLoader.blocks.Block;
|
||||
import de.bixilon.minosoft.game.datatypes.objectLoader.blocks.Blocks;
|
||||
import de.bixilon.minosoft.game.datatypes.objectLoader.effects.MobEffects;
|
||||
import de.bixilon.minosoft.game.datatypes.objectLoader.enchantments.Enchantments;
|
||||
import de.bixilon.minosoft.game.datatypes.objectLoader.entities.Entities;
|
||||
import de.bixilon.minosoft.game.datatypes.objectLoader.items.Items;
|
||||
@ -58,6 +59,7 @@ public class ObjectLoader {
|
||||
BlockIds.load(mod, modJSON.getAsJsonObject("block").getAsJsonObject("entries"), version);
|
||||
Motives.load(mod, modJSON.getAsJsonObject("motive").getAsJsonObject("entries"), version);
|
||||
Particles.load(mod, modJSON.getAsJsonObject("particle_type").getAsJsonObject("entries"), version);
|
||||
MobEffects.load(mod, modJSON.getAsJsonObject("mob_effect").getAsJsonObject("entries"), version);
|
||||
break;
|
||||
case BLOCKS:
|
||||
Blocks.load(mod, modJSON, version);
|
||||
|
@ -0,0 +1,54 @@
|
||||
/*
|
||||
* 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.objectLoader.effects;
|
||||
|
||||
public class MobEffect {
|
||||
final String mod;
|
||||
final String identifier;
|
||||
|
||||
public MobEffect(String mod, String identifier) {
|
||||
this.mod = mod;
|
||||
this.identifier = identifier;
|
||||
}
|
||||
|
||||
public String getMod() {
|
||||
return mod;
|
||||
}
|
||||
|
||||
public String getIdentifier() {
|
||||
return identifier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("%s:%s", getMod(), getIdentifier());
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode() {
|
||||
return mod.hashCode() * identifier.hashCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (super.equals(obj)) {
|
||||
return true;
|
||||
}
|
||||
if (hashCode() != obj.hashCode()) {
|
||||
return false;
|
||||
}
|
||||
MobEffect their = (MobEffect) obj;
|
||||
return getIdentifier().equals(their.getIdentifier()) && getMod().equals(their.getMod());
|
||||
}
|
||||
}
|
@ -0,0 +1,42 @@
|
||||
/*
|
||||
* 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.objectLoader.effects;
|
||||
|
||||
import com.google.common.collect.HashBiMap;
|
||||
import com.google.gson.JsonObject;
|
||||
import de.bixilon.minosoft.protocol.protocol.ProtocolVersion;
|
||||
|
||||
import java.util.HashMap;
|
||||
|
||||
public class MobEffects {
|
||||
|
||||
|
||||
static HashMap<ProtocolVersion, HashBiMap<Integer, MobEffect>> statusEffectMap = new java.util.HashMap<>();
|
||||
|
||||
public static MobEffect byId(int protocolId, ProtocolVersion version) {
|
||||
if (version.getVersionNumber() < ProtocolVersion.VERSION_1_12_2.getVersionNumber()) {
|
||||
version = ProtocolVersion.VERSION_1_12_2;
|
||||
}
|
||||
return statusEffectMap.get(version).get(protocolId);
|
||||
}
|
||||
|
||||
public static void load(String mod, JsonObject json, ProtocolVersion version) {
|
||||
HashBiMap<Integer, MobEffect> versionMapping = HashBiMap.create();
|
||||
for (String identifierName : json.keySet()) {
|
||||
MobEffect mobEffect = new MobEffect(mod, identifierName);
|
||||
versionMapping.put(json.getAsJsonObject(identifierName).get("id").getAsInt(), mobEffect);
|
||||
}
|
||||
statusEffectMap.put(version, versionMapping);
|
||||
}
|
||||
}
|
@ -16,7 +16,6 @@ package de.bixilon.minosoft.game.datatypes.objectLoader.entities;
|
||||
import com.google.common.collect.HashBiMap;
|
||||
import com.google.gson.JsonObject;
|
||||
import de.bixilon.minosoft.game.datatypes.entities.Entity;
|
||||
import de.bixilon.minosoft.game.datatypes.entities.ExperienceOrb;
|
||||
import de.bixilon.minosoft.game.datatypes.entities.mob.*;
|
||||
import de.bixilon.minosoft.game.datatypes.entities.objects.*;
|
||||
import de.bixilon.minosoft.protocol.protocol.ProtocolVersion;
|
||||
|
@ -14,7 +14,7 @@
|
||||
package de.bixilon.minosoft.protocol.packets.clientbound.play;
|
||||
|
||||
import de.bixilon.minosoft.game.datatypes.entities.StatusEffect;
|
||||
import de.bixilon.minosoft.game.datatypes.entities.StatusEffects;
|
||||
import de.bixilon.minosoft.game.datatypes.objectLoader.effects.MobEffects;
|
||||
import de.bixilon.minosoft.logging.Log;
|
||||
import de.bixilon.minosoft.protocol.packets.ClientboundPacket;
|
||||
import de.bixilon.minosoft.protocol.protocol.InByteBuffer;
|
||||
@ -35,18 +35,18 @@ public class PacketEntityEffect implements ClientboundPacket {
|
||||
switch (buffer.getVersion()) {
|
||||
case VERSION_1_7_10:
|
||||
entityId = buffer.readInt();
|
||||
effect = new StatusEffect(StatusEffects.byId(buffer.readByte()), buffer.readByte(), buffer.readShort());
|
||||
effect = new StatusEffect(MobEffects.byId(buffer.readByte(), buffer.getVersion()), buffer.readByte() + 1, buffer.readShort());
|
||||
hideParticles = false;
|
||||
return true;
|
||||
case VERSION_1_8:
|
||||
case VERSION_1_9_4:
|
||||
entityId = buffer.readVarInt();
|
||||
effect = new StatusEffect(StatusEffects.byId(buffer.readByte()), buffer.readByte(), buffer.readVarInt());
|
||||
effect = new StatusEffect(MobEffects.byId(buffer.readByte(), buffer.getVersion()), buffer.readByte() + 1, buffer.readVarInt());
|
||||
hideParticles = buffer.readBoolean();
|
||||
return true;
|
||||
default:
|
||||
entityId = buffer.readVarInt();
|
||||
effect = new StatusEffect(StatusEffects.byId(buffer.readByte()), buffer.readByte(), buffer.readVarInt());
|
||||
effect = new StatusEffect(MobEffects.byId(buffer.readByte(), buffer.getVersion()), buffer.readByte() + 1, buffer.readVarInt());
|
||||
byte flags = buffer.readByte();
|
||||
isAmbient = BitByte.isBitMask(flags, 0x01);
|
||||
hideParticles = !BitByte.isBitMask(flags, 0x02);
|
||||
|
@ -13,7 +13,8 @@
|
||||
|
||||
package de.bixilon.minosoft.protocol.packets.clientbound.play;
|
||||
|
||||
import de.bixilon.minosoft.game.datatypes.entities.StatusEffects;
|
||||
import de.bixilon.minosoft.game.datatypes.objectLoader.effects.MobEffect;
|
||||
import de.bixilon.minosoft.game.datatypes.objectLoader.effects.MobEffects;
|
||||
import de.bixilon.minosoft.logging.Log;
|
||||
import de.bixilon.minosoft.protocol.packets.ClientboundPacket;
|
||||
import de.bixilon.minosoft.protocol.protocol.InByteBuffer;
|
||||
@ -21,7 +22,7 @@ import de.bixilon.minosoft.protocol.protocol.PacketHandler;
|
||||
|
||||
public class PacketRemoveEntityEffect implements ClientboundPacket {
|
||||
int entityId;
|
||||
StatusEffects effect;
|
||||
MobEffect effect;
|
||||
|
||||
|
||||
@Override
|
||||
@ -29,11 +30,11 @@ public class PacketRemoveEntityEffect implements ClientboundPacket {
|
||||
switch (buffer.getVersion()) {
|
||||
case VERSION_1_7_10:
|
||||
entityId = buffer.readInt();
|
||||
effect = StatusEffects.byId(buffer.readByte());
|
||||
effect = MobEffects.byId(buffer.readByte(), buffer.getVersion());
|
||||
return true;
|
||||
default:
|
||||
entityId = buffer.readVarInt();
|
||||
effect = StatusEffects.byId(buffer.readByte());
|
||||
effect = MobEffects.byId(buffer.readByte(), buffer.getVersion());
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -52,7 +53,7 @@ public class PacketRemoveEntityEffect implements ClientboundPacket {
|
||||
return entityId;
|
||||
}
|
||||
|
||||
public StatusEffects getEffect() {
|
||||
public MobEffect getEffect() {
|
||||
return effect;
|
||||
}
|
||||
}
|
||||
|
@ -13,8 +13,8 @@
|
||||
|
||||
package de.bixilon.minosoft.protocol.packets.clientbound.play;
|
||||
|
||||
import de.bixilon.minosoft.game.datatypes.entities.ExperienceOrb;
|
||||
import de.bixilon.minosoft.game.datatypes.entities.Location;
|
||||
import de.bixilon.minosoft.game.datatypes.entities.objects.ExperienceOrb;
|
||||
import de.bixilon.minosoft.logging.Log;
|
||||
import de.bixilon.minosoft.protocol.packets.ClientboundPacket;
|
||||
import de.bixilon.minosoft.protocol.protocol.InByteBuffer;
|
||||
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
x
Reference in New Issue
Block a user