Backport minecart-item-type fix from f5467001.

This commit is contained in:
wizjany 2019-09-03 17:56:52 -04:00
parent 8db0053ffc
commit b0ebbee3de
2 changed files with 16 additions and 3 deletions

View File

@ -1013,14 +1013,16 @@ private static <T extends Event & Cancellable> void handleBlockRightClick(T even
// Handle created Minecarts // Handle created Minecarts
if (item != null && Materials.isMinecart(item.getType())) { if (item != null && Materials.isMinecart(item.getType())) {
// TODO: Give a more specific Minecart type EntityType entityType = Materials.getRelatedEntity(item.getType());
Events.fireToCancel(event, new SpawnEntityEvent(event, cause, clicked.getLocation().add(0.5, 0, 0.5), EntityType.MINECART)); if (entityType == null) {
entityType = EntityType.MINECART;
}
Events.fireToCancel(event, new SpawnEntityEvent(event, cause, placed.getLocation().add(0.5, 0, 0.5), entityType));
return; return;
} }
// Handle created boats // Handle created boats
if (item != null && Materials.isBoat(item.getType())) { if (item != null && Materials.isBoat(item.getType())) {
// TODO as above
Events.fireToCancel(event, new SpawnEntityEvent(event, cause, placed.getLocation().add(0.5, 0, 0.5), EntityType.BOAT)); Events.fireToCancel(event, new SpawnEntityEvent(event, cause, placed.getLocation().add(0.5, 0, 0.5), EntityType.BOAT));
return; return;
} }

View File

@ -806,6 +806,17 @@ public static Material getRelatedMaterial(EntityType type) {
return ENTITY_ITEMS.get(type); return ENTITY_ITEMS.get(type);
} }
/**
* Get the related entity type for a material.
*
* @param material the material
* @return the related entity type or {@code null} if one is not known or exists
*/
@Nullable
public static EntityType getRelatedEntity(Material material) {
return ENTITY_ITEMS.inverse().get(material);
}
/** /**
* Get the material of the block placed by the given bucket, defaulting * Get the material of the block placed by the given bucket, defaulting
* to water if the bucket type is not known. * to water if the bucket type is not known.