Permalink
Browse files

BREAKING CHANGES: Update to reflect changes in 1.13 to items and blocks.

It is highly recommended that you do not run this on a production server running pre-1.13 scripts. While efforts were made to warn and convert where necessary, there will be problems with scripts handling items or blocks! Here is a summary of most of the changes:

Numerical material ids and data values have been removed in Minecraft. This requires a significant number of changes to any functions or events that handle items or blocks. Though old inputs should continue to work for the most part, deprecation warnings have been inserted when converting from old values, as these are no longer guaranteed to have perfect conversion. Most affected "get" functions and event data output the new material names, so it's impossible to automatically detect all places scripts need to be updated. Saved item arrays will still work in all functions, but a convert_legacy_item() function has been provided to better guarantee conversion accuracy for certain old materials with name conflicts. (eg. MELON) A key "isInteractable" has been added to material_info().

In the item array output, the "type" key and the redundant "enchants" key were removed.

The following functions were removed: data_values() and data_name().

The following functions were deprecated completely: set_block_at() and get_block_at().

The following functions were added: get_blockdata_string(), set_blockdata_string(), and convert_legacy_item()

The following functions' inputs and/or outputs may be affected: can_enchant_target(), get_enchants(), entity_spec() and set_entity_spec() for enderman and minecart blocks, phas_item(), pitem_slot(), pgive_item(), ptake_item(), pgive_enderchest_item(), ptake_enderchest_item(),  add_to_inventory(), take_from_inventory(), max_stack_size(), material_info(), entity_line_of_sight() and pcursor() (transparent block array), pinfo(), psend_block_change(), and spawn_falling_block(). (not including any item array changes)

The following events' prefilters, event data, and possibly mutable data were affected: piston_retract, piston_extend, block_break, block_place, block_burn, block_ignite, block_from_to, block_dispense, block_grow, note_play (no more mutable data), block_fade, item_despawn, item_spawn, item_drop, item_pickup, entity_change_block, entity_interact, inventory_click, inventory_drag, item_swap, player_interact, and vehicle_collide (not including any item array changes in event data)
  • Loading branch information...
PseudoKnight committed Aug 8, 2018
1 parent f6fcd5b commit 03f9d187d485898cb73689c041a5b92be10df694
Showing with 2,411 additions and 10,910 deletions.
  1. +3 −3 src/main/java/com/laytonsmith/abstraction/Convertor.java
  2. +3 −9 src/main/java/com/laytonsmith/abstraction/MCItemStack.java
  3. +3 −2 src/main/java/com/laytonsmith/abstraction/MCLivingEntity.java
  4. +0 −10 src/main/java/com/laytonsmith/abstraction/MCMaterialData.java
  5. +3 −0 src/main/java/com/laytonsmith/abstraction/MCServer.java
  6. +2 −1 src/main/java/com/laytonsmith/abstraction/MCWorld.java
  7. +0 −20 src/main/java/com/laytonsmith/abstraction/StaticLayer.java
  8. +16 −2 src/main/java/com/laytonsmith/abstraction/blocks/MCBlock.java
  9. +8 −0 src/main/java/com/laytonsmith/abstraction/blocks/MCBlockData.java
  10. +0 −17 src/main/java/com/laytonsmith/abstraction/blocks/MCBlockState.java
  11. +4 −3 src/main/java/com/laytonsmith/abstraction/blocks/MCMaterial.java
  12. +54 −35 src/main/java/com/laytonsmith/abstraction/bukkit/BukkitConvertor.java
  13. +12 −26 src/main/java/com/laytonsmith/abstraction/bukkit/BukkitMCItemStack.java
  14. +0 −56 src/main/java/com/laytonsmith/abstraction/bukkit/BukkitMCMaterialData.java
  15. +7 −0 src/main/java/com/laytonsmith/abstraction/bukkit/BukkitMCServer.java
  16. +8 −9 src/main/java/com/laytonsmith/abstraction/bukkit/BukkitMCWorld.java
  17. +31 −12 src/main/java/com/laytonsmith/abstraction/bukkit/blocks/BukkitMCBlock.java
  18. +45 −0 src/main/java/com/laytonsmith/abstraction/bukkit/blocks/BukkitMCBlockData.java
  19. +0 −22 src/main/java/com/laytonsmith/abstraction/bukkit/blocks/BukkitMCBlockState.java
  20. +11 −8 src/main/java/com/laytonsmith/abstraction/bukkit/blocks/BukkitMCMaterial.java
  21. +7 −7 src/main/java/com/laytonsmith/abstraction/bukkit/entities/BukkitMCEnderman.java
  22. +18 −13 src/main/java/com/laytonsmith/abstraction/bukkit/entities/BukkitMCLivingEntity.java
  23. +7 −7 src/main/java/com/laytonsmith/abstraction/bukkit/entities/BukkitMCMinecart.java
  24. +11 −2 src/main/java/com/laytonsmith/abstraction/bukkit/entities/BukkitMCPlayer.java
  25. +11 −8 src/main/java/com/laytonsmith/abstraction/bukkit/events/BukkitEntityEvents.java
  26. +3 −3 src/main/java/com/laytonsmith/abstraction/entities/MCEnderman.java
  27. +3 −3 src/main/java/com/laytonsmith/abstraction/entities/MCMinecart.java
  28. +532 −0 src/main/java/com/laytonsmith/abstraction/enums/bukkit/BukkitMCLegacyMaterial.java
  29. +2 −1 src/main/java/com/laytonsmith/abstraction/events/MCEntityChangeBlockEvent.java
  30. +2 −0 src/main/java/com/laytonsmith/commandhelper/CommandHelperPlugin.java
  31. +38 −31 src/main/java/com/laytonsmith/core/ObjectGenerator.java
  32. +5 −34 src/main/java/com/laytonsmith/core/Static.java
  33. +1 −1 src/main/java/com/laytonsmith/core/events/Prefilters.java
  34. +474 −382 src/main/java/com/laytonsmith/core/events/drivers/BlockEvents.java
  35. +143 −36 src/main/java/com/laytonsmith/core/events/drivers/EntityEvents.java
  36. +76 −23 src/main/java/com/laytonsmith/core/events/drivers/InventoryEvents.java
  37. +74 −13 src/main/java/com/laytonsmith/core/events/drivers/PlayerEvents.java
  38. +26 −7 src/main/java/com/laytonsmith/core/events/drivers/VehicleEvents.java
  39. +91 −81 src/main/java/com/laytonsmith/core/functions/Enchantments.java
  40. +13 −13 src/main/java/com/laytonsmith/core/functions/EntityManagement.java
  41. +268 −11 src/main/java/com/laytonsmith/core/functions/Environment.java
  42. +144 −30 src/main/java/com/laytonsmith/core/functions/InventoryManagement.java
  43. +110 −195 src/main/java/com/laytonsmith/core/functions/Minecraft.java
  44. +19 −3 src/main/java/com/laytonsmith/core/functions/MobManagement.java
  45. +65 −24 src/main/java/com/laytonsmith/core/functions/PlayerManagement.java
  46. +36 −13 src/main/java/com/laytonsmith/core/functions/World.java
  47. +10 −10 src/main/java/com/laytonsmith/tools/Interpreter.java
  48. +0 −756 src/main/resources/data_names.txt
  49. +0 −8,956 src/main/resources/data_values.txt
  50. +2 −2 src/test/java/com/laytonsmith/core/functions/EnchantmentsTest.java
  51. +10 −10 src/test/java/com/laytonsmith/testing/StaticTest.java
@@ -55,11 +55,11 @@
void Startup(CommandHelperPlugin chp);
int LookupItemId(String materialName);
MCMaterial getMaterial(int id);
String LookupMaterialName(int id);
MCMaterial GetMaterialFromLegacy(String name, int data);
MCMaterial getMaterial(int id);
MCMaterial GetMaterialFromLegacy(int id, int data);
MCMaterial GetMaterial(String name);
@@ -5,8 +5,6 @@
public interface MCItemStack extends AbstractionObject {
MCMaterialData getData();
short getDurability();
/**
@@ -27,23 +25,19 @@
MCMaterial getType();
/**
* @deprecated Magic value
*/
@Deprecated
void setTypeId(int type);
void setType(MCMaterial type);
int maxStackSize();
int getAmount();
void setAmount(int amt);
void setData(int data);
boolean hasItemMeta();
MCItemMeta getItemMeta();
void setItemMeta(MCItemMeta im);
boolean isEmpty();
}
@@ -1,6 +1,7 @@
package com.laytonsmith.abstraction;
import com.laytonsmith.abstraction.blocks.MCBlock;
import com.laytonsmith.abstraction.blocks.MCMaterial;
import com.laytonsmith.core.constructs.Target;
import java.util.HashSet;
@@ -53,11 +54,11 @@
MCLivingEntity getTarget(Target t);
MCBlock getTargetBlock(HashSet<Short> transparent, int maxDistance);
MCBlock getTargetBlock(HashSet<MCMaterial> transparent, int maxDistance);
MCBlock getTargetSpace(int maxDistance);
List<MCBlock> getLineOfSight(HashSet<Short> transparent, int maxDistance);
List<MCBlock> getLineOfSight(HashSet<MCMaterial> transparent, int maxDistance);
boolean hasLineOfSight(MCEntity other);

This file was deleted.

Oops, something went wrong.
@@ -1,5 +1,6 @@
package com.laytonsmith.abstraction;
import com.laytonsmith.abstraction.blocks.MCBlockData;
import com.laytonsmith.abstraction.enums.MCBarColor;
import com.laytonsmith.abstraction.enums.MCBarStyle;
import com.laytonsmith.abstraction.enums.MCInventoryType;
@@ -162,4 +163,6 @@
String dispatchAndCaptureCommand(MCCommandSender commandSender, String cmd);
MCBossBar createBossBar(String title, MCBarColor color, MCBarStyle style);
MCBlockData createBlockData(String data);
}
@@ -1,6 +1,7 @@
package com.laytonsmith.abstraction;
import com.laytonsmith.abstraction.blocks.MCBlock;
import com.laytonsmith.abstraction.blocks.MCBlockData;
import com.laytonsmith.abstraction.entities.MCFallingBlock;
import com.laytonsmith.abstraction.entities.MCFirework;
import com.laytonsmith.abstraction.entities.MCItem;
@@ -128,7 +129,7 @@
CArray spawnMob(MCMobs name, String subClass, int qty, MCLocation location, Target t);
MCFallingBlock spawnFallingBlock(MCLocation loc, int type, byte data);
MCFallingBlock spawnFallingBlock(MCLocation loc, MCBlockData data);
MCFirework launchFirework(MCLocation l, int strength, List<MCFireworkEffect> effects);
@@ -116,26 +116,6 @@ public static MCMetadataValue GetMetadataValue(Object value, MCPlugin plugin) {
return convertor.GetMetadataValue(value, plugin);
}
/**
* Returns the data value of the specified material name, or -1 if none was found.
*
* @param materialName
* @return
*/
public static int LookupItemId(String materialName) {
return convertor.LookupItemId(materialName);
}
/**
* Returns the name of the material, given the material's ID.
*
* @param id
* @return
*/
public static String LookupMaterialName(int id) {
return convertor.LookupMaterialName(id);
}
/**
* Adds a runnable to the main thread, if required by this platform, if a multithreaded user code would be
* dangerous.
@@ -9,8 +9,6 @@
public interface MCBlock extends MCMetadatable {
boolean isNull();
MCMaterial getType();
/**
@@ -19,16 +17,26 @@
@Deprecated
int getTypeId();
/**
* @deprecated Magic value
*/
@Deprecated
byte getData();
void setType(MCMaterial mat);
void setType(MCMaterial mat, boolean physics);
/**
* @deprecated Magic value
*/
@Deprecated
void setTypeId(int idata);
/**
* @deprecated Magic value
*/
@Deprecated
void setData(byte imeta);
/**
@@ -37,6 +45,10 @@
@Deprecated
void setTypeAndData(int type, byte data, boolean physics);
MCBlockData getBlockData();
void setBlockData(MCBlockData data, boolean physics);
MCBlockState getState();
MCWorld getWorld();
@@ -88,4 +100,6 @@
MCBlock getRelative(MCBlockFace face);
MCBlockFace getFace(MCBlock get);
boolean isEmpty();
}
@@ -0,0 +1,8 @@
package com.laytonsmith.abstraction.blocks;
import com.laytonsmith.abstraction.AbstractionObject;
public interface MCBlockData extends AbstractionObject {
MCMaterial getMaterial();
String getAsString();
}
@@ -1,29 +1,12 @@
package com.laytonsmith.abstraction.blocks;
import com.laytonsmith.abstraction.MCLocation;
import com.laytonsmith.abstraction.MCMaterialData;
import com.laytonsmith.abstraction.MCMetadatable;
public interface MCBlockState extends MCMetadatable {
MCMaterialData getData();
MCMaterial getType();
/**
* @deprecated Magic value
*/
@Deprecated
int getTypeId();
/**
* @deprecated Magic value
*/
@Deprecated
void setTypeId(int type);
void setRawData(byte data);
MCBlock getBlock();
MCLocation getLocation();
@@ -1,16 +1,15 @@
package com.laytonsmith.abstraction.blocks;
import com.laytonsmith.abstraction.AbstractionObject;
import com.laytonsmith.abstraction.MCMaterialData;
public interface MCMaterial extends AbstractionObject {
MCBlockData createBlockData();
short getMaxDurability();
int getType();
MCMaterialData getData();
String getName();
int getMaxStackSize();
@@ -32,4 +31,6 @@
boolean isSolid();
boolean isTransparent();
boolean isInteractable();
}
@@ -68,6 +68,7 @@
import com.laytonsmith.abstraction.enums.MCRecipeType;
import com.laytonsmith.abstraction.enums.MCTone;
import com.laytonsmith.abstraction.enums.MCVersion;
import com.laytonsmith.abstraction.enums.bukkit.BukkitMCLegacyMaterial;
import com.laytonsmith.abstraction.enums.bukkit.BukkitMCDyeColor;
import com.laytonsmith.abstraction.enums.bukkit.BukkitMCEntityType;
import com.laytonsmith.abstraction.enums.bukkit.BukkitMCPatternShape;
@@ -197,18 +198,55 @@ public MCServer GetServer() {
@Override
public MCMaterial getMaterial(int id) {
Material mat = Material.getMaterial(id);
Material mat = BukkitMCLegacyMaterial.getMaterial(id);
return mat == null ? null : new BukkitMCMaterial(mat);
}
@Override
public MCItemStack GetItemStack(int type, int qty) {
return new BukkitMCItemStack(new ItemStack(type, qty));
public MCMaterial GetMaterialFromLegacy(String mat, int data) {
Material m = BukkitMCLegacyMaterial.getMaterial(mat, data);
return m == null ? null : new BukkitMCMaterial(m);
}
@Override
public MCItemStack GetItemStack(int type, int data, int qty) {
return new BukkitMCItemStack(new ItemStack(type, qty, (short) data));
public MCMaterial GetMaterialFromLegacy(int id, int data) {
Material m = BukkitMCLegacyMaterial.getMaterial(id, data);
return m == null ? null : new BukkitMCMaterial(m);
}
@Override
public MCMaterial GetMaterial(String name) {
// Fast match
Material match = Material.getMaterial(name);
if(match != null) {
return new BukkitMCMaterial(match);
}
// Try legacy
match = Material.getMaterial(name, true);
if(match != null) {
return new BukkitMCMaterial(match);
}
// Try fuzzy match
match = Material.matchMaterial(name);
if(match != null) {
return new BukkitMCMaterial(match);
}
return null;
}
@Override
public MCItemStack GetItemStack(int id, int qty) {
Material mat = BukkitMCLegacyMaterial.getMaterial(id);
if(mat == null) {
return new BukkitMCItemStack(new ItemStack(Material.AIR));
}
return new BukkitMCItemStack(new ItemStack(mat, qty));
}
@Override
public MCItemStack GetItemStack(int id, int data, int qty) {
Material mat = BukkitMCLegacyMaterial.getMaterial(id, data);
return new BukkitMCItemStack(new ItemStack(mat, qty, (short) data));
}
@Override
@@ -225,7 +263,10 @@ public MCItemStack GetItemStack(MCMaterial type, int data, int qty) {
public MCItemStack GetItemStack(String type, int qty) {
Material mat = Material.getMaterial(type);
if(mat == null) {
return null;
mat = Material.getMaterial(type, true);
if(mat == null) {
return new BukkitMCItemStack(new ItemStack(Material.AIR));
}
}
return new BukkitMCItemStack(new ItemStack(mat, qty));
}
@@ -234,7 +275,13 @@ public MCItemStack GetItemStack(String type, int qty) {
public MCItemStack GetItemStack(String type, int data, int qty) {
Material mat = Material.getMaterial(type);
if(mat == null) {
return null;
mat = BukkitMCLegacyMaterial.getMaterial(type, data);
} else if(mat.getMaxDurability() == 0) {
// only do this for non-damageable items with data values, which don't exist for modern materials
Material converted = BukkitMCLegacyMaterial.getMaterial(type, data);
if(converted != null) {
mat = converted;
}
}
return new BukkitMCItemStack(new ItemStack(mat, qty, (short) data));
}
@@ -271,21 +318,6 @@ public void Startup(CommandHelperPlugin chp) {
chp.registerEvents(WORLD_LISTENER);
}
@Override
public int LookupItemId(String materialName) {
Material mat = Material.matchMaterial(materialName);
if(mat != null) {
return mat.getId();
} else {
return -1;
}
}
@Override
public String LookupMaterialName(int id) {
return Material.getMaterial(id).toString();
}
@Override
protected void triggerRunnable(final Runnable r) {
try {
@@ -711,19 +743,6 @@ public static MCCommandSender BukkitGetCorrectSender(CommandSender sender) {
}
}
@Override
public MCMaterial GetMaterial(String name) {
Material match = Material.getMaterial(name);
if(match == null) {
// Try harder
match = Material.matchMaterial(name);
if(match == null) {
return null;
}
}
return new BukkitMCMaterial(match);
}
@Override
public String GetPluginName() {
return (String) new Yaml().loadAs(getClass().getResourceAsStream("/plugin.yml"), Map.class).get("name");
Oops, something went wrong.

0 comments on commit 03f9d18

Please sign in to comment.