Mirror von
https://github.com/ViaVersion/ViaVersion.git
synchronisiert 2024-11-08 17:20:24 +01:00
Merge pull request #1262 from creeper123123321/dev2
attack metadata handling
Dieser Commit ist enthalten in:
Commit
4fa57fd642
@ -11,6 +11,7 @@ import us.myles.ViaVersion.api.minecraft.metadata.types.MetaType1_14;
|
|||||||
import us.myles.ViaVersion.api.type.Type;
|
import us.myles.ViaVersion.api.type.Type;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.Particle;
|
import us.myles.ViaVersion.protocols.protocol1_13to1_12_2.data.Particle;
|
||||||
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.packets.InventoryPackets;
|
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.packets.InventoryPackets;
|
||||||
|
import us.myles.ViaVersion.protocols.protocol1_14to1_13_2.storage.EntityTracker;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
@ -22,6 +23,8 @@ public class MetadataRewriter {
|
|||||||
try {
|
try {
|
||||||
metadata.setMetaType(MetaType1_14.byId(metadata.getMetaType().getTypeID()));
|
metadata.setMetaType(MetaType1_14.byId(metadata.getMetaType().getTypeID()));
|
||||||
|
|
||||||
|
EntityTracker tracker = connection.get(EntityTracker.class);
|
||||||
|
|
||||||
if (metadata.getMetaType() == MetaType1_14.Slot) {
|
if (metadata.getMetaType() == MetaType1_14.Slot) {
|
||||||
InventoryPackets.toClient((Item) metadata.getValue());
|
InventoryPackets.toClient((Item) metadata.getValue());
|
||||||
} else if (metadata.getMetaType() == MetaType1_14.BlockID) {
|
} else if (metadata.getMetaType() == MetaType1_14.BlockID) {
|
||||||
@ -42,6 +45,24 @@ public class MetadataRewriter {
|
|||||||
metadata.setId(metadata.getId() + 1);
|
metadata.setId(metadata.getId() + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (type.isOrHasParent(Entity1_14Types.EntityType.ABSTRACT_INSENTIENT)) {
|
||||||
|
if (metadata.getId() == 13) {
|
||||||
|
tracker.setInsentientData(entityId, (byte) ((((Number)metadata.getValue()).byteValue() & ~0x4)
|
||||||
|
| (tracker.getInsentientData(entityId) & 0x4))); // New attacking metadata
|
||||||
|
metadata.setValue(tracker.getInsentientData(entityId));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (type.isOrHasParent(Entity1_14Types.EntityType.ZOMBIE)) {
|
||||||
|
if (metadata.getId() == 16) {
|
||||||
|
tracker.setInsentientData(entityId, (byte) ((tracker.getInsentientData(entityId) & ~0x4)
|
||||||
|
| ((boolean) metadata.getValue() ? 0x4 : 0))); // New attacking
|
||||||
|
metadatas.remove(metadata); // "Are hands held up"
|
||||||
|
metadatas.add(new Metadata(13, MetaType1_14.Byte, tracker.getInsentientData(entityId)));
|
||||||
|
} else if (metadata.getId() > 16) {
|
||||||
|
metadata.setId(metadata.getId() - 1);
|
||||||
|
}
|
||||||
|
}
|
||||||
if (type.isOrHasParent(Entity1_14Types.EntityType.MINECART_ABSTRACT)) {
|
if (type.isOrHasParent(Entity1_14Types.EntityType.MINECART_ABSTRACT)) {
|
||||||
if (metadata.getId() == 10) {
|
if (metadata.getId() == 10) {
|
||||||
// New block format
|
// New block format
|
||||||
@ -75,13 +96,13 @@ public class MetadataRewriter {
|
|||||||
metadata.setMetaType(MetaType1_14.VillagerData);
|
metadata.setMetaType(MetaType1_14.VillagerData);
|
||||||
}
|
}
|
||||||
} else if (type.is(Entity1_14Types.EntityType.ZOMBIE_VILLAGER)) {
|
} else if (type.is(Entity1_14Types.EntityType.ZOMBIE_VILLAGER)) {
|
||||||
if (metadata.getId() == 19) {
|
if (metadata.getId() == 18) {
|
||||||
// plains
|
// plains
|
||||||
metadata.setValue(new VillagerData(2, getNewProfessionId((int) metadata.getValue()), 0));
|
metadata.setValue(new VillagerData(2, getNewProfessionId((int) metadata.getValue()), 0));
|
||||||
metadata.setMetaType(MetaType1_14.VillagerData);
|
metadata.setMetaType(MetaType1_14.VillagerData);
|
||||||
}
|
}
|
||||||
} else if (type.isOrHasParent(Entity1_14Types.EntityType.ARROW)) {
|
} else if (type.isOrHasParent(Entity1_14Types.EntityType.ABSTRACT_ARROW)) {
|
||||||
if (metadata.getId() >= 9) {
|
if (metadata.getId() >= 9) { // New piercing
|
||||||
metadata.setId(metadata.getId() + 1);
|
metadata.setId(metadata.getId() + 1);
|
||||||
}
|
}
|
||||||
} else if (type.is(Entity1_14Types.EntityType.FIREWORKS_ROCKET)) {
|
} else if (type.is(Entity1_14Types.EntityType.FIREWORKS_ROCKET)) {
|
||||||
@ -90,14 +111,11 @@ public class MetadataRewriter {
|
|||||||
metadata.setMetaType(MetaType1_14.OptVarInt);
|
metadata.setMetaType(MetaType1_14.OptVarInt);
|
||||||
}
|
}
|
||||||
} else if (type.isOrHasParent(Entity1_14Types.EntityType.ABSTRACT_SKELETON)) {
|
} else if (type.isOrHasParent(Entity1_14Types.EntityType.ABSTRACT_SKELETON)) {
|
||||||
if (metadata.getId() == 12) {
|
if (metadata.getId() == 14) {
|
||||||
metadatas.remove(metadata); // TODO "Is swinging arms", maybe moved to pos / entity status
|
tracker.setInsentientData(entityId, (byte) ((tracker.getInsentientData(entityId) & ~0x4)
|
||||||
}
|
| ((boolean) metadata.getValue() ? 0x4 : 0))); // New attacking
|
||||||
} else if (type.isOrHasParent(Entity1_14Types.EntityType.ZOMBIE)) {
|
metadatas.remove(metadata); // "Is swinging arms"
|
||||||
if (metadata.getId() == 16) {
|
metadatas.add(new Metadata(13, MetaType1_14.Byte, tracker.getInsentientData(entityId)));
|
||||||
metadatas.remove(metadata); // TODO "Are hands held up", maybe moved to pos / entity status
|
|
||||||
} else if (metadata.getId() > 16) {
|
|
||||||
metadata.setId(metadata.getId() - 1);
|
|
||||||
}
|
}
|
||||||
} else if (type.is(Entity1_14Types.EntityType.AREA_EFFECT_CLOUD)) {
|
} else if (type.is(Entity1_14Types.EntityType.AREA_EFFECT_CLOUD)) {
|
||||||
if (metadata.getId() == 10) {
|
if (metadata.getId() == 10) {
|
||||||
@ -108,13 +126,16 @@ public class MetadataRewriter {
|
|||||||
|
|
||||||
if (type.isOrHasParent(Entity1_14Types.EntityType.ABSTRACT_ILLAGER_BASE)) {
|
if (type.isOrHasParent(Entity1_14Types.EntityType.ABSTRACT_ILLAGER_BASE)) {
|
||||||
if (metadata.getId() == 14) {
|
if (metadata.getId() == 14) {
|
||||||
metadatas.remove(metadata); // TODO "Has target (aggressive state)", maybe moved to pos / entity status
|
tracker.setInsentientData(entityId, (byte) ((tracker.getInsentientData(entityId) & ~0x4)
|
||||||
|
| (((Number) metadata.getValue()).byteValue() != 0 ? 0x4 : 0))); // New attacking
|
||||||
|
metadatas.remove(metadata); // "Has target (aggressive state)"
|
||||||
|
metadatas.add(new Metadata(13, MetaType1_14.Byte, tracker.getInsentientData(entityId)));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// TODO Are witch and ravager also abstract illagers? They all inherit the new metadata 14 added in 19w13a
|
// TODO Are witch and ravager also abstract illagers? They all inherit the new metadata 14 added in 19w13a
|
||||||
if (type.is(Entity1_14Types.EntityType.WITCH) || type.is(Entity1_14Types.EntityType.RAVAGER) || type.isOrHasParent(Entity1_14Types.EntityType.ABSTRACT_ILLAGER_BASE)) {
|
if (type.is(Entity1_14Types.EntityType.WITCH) || type.is(Entity1_14Types.EntityType.RAVAGER) || type.isOrHasParent(Entity1_14Types.EntityType.ABSTRACT_ILLAGER_BASE)) {
|
||||||
if (metadata.getId() >= 14) { // TODO 19w13 added a new boolean with id 14
|
if (metadata.getId() >= 14) { // TODO 19w13 added a new boolean (raid participant - is celebrating) with id 14
|
||||||
metadata.setId(metadata.getId() + 1);
|
metadata.setId(metadata.getId() + 1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,7 @@ import java.util.concurrent.ConcurrentHashMap;
|
|||||||
|
|
||||||
public class EntityTracker extends StoredObject {
|
public class EntityTracker extends StoredObject {
|
||||||
private final Map<Integer, Entity1_14Types.EntityType> clientEntityTypes = new ConcurrentHashMap<>();
|
private final Map<Integer, Entity1_14Types.EntityType> clientEntityTypes = new ConcurrentHashMap<>();
|
||||||
|
private final Map<Integer, Byte> insentientData = new ConcurrentHashMap<>();
|
||||||
@Getter
|
@Getter
|
||||||
@Setter
|
@Setter
|
||||||
private int latestTradeWindowId;
|
private int latestTradeWindowId;
|
||||||
@ -23,12 +24,22 @@ public class EntityTracker extends StoredObject {
|
|||||||
|
|
||||||
public void removeEntity(int entityId) {
|
public void removeEntity(int entityId) {
|
||||||
clientEntityTypes.remove(entityId);
|
clientEntityTypes.remove(entityId);
|
||||||
|
insentientData.remove(entityId);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void addEntity(int entityId, UUID uuid, Entity1_14Types.EntityType type) {
|
public void addEntity(int entityId, UUID uuid, Entity1_14Types.EntityType type) {
|
||||||
clientEntityTypes.put(entityId, type);
|
clientEntityTypes.put(entityId, type);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public byte getInsentientData(int entity) {
|
||||||
|
Byte val = insentientData.get(entity);
|
||||||
|
return val == null ? 0 : val;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setInsentientData(int entity, byte value) {
|
||||||
|
insentientData.put(entity, value);
|
||||||
|
}
|
||||||
|
|
||||||
public boolean has(int entityId) {
|
public boolean has(int entityId) {
|
||||||
return clientEntityTypes.containsKey(entityId);
|
return clientEntityTypes.containsKey(entityId);
|
||||||
}
|
}
|
||||||
|
Laden…
In neuem Issue referenzieren
Einen Benutzer sperren