Added an item avatar exclusion tag to work around buggy items

This commit is contained in:
LemADEC 2021-02-02 02:21:59 +01:00
parent ccc91bcedf
commit 09918c19fb
3 changed files with 22 additions and 2 deletions

View file

@ -73,6 +73,7 @@ public class Dictionary {
public static HashSet<Item> ITEMS_FLYINSPACE = null; public static HashSet<Item> ITEMS_FLYINSPACE = null;
public static HashSet<Item> ITEMS_NOFALLDAMAGE = null; public static HashSet<Item> ITEMS_NOFALLDAMAGE = null;
public static HashSet<Item> ITEMS_BREATHING_HELMET = null; public static HashSet<Item> ITEMS_BREATHING_HELMET = null;
public static HashSet<Item> ITEMS_EXCLUDED_AVATAR = null;
public static void loadConfig(@Nonnull final Configuration config) { public static void loadConfig(@Nonnull final Configuration config) {
@ -432,7 +433,8 @@ public class Dictionary {
+ "Tags shall be separated by at least one space, comma or tabulation.\n" + "Invalid tags will be ignored silently. Tags and block names are case sensitive.\n" + "Tags shall be separated by at least one space, comma or tabulation.\n" + "Invalid tags will be ignored silently. Tags and block names are case sensitive.\n"
+ "In case of conflicts, the latest tag overwrite the previous ones.\n" + "- FlyInSpace: player can move without gravity effect while wearing this item (default: jetpacks).\n" + "In case of conflicts, the latest tag overwrite the previous ones.\n" + "- FlyInSpace: player can move without gravity effect while wearing this item (default: jetpacks).\n"
+ "- NoFallDamage: player doesn't take fall damage while wearing this armor item (default: IC2 rubber boots).\n" + "- NoFallDamage: player doesn't take fall damage while wearing this armor item (default: IC2 rubber boots).\n"
+ "- BreathingHelmet: player can breath from WarpDrive air canister or IC2 compressed air while wearing this armor item (default: IC2 nano helmet and Cie).\n"); + "- BreathingHelmet: player can breath from WarpDrive air canister or IC2 compressed air while wearing this armor item (default: IC2 nano helmet and Cie).\n"
+ "- ExcludedAvatar: offline avatars can't wear nor hold this item (default: SimplyJetpacks).\n");
final ConfigCategory categoryItemTags = config.getCategory("item_tags"); final ConfigCategory categoryItemTags = config.getCategory("item_tags");
// *** enforce default values // *** enforce default values
@ -490,6 +492,8 @@ public class Dictionary {
config.get("item_tags", "warpdrive:warp_armor.superior.leggings" , "NoFallDamage").getString(); config.get("item_tags", "warpdrive:warp_armor.superior.leggings" , "NoFallDamage").getString();
config.get("item_tags", "warpdrive:warp_armor.superior.boots" , "NoFallDamage").getString(); config.get("item_tags", "warpdrive:warp_armor.superior.boots" , "NoFallDamage").getString();
config.get("item_tags", "simplyjetpacks:itemjetpack" , "ExcludedAvatar").getString();
// *** read actual values // *** read actual values
final String[] taggedItemsName = categoryItemTags.getValues().keySet().toArray(new String[0]); final String[] taggedItemsName = categoryItemTags.getValues().keySet().toArray(new String[0]);
taggedItems = new HashMap<>(taggedItemsName.length); taggedItems = new HashMap<>(taggedItemsName.length);
@ -613,6 +617,7 @@ public class Dictionary {
ITEMS_FLYINSPACE = new HashSet<>(taggedItems.size()); ITEMS_FLYINSPACE = new HashSet<>(taggedItems.size());
ITEMS_NOFALLDAMAGE = new HashSet<>(taggedItems.size()); ITEMS_NOFALLDAMAGE = new HashSet<>(taggedItems.size());
ITEMS_BREATHING_HELMET = new HashSet<>(taggedItems.size()); ITEMS_BREATHING_HELMET = new HashSet<>(taggedItems.size());
ITEMS_EXCLUDED_AVATAR = new HashSet<>(taggedItems.size());
for (final Entry<String, String> taggedItem : taggedItems.entrySet()) { for (final Entry<String, String> taggedItem : taggedItems.entrySet()) {
final String itemId = taggedItem.getKey(); final String itemId = taggedItem.getKey();
final Item item = Item.REGISTRY.getObject(new ResourceLocation(itemId)); final Item item = Item.REGISTRY.getObject(new ResourceLocation(itemId));
@ -625,6 +630,7 @@ public class Dictionary {
case "FlyInSpace" : ITEMS_FLYINSPACE.add(item); break; case "FlyInSpace" : ITEMS_FLYINSPACE.add(item); break;
case "NoFallDamage" : ITEMS_NOFALLDAMAGE.add(item); break; case "NoFallDamage" : ITEMS_NOFALLDAMAGE.add(item); break;
case "BreathingHelmet": ITEMS_BREATHING_HELMET.add(item); break; case "BreathingHelmet": ITEMS_BREATHING_HELMET.add(item); break;
case "ExcludedAvatar" : ITEMS_EXCLUDED_AVATAR.add(item); break;
default: default:
WarpDrive.logger.error(String.format("Unsupported tag %s for item %s", tag, item)); WarpDrive.logger.error(String.format("Unsupported tag %s for item %s", tag, item));
break; break;
@ -665,6 +671,7 @@ public class Dictionary {
WarpDrive.logger.info(String.format("- %s allowing fly in space: %s" , ITEMS_FLYINSPACE.size(), getHashMessage(ITEMS_FLYINSPACE))); WarpDrive.logger.info(String.format("- %s allowing fly in space: %s" , ITEMS_FLYINSPACE.size(), getHashMessage(ITEMS_FLYINSPACE)));
WarpDrive.logger.info(String.format("- %s absorbing fall damages: %s", ITEMS_NOFALLDAMAGE.size(), getHashMessage(ITEMS_NOFALLDAMAGE))); WarpDrive.logger.info(String.format("- %s absorbing fall damages: %s", ITEMS_NOFALLDAMAGE.size(), getHashMessage(ITEMS_NOFALLDAMAGE)));
WarpDrive.logger.info(String.format("- %s allowing breathing air: %s", ITEMS_BREATHING_HELMET.size(), getHashMessage(ITEMS_BREATHING_HELMET))); WarpDrive.logger.info(String.format("- %s allowing breathing air: %s", ITEMS_BREATHING_HELMET.size(), getHashMessage(ITEMS_BREATHING_HELMET)));
WarpDrive.logger.info(String.format("- %s excluded avatar items: %s" , ITEMS_EXCLUDED_AVATAR.size(), getHashMessage(ITEMS_EXCLUDED_AVATAR)));
} }
private static void adjustHardnessAndResistance() { private static void adjustHardnessAndResistance() {

View file

@ -2,6 +2,7 @@ package cr0s.warpdrive.data;
import cr0s.warpdrive.Commons; import cr0s.warpdrive.Commons;
import cr0s.warpdrive.WarpDrive; import cr0s.warpdrive.WarpDrive;
import cr0s.warpdrive.config.Dictionary;
import cr0s.warpdrive.config.WarpDriveConfig; import cr0s.warpdrive.config.WarpDriveConfig;
import cr0s.warpdrive.entity.EntityOfflineAvatar; import cr0s.warpdrive.entity.EntityOfflineAvatar;
@ -203,7 +204,8 @@ public class OfflineAvatarManager {
// copy equipment with a marker to remember those aren't 'legit' items // copy equipment with a marker to remember those aren't 'legit' items
for (final EntityEquipmentSlot entityEquipmentSlot : EntityEquipmentSlot.values()) { for (final EntityEquipmentSlot entityEquipmentSlot : EntityEquipmentSlot.values()) {
final ItemStack itemStack = entityPlayer.getItemStackFromSlot(entityEquipmentSlot).copy(); final ItemStack itemStack = entityPlayer.getItemStackFromSlot(entityEquipmentSlot).copy();
if (!itemStack.isEmpty()) { if ( !itemStack.isEmpty()
&& !Dictionary.ITEMS_EXCLUDED_AVATAR.contains(itemStack.getItem()) ) {
if (!itemStack.hasTagCompound()) { if (!itemStack.hasTagCompound()) {
itemStack.setTagCompound(new NBTTagCompound()); itemStack.setTagCompound(new NBTTagCompound());
} }

View file

@ -1,6 +1,7 @@
package cr0s.warpdrive.entity; package cr0s.warpdrive.entity;
import cr0s.warpdrive.WarpDrive; import cr0s.warpdrive.WarpDrive;
import cr0s.warpdrive.config.Dictionary;
import cr0s.warpdrive.config.WarpDriveConfig; import cr0s.warpdrive.config.WarpDriveConfig;
import cr0s.warpdrive.data.GlobalPosition; import cr0s.warpdrive.data.GlobalPosition;
import cr0s.warpdrive.data.OfflineAvatarManager; import cr0s.warpdrive.data.OfflineAvatarManager;
@ -12,6 +13,8 @@ import java.util.UUID;
import net.minecraft.entity.EntityLiving; import net.minecraft.entity.EntityLiving;
import net.minecraft.entity.player.EntityPlayer; import net.minecraft.entity.player.EntityPlayer;
import net.minecraft.inventory.EntityEquipmentSlot;
import net.minecraft.item.ItemStack;
import net.minecraft.nbt.NBTTagCompound; import net.minecraft.nbt.NBTTagCompound;
import net.minecraft.network.datasync.DataParameter; import net.minecraft.network.datasync.DataParameter;
import net.minecraft.network.datasync.DataSerializers; import net.minecraft.network.datasync.DataSerializers;
@ -132,6 +135,14 @@ public class EntityOfflineAvatar extends EntityLiving {
return; return;
} }
setPlayer(uuidPlayer, namePlayer); setPlayer(uuidPlayer, namePlayer);
for (final EntityEquipmentSlot entityEquipmentSlot : EntityEquipmentSlot.values()) {
final ItemStack itemStack = getItemStackFromSlot(entityEquipmentSlot);
if ( !itemStack.isEmpty()
&& Dictionary.ITEMS_EXCLUDED_AVATAR.contains(itemStack.getItem()) ) {
setItemStackToSlot(entityEquipmentSlot, ItemStack.EMPTY);
}
}
} }
@Override @Override