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 @@ public class EventAbstractionListener extends AbstractListener {
// Handle created Minecarts
if (item != null && Materials.isMinecart(item.getType())) {
// TODO: Give a more specific Minecart type
Events.fireToCancel(event, new SpawnEntityEvent(event, cause, clicked.getLocation().add(0.5, 0, 0.5), EntityType.MINECART));
EntityType entityType = Materials.getRelatedEntity(item.getType());
if (entityType == null) {
entityType = EntityType.MINECART;
}
Events.fireToCancel(event, new SpawnEntityEvent(event, cause, placed.getLocation().add(0.5, 0, 0.5), entityType));
return;
}
// Handle created boats
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));
return;
}

View File

@ -806,6 +806,17 @@ public final class Materials {
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
* to water if the bucket type is not known.