|
36 | 36 | import com.laytonsmith.abstraction.entities.MCChestedHorse; |
37 | 37 | import com.laytonsmith.abstraction.entities.MCCommandMinecart; |
38 | 38 | import com.laytonsmith.abstraction.entities.MCCreeper; |
| 39 | +import com.laytonsmith.abstraction.entities.MCDisplay; |
39 | 40 | import com.laytonsmith.abstraction.entities.MCEnderCrystal; |
40 | 41 | import com.laytonsmith.abstraction.entities.MCEnderDragon; |
41 | 42 | import com.laytonsmith.abstraction.entities.MCEnderSignal; |
@@ -4974,4 +4975,228 @@ public Set<Optimizable.OptimizationOption> optimizationOptions() { |
4974 | 4975 |
|
4975 | 4976 | } |
4976 | 4977 |
|
| 4978 | + @api(environments = {CommandHelperEnvironment.class}) |
| 4979 | + @seealso({set_display_entity.class}) |
| 4980 | + public static class get_display_entity extends AbstractFunction { |
| 4981 | + |
| 4982 | + @Override |
| 4983 | + public String getName() { |
| 4984 | + return "get_display_entity"; |
| 4985 | + } |
| 4986 | + |
| 4987 | + @Override |
| 4988 | + public Integer[] numArgs() { |
| 4989 | + return new Integer[]{1}; |
| 4990 | + } |
| 4991 | + |
| 4992 | + @Override |
| 4993 | + public String docs() { |
| 4994 | + return "array {entityUUID} Returns an associative array of display entity data." |
| 4995 | + + " Array keys are: 'billboard', 'brightness', 'glowcolor', 'height', 'width'," |
| 4996 | + + " 'viewrange', 'shadowradius', and 'shadowstrength'. ---- " |
| 4997 | + + " The following values are common to all display entity types. Data about specific display entity" |
| 4998 | + + " types (block, text, and item display entities) can be found in {{function|entity_spec}}." |
| 4999 | + + " * '''billboard''' (string) : Controls which axes the rendered entity rotates around the entity" |
| 5000 | + + " location when the viewing player's position or facing changes. FIXED (default) will not rotate." |
| 5001 | + + " HORIZONTAL or VERTICAL rotate on their respective axes. CENTER rotates on both axes." |
| 5002 | + + " * '''brightness''' (array) : Controls the brightness when rendering the display entity." |
| 5003 | + + " A null value (default) will render the entity based on the environment." |
| 5004 | + + " An array with int values for the keys '''\"block\"''' and '''\"sky\"''' simulate the rendering" |
| 5005 | + + " brightness from those respective light sources. Each must be from 0 - 15." |
| 5006 | + + " Optionally a single int can be provided and will be used for both sky and block sources." |
| 5007 | + + " * '''glowcolor''' (array) : An RGB array for the entity glow color. If null (default), the" |
| 5008 | + + " entity will use its scoreboard team color, if it has one." |
| 5009 | + + " * '''height''' (double) : The maximum height of the entity's bounding box. (default: 0.0)" |
| 5010 | + + " Spans vertically from the entity's y location to (y+height), and is used for culling." |
| 5011 | + + " If the client's field of view does not include this box, the entity will not be rendered." |
| 5012 | + + " If either width or height is 0.0, culling is disabled." |
| 5013 | + + " * '''width''' (double) : The maximum width of the entity's bounding box. (default: 0.0)" |
| 5014 | + + " Spans horizontally (width/2) from entity location." |
| 5015 | + + " * '''viewrange''' (double) : The relative distance the entity will be viewable." |
| 5016 | + + " The default is 1.0, which is 64 meters multiplied by the player's entity distance scaling." |
| 5017 | + + " This can also be limited by the world's entity-tracking-range for display entities." |
| 5018 | + + " * '''shadowradius''' (double) : The visible radius in meters of the entity's shadow." |
| 5019 | + + " Effective range is from 0.0 (default) to 64.0." |
| 5020 | + + " * '''shadowstrength''' (double) : The opacity of the entity's shadow as a function of distance" |
| 5021 | + + " to a block below the entity within shadowradius. (default: 1.0)" |
| 5022 | + + " * '''teleportduration''' (int) : The duration in ticks a teleport is interpolated on the client." |
| 5023 | + + " Range is strictly from 0 - 59. (default: 0) (MC 1.20.2+)"; |
| 5024 | + } |
| 5025 | + |
| 5026 | + @Override |
| 5027 | + public Mixed exec(Target t, com.laytonsmith.core.environments.Environment environment, Mixed... args) throws ConfigRuntimeException { |
| 5028 | + MCEntity entity = Static.getEntity(args[0], t); |
| 5029 | + if(!(entity instanceof MCDisplay display)) { |
| 5030 | + throw new CREBadEntityException("Not a display entity.", t); |
| 5031 | + } |
| 5032 | + CArray info = CArray.GetAssociativeArray(t); |
| 5033 | + info.set("billboard", display.getBillboard().name()); |
| 5034 | + MCDisplay.Brightness brightness = display.getBrightness(); |
| 5035 | + if(brightness != null) { |
| 5036 | + CArray brightnessArray = CArray.GetAssociativeArray(t); |
| 5037 | + brightnessArray.set("block", new CInt(brightness.block(), t), t); |
| 5038 | + brightnessArray.set("sky", new CInt(brightness.block(), t), t); |
| 5039 | + info.set("brightness", brightnessArray, t); |
| 5040 | + } else { |
| 5041 | + info.set("brightness", CNull.NULL, t); |
| 5042 | + } |
| 5043 | + MCColor color = display.getGlowColorOverride(); |
| 5044 | + if(color != null) { |
| 5045 | + info.set("glowcolor", ObjectGenerator.GetGenerator().color(color, t), t); |
| 5046 | + } else { |
| 5047 | + info.set("glowcolor", CNull.NULL, t); |
| 5048 | + } |
| 5049 | + info.set("height", new CDouble(display.getDisplayHeight(), t), t); |
| 5050 | + info.set("width", new CDouble(display.getDisplayWidth(), t), t); |
| 5051 | + info.set("viewrange", new CDouble(display.getViewRange(), t), t); |
| 5052 | + info.set("shadowradius", new CDouble(display.getShadowRadius(), t), t); |
| 5053 | + info.set("shadowstrength", new CDouble(display.getShadowStrength(), t), t); |
| 5054 | + if(Static.getServer().getMinecraftVersion().gte(MCVersion.MC1_20_2)) { |
| 5055 | + info.set("teleportduration", new CInt(display.getTeleportDuration(), t), t); |
| 5056 | + } |
| 5057 | + return info; |
| 5058 | + } |
| 5059 | + |
| 5060 | + @Override |
| 5061 | + public Class<? extends CREThrowable>[] thrown() { |
| 5062 | + return new Class[] {CREBadEntityException.class, CRELengthException.class, CREFormatException.class}; |
| 5063 | + } |
| 5064 | + |
| 5065 | + @Override |
| 5066 | + public Version since() { |
| 5067 | + return MSVersion.V3_3_5; |
| 5068 | + } |
| 5069 | + |
| 5070 | + @Override |
| 5071 | + public boolean isRestricted() { |
| 5072 | + return true; |
| 5073 | + } |
| 5074 | + |
| 5075 | + @Override |
| 5076 | + public Boolean runAsync() { |
| 5077 | + return false; |
| 5078 | + } |
| 5079 | + |
| 5080 | + } |
| 5081 | + |
| 5082 | + @api(environments = {CommandHelperEnvironment.class}) |
| 5083 | + @seealso({get_display_entity.class}) |
| 5084 | + public static class set_display_entity extends AbstractFunction { |
| 5085 | + |
| 5086 | + @Override |
| 5087 | + public String getName() { |
| 5088 | + return "set_display_entity"; |
| 5089 | + } |
| 5090 | + |
| 5091 | + @Override |
| 5092 | + public Integer[] numArgs() { |
| 5093 | + return new Integer[]{2}; |
| 5094 | + } |
| 5095 | + |
| 5096 | + @Override |
| 5097 | + public String docs() { |
| 5098 | + return "void {entityUUID, array} Sets the data for a display entity." |
| 5099 | + + " See {{function|get_display_entity}} for details about the array format."; |
| 5100 | + } |
| 5101 | + |
| 5102 | + @Override |
| 5103 | + public Mixed exec(Target t, com.laytonsmith.core.environments.Environment environment, Mixed... args) throws ConfigRuntimeException { |
| 5104 | + MCEntity entity = Static.getEntity(args[0], t); |
| 5105 | + if(!(entity instanceof MCDisplay display)) { |
| 5106 | + throw new CREBadEntityException("Not a display entity.", t); |
| 5107 | + } |
| 5108 | + CArray info = ArgumentValidation.getArray(args[1], t); |
| 5109 | + if(!info.isAssociative()) { |
| 5110 | + throw new CREIllegalArgumentException("Expected an associative array but found a normal array.", t); |
| 5111 | + } |
| 5112 | + if(info.containsKey("billboard")) { |
| 5113 | + try { |
| 5114 | + MCDisplay.Billboard billboard = MCDisplay.Billboard.valueOf(info.get("billboard", t).val()); |
| 5115 | + display.setBillboard(billboard); |
| 5116 | + } catch (IllegalArgumentException ex) { |
| 5117 | + throw new CREFormatException("Invalid billboard type for display entity.", t); |
| 5118 | + } |
| 5119 | + } |
| 5120 | + if(info.containsKey("brightness")) { |
| 5121 | + Mixed m = info.get("brightness", t); |
| 5122 | + if(m instanceof CNull) { |
| 5123 | + display.setBrightness(null); |
| 5124 | + } else { |
| 5125 | + MCDisplay.Brightness brightness; |
| 5126 | + if(m.isInstanceOf(CArray.TYPE)) { |
| 5127 | + CArray brightnessArray = (CArray) m; |
| 5128 | + if(!brightnessArray.isAssociative()) { |
| 5129 | + throw new CREIllegalArgumentException( |
| 5130 | + "Expected an associative array for brightness but found a normal array.", t); |
| 5131 | + } |
| 5132 | + int blockBrightness = ArgumentValidation.getInt32(brightnessArray.get("block", t), t); |
| 5133 | + int skyBrightness = ArgumentValidation.getInt32(brightnessArray.get("sky", t), t); |
| 5134 | + brightness = new MCDisplay.Brightness(blockBrightness, skyBrightness); |
| 5135 | + display.setBrightness(new MCDisplay.Brightness(blockBrightness, skyBrightness)); |
| 5136 | + } else { |
| 5137 | + int level = ArgumentValidation.getInt32(m, t); |
| 5138 | + brightness = new MCDisplay.Brightness(level, level); |
| 5139 | + } |
| 5140 | + try { |
| 5141 | + display.setBrightness(brightness); |
| 5142 | + } catch (IllegalArgumentException ex) { |
| 5143 | + throw new CREIllegalArgumentException(ex.getMessage(), t); |
| 5144 | + } |
| 5145 | + } |
| 5146 | + } |
| 5147 | + if(info.containsKey("glowcolor")) { |
| 5148 | + Mixed m = info.get("glowcolor", t); |
| 5149 | + if(!(m instanceof CNull)) { |
| 5150 | + MCColor color = ObjectGenerator.GetGenerator().color(ArgumentValidation.getArray(m, t), t); |
| 5151 | + display.setGlowColorOverride(color); |
| 5152 | + } |
| 5153 | + } |
| 5154 | + if(info.containsKey("height")) { |
| 5155 | + display.setDisplayHeight((float) ArgumentValidation.getDouble(info.get("height", t), t)); |
| 5156 | + } |
| 5157 | + if(info.containsKey("width")) { |
| 5158 | + display.setDisplayWidth((float) ArgumentValidation.getDouble(info.get("width", t), t)); |
| 5159 | + } |
| 5160 | + if(info.containsKey("viewrange")) { |
| 5161 | + display.setViewRange((float) ArgumentValidation.getDouble(info.get("viewrange", t), t)); |
| 5162 | + } |
| 5163 | + if(info.containsKey("shadowradius")) { |
| 5164 | + display.setShadowRadius((float) ArgumentValidation.getDouble(info.get("shadowradius", t), t)); |
| 5165 | + } |
| 5166 | + if(info.containsKey("shadowstrength")) { |
| 5167 | + display.setShadowStrength((float) ArgumentValidation.getDouble(info.get("shadowstrength", t), t)); |
| 5168 | + } |
| 5169 | + if(info.containsKey("teleportduration") && Static.getServer().getMinecraftVersion().gte(MCVersion.MC1_20_2)) { |
| 5170 | + int ticks = ArgumentValidation.getInt32(info.get("teleportduration", t), t); |
| 5171 | + if(ticks < 0 || ticks > 59) { |
| 5172 | + throw new CRERangeException("Teleport duration must be from 0 - 59, but got " + ticks, t); |
| 5173 | + } |
| 5174 | + display.setTeleportDuration(ticks); |
| 5175 | + } |
| 5176 | + return CVoid.VOID; |
| 5177 | + } |
| 5178 | + |
| 5179 | + @Override |
| 5180 | + public Class<? extends CREThrowable>[] thrown() { |
| 5181 | + return new Class[] {CREBadEntityException.class, CRELengthException.class, CREFormatException.class, |
| 5182 | + CREIllegalArgumentException.class, CRECastException.class, CRERangeException.class}; |
| 5183 | + } |
| 5184 | + |
| 5185 | + @Override |
| 5186 | + public Version since() { |
| 5187 | + return MSVersion.V3_3_5; |
| 5188 | + } |
| 5189 | + |
| 5190 | + @Override |
| 5191 | + public boolean isRestricted() { |
| 5192 | + return true; |
| 5193 | + } |
| 5194 | + |
| 5195 | + @Override |
| 5196 | + public Boolean runAsync() { |
| 5197 | + return false; |
| 5198 | + } |
| 5199 | + |
| 5200 | + } |
| 5201 | + |
4977 | 5202 | } |
0 commit comments