PotionTypes created
This commit is contained in:
1 parent
06113b1cee
commit
5bc3597c70
8 files changed
+193
-8
No files matched your search
+8
-3
@@ -38,9 +38,6 @@ public class EntityTypes {
|
||||
if (ENTITY_TYPES_JSON == null) {
|
||||
ENTITY_TYPES_JSON = MappingHelper.getJSONObject("modernentitytypes");
|
||||
}
|
||||
if (ENTITY_TYPES_JSON.get(key) == null) {
|
||||
System.out.println("KEY: " + key + " COULD NOT BE FOUND!");
|
||||
}
|
||||
int id = ENTITY_TYPES_JSON.get(key).getAsInt();
|
||||
ResourceLocation identifier = ResourceLocation.minecraft(key);
|
||||
EntityType entityType = new EntityType() {
|
||||
@@ -53,6 +50,14 @@ public class EntityTypes {
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof EntityType) {
|
||||
return getId() == ((EntityType)obj).getId();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
ENTITY_TYPE_MAP.put(entityType.getIdentifier().getKey(), entityType);
|
||||
|
||||
@@ -77,6 +77,14 @@ public class ItemTypes {
|
||||
public boolean isMusicDisc() {
|
||||
return musicDisc;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof ItemType) {
|
||||
return getId() == ((ItemType)obj).getId();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
ITEM_TYPE_MAP.put(type.getIdentifier().getKey(), type);
|
||||
ITEM_TYPE_ID_MAP.put(type.getId(), type);
|
||||
|
||||
@@ -24,8 +24,4 @@ public interface MappedEntity {
|
||||
ResourceLocation getIdentifier();
|
||||
|
||||
int getId();
|
||||
|
||||
default boolean equals(MappedEntity other) {
|
||||
return getId() == other.getId();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2021 retrooper and contributors
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.potion;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.mapper.MappedEntity;
|
||||
|
||||
public interface PotionType extends MappedEntity {
|
||||
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
/*
|
||||
* This file is part of packetevents - https://github.com/retrooper/packetevents
|
||||
* Copyright (C) 2021 retrooper and contributors
|
||||
*
|
||||
* 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 <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
package com.github.retrooper.packetevents.protocol.potion;
|
||||
|
||||
import com.github.retrooper.packetevents.protocol.resources.ResourceLocation;
|
||||
import com.github.retrooper.packetevents.util.MappingHelper;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class PotionTypes {
|
||||
private static final Map<String, PotionType> POTION_TYPE_MAP = new HashMap<>();
|
||||
private static final Map<Integer, PotionType> POTION_TYPE_ID_MAP = new HashMap<>();
|
||||
private static JsonObject POTION_TYPES_JSON;
|
||||
|
||||
public static void replaceJSONObject(JsonObject jsonObject) {
|
||||
POTION_TYPES_JSON = jsonObject;
|
||||
}
|
||||
|
||||
public static PotionType define(String key) {
|
||||
if (POTION_TYPES_JSON == null) {
|
||||
POTION_TYPES_JSON = MappingHelper.getJSONObject("modernpotiontypes");
|
||||
}
|
||||
int id = POTION_TYPES_JSON.get(key).getAsInt();
|
||||
ResourceLocation identifier = ResourceLocation.minecraft(key);
|
||||
PotionType potionType = new PotionType() {
|
||||
@Override
|
||||
public ResourceLocation getIdentifier() {
|
||||
return identifier;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getId() {
|
||||
return id;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj instanceof PotionType) {
|
||||
return getId() == ((PotionType)obj).getId();
|
||||
}
|
||||
return false;
|
||||
}
|
||||
};
|
||||
|
||||
POTION_TYPE_MAP.put(potionType.getIdentifier().getKey(), potionType);
|
||||
POTION_TYPE_ID_MAP.put(potionType.getId(), potionType);
|
||||
return potionType;
|
||||
}
|
||||
|
||||
public static PotionType getByKey(String key) {
|
||||
return POTION_TYPE_MAP.get(key);
|
||||
}
|
||||
|
||||
public static PotionType getById(int id) {
|
||||
return POTION_TYPE_ID_MAP.get(id);
|
||||
}
|
||||
|
||||
public static final PotionType SPEED = define("speed");
|
||||
public static final PotionType SLOWNESS = define("slowness");
|
||||
public static final PotionType HASTE = define("haste");
|
||||
public static final PotionType MINING_FATIGUE = define("mining_fatigue");
|
||||
public static final PotionType STRENGTH = define("strength");
|
||||
public static final PotionType INSTANT_HEALTH = define("instant_health");
|
||||
public static final PotionType INSTANT_DAMAGE = define("instant_damage");
|
||||
public static final PotionType JUMP_BOOST = define("jump_boost");
|
||||
public static final PotionType NAUSEA = define("nausea");
|
||||
public static final PotionType REGENERATION = define("regeneration");
|
||||
public static final PotionType RESISTANCE = define("resistance");
|
||||
public static final PotionType FIRE_RESISTANCE = define("fire_resistance");
|
||||
public static final PotionType WATER_BREATHING = define("water_breathing");
|
||||
public static final PotionType INVISIBILITY = define("invisibility");
|
||||
public static final PotionType BLINDNESS = define("blindness");
|
||||
public static final PotionType NIGHT_VISION = define("night_vision");
|
||||
public static final PotionType HUNGER = define("hunger");
|
||||
public static final PotionType WEAKNESS = define("weakness");
|
||||
public static final PotionType POISON = define("poison");
|
||||
public static final PotionType WITHER = define("wither");
|
||||
public static final PotionType HEALTH_BOOST = define("health_boost");
|
||||
public static final PotionType ABSORPTION = define("absorption");
|
||||
public static final PotionType SATURATION = define("saturation");
|
||||
public static final PotionType GLOWING = define("glowing");
|
||||
public static final PotionType LEVITATION = define("levitation");
|
||||
public static final PotionType LUCK = define("luck");
|
||||
public static final PotionType UNLUCK = define("unluck");
|
||||
public static final PotionType SLOW_FALLING = define("slow_falling");
|
||||
public static final PotionType CONDUIT_POWER = define("conduit_power");
|
||||
public static final PotionType DOLPHINS_GRACE = define("dolphins_grace");
|
||||
public static final PotionType BAD_OMEN = define("bad_omen");
|
||||
public static final PotionType HERO_OF_THE_VILLAGE = define("hero_of_the_village");
|
||||
|
||||
|
||||
}
|
||||
@@ -21,6 +21,7 @@ package com.github.retrooper.packetevents.util;
|
||||
import com.github.retrooper.packetevents.protocol.chat.component.ComponentSerializer;
|
||||
import com.github.retrooper.packetevents.protocol.entity.EntityTypes;
|
||||
import com.github.retrooper.packetevents.protocol.inventory.ItemTypes;
|
||||
import com.github.retrooper.packetevents.protocol.potion.PotionTypes;
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import java.io.BufferedReader;
|
||||
@@ -66,5 +67,7 @@ public class MappingHelper {
|
||||
ItemTypes.replaceJsonObject(MappingHelper.getJSONObject("modernitemtypes"));
|
||||
MAPPING_JSON_OBJECTS.put("modernentitytypes", searchJSONObject("modernentitytypes"));
|
||||
EntityTypes.replaceJSONObject(MappingHelper.getJSONObject("modernentitytypes"));
|
||||
MAPPING_JSON_OBJECTS.put("modernpotiontypes", searchJSONObject("modernpotiontypes"));
|
||||
PotionTypes.replaceJSONObject(MappingHelper.getJSONObject("modernpotiontypes"));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,34 @@
|
||||
{
|
||||
"speed": "1",
|
||||
"slowness": "2",
|
||||
"haste": "3",
|
||||
"mining_fatigue": "4",
|
||||
"strength": "5",
|
||||
"instant_health": "6",
|
||||
"instant_damage": "7",
|
||||
"jump_boost": "8",
|
||||
"nausea": "9",
|
||||
"regeneration": "10",
|
||||
"resistance": "11",
|
||||
"fire_resistance": "12",
|
||||
"water_breathing": "13",
|
||||
"invisibility": "14",
|
||||
"blindness": "15",
|
||||
"night_vision": "16",
|
||||
"hunger": "17",
|
||||
"weakness": "18",
|
||||
"poison": "19",
|
||||
"wither": "20",
|
||||
"health_boost": "21",
|
||||
"absorption": "22",
|
||||
"saturation": "23",
|
||||
"glowing": "24",
|
||||
"levitation": "25",
|
||||
"luck": "26",
|
||||
"unluck": "27",
|
||||
"slow_falling": "28",
|
||||
"conduit_power": "29",
|
||||
"dolphins_grace": "30",
|
||||
"bad_omen": "31",
|
||||
"hero_of_the_village": "32"
|
||||
}
|
||||
+5
-1
@@ -28,9 +28,9 @@ import com.github.retrooper.packetevents.protocol.chat.Color;
|
||||
import com.github.retrooper.packetevents.protocol.chat.component.ComponentSerializer;
|
||||
import com.github.retrooper.packetevents.protocol.chat.component.TextComponent;
|
||||
import com.github.retrooper.packetevents.protocol.entity.EntityType;
|
||||
import com.github.retrooper.packetevents.protocol.entity.EntityTypes;
|
||||
import com.github.retrooper.packetevents.protocol.packettype.PacketType;
|
||||
import com.github.retrooper.packetevents.protocol.player.ClientVersion;
|
||||
import com.github.retrooper.packetevents.util.MappingHelper;
|
||||
import com.github.retrooper.packetevents.util.Vector3d;
|
||||
import com.github.retrooper.packetevents.wrapper.handshaking.client.WrapperHandshakingClientHandshake;
|
||||
import com.github.retrooper.packetevents.wrapper.login.client.WrapperLoginClientLoginStart;
|
||||
@@ -65,6 +65,10 @@ public class InternalPacketListener implements PacketListener {
|
||||
WrapperPlayServerSpawnLivingEntity spawnLivingEntity = new WrapperPlayServerSpawnLivingEntity(event);
|
||||
int entityID = spawnLivingEntity.getEntityId();
|
||||
EntityType entityType = spawnLivingEntity.getEntityType();
|
||||
if (entityType.equals(EntityTypes.PLAYER)) {
|
||||
//This is a player
|
||||
System.out.println("Spawning a player...");
|
||||
}
|
||||
Vector3d position = spawnLivingEntity.getPosition();
|
||||
System.out.println("Spawned entity with ID " + entityID + " of type " + entityType.getIdentifier().getKey() + "=" + entityType.getId() + " at position " + position);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user