├── .github ├── images │ └── banner.png └── workflows │ └── release.yml ├── LICENSE ├── README.md ├── pom.xml └── src └── main ├── java └── de │ └── kcodeyt │ └── vanilla │ ├── VanillaGeneratorPlugin.java │ ├── behavior │ ├── LootTable.java │ ├── LootTableBuilder.java │ ├── LootTableManager.java │ ├── LootTableNumber.java │ ├── Pool.java │ ├── PoolEntry.java │ └── function │ │ ├── EnchantRandomlyFunction.java │ │ ├── EnchantWithLevelsFunction.java │ │ ├── FunctionRegistry.java │ │ ├── LootTableFunction.java │ │ ├── RandomAuxValueFunction.java │ │ ├── SetCountFunction.java │ │ ├── SetDamageFunction.java │ │ ├── SetDataFunction.java │ │ └── SpecificEnchantsFunction.java │ ├── command │ ├── LocateCommand.java │ ├── SudoCommand.java │ └── WorldCommand.java │ ├── enchantment │ ├── EnchantmentHelper.java │ ├── EnchantmentHolder.java │ ├── EnchantmentRarity.java │ ├── EnchantmentType.java │ ├── Enchantments.java │ ├── ItemEnchantment.java │ ├── VanillaEnchantment.java │ └── defaults │ │ ├── AquaAffinityEnchantment.java │ │ ├── BindingCurseEnchantment.java │ │ ├── ChannelingEnchantment.java │ │ ├── DamageEnchantment.java │ │ ├── DepthStriderEnchantment.java │ │ ├── EfficiencyEnchantment.java │ │ ├── FireAspectEnchantment.java │ │ ├── FlameEnchantment.java │ │ ├── FrostWalkerEnchantment.java │ │ ├── ImpalingEnchantment.java │ │ ├── InfinityEnchantment.java │ │ ├── KnockbackEnchantment.java │ │ ├── LootBonusEnchantment.java │ │ ├── LoyaltyEnchantment.java │ │ ├── LureEnchantment.java │ │ ├── MendingEnchantment.java │ │ ├── MultishotEnchantment.java │ │ ├── PiercingEnchantment.java │ │ ├── PowerEnchantment.java │ │ ├── ProtectionEnchantment.java │ │ ├── PunchEnchantment.java │ │ ├── QuickChargeEnchantment.java │ │ ├── RespirationEnchantment.java │ │ ├── RiptideEnchantment.java │ │ ├── SilkTouchEnchantment.java │ │ ├── SoulSpeedEnchantment.java │ │ ├── SwiftSneakEnchantment.java │ │ ├── ThornsEnchantment.java │ │ ├── UnbreakingEnchantment.java │ │ └── VanishingCurseEnchantment.java │ ├── generator │ ├── Vanilla.java │ ├── VanillaNether.java │ ├── VanillaOverworld.java │ ├── VanillaTheEnd.java │ ├── chunk │ │ ├── ChunkData.java │ │ ├── ChunkRequest.java │ │ └── ChunkWaiter.java │ ├── client │ │ ├── Client.java │ │ ├── ConnectionState.java │ │ ├── MojangLoginForger.java │ │ ├── Network.java │ │ ├── clientdata │ │ │ ├── DeviceOS.java │ │ │ ├── LoginData.java │ │ │ ├── Skin.java │ │ │ └── UIProfile.java │ │ └── handler │ │ │ ├── LoginHandler.java │ │ │ ├── NetworkHandler.java │ │ │ ├── PlayingHandler.java │ │ │ └── ResourcePackHandler.java │ └── server │ │ ├── BedrockDedicatedServer.java │ │ ├── ProcessWrapper.java │ │ └── VanillaServer.java │ ├── util │ ├── GameVersion.java │ ├── ItemIdentifier.java │ ├── NbtConverter.java │ ├── Palette.java │ ├── SimpleMath.java │ ├── WebRequest.java │ ├── WeightedRandom.java │ └── ZipHelper.java │ └── world │ ├── BlockEntityData.java │ ├── World.java │ └── blockentity │ ├── BasicCreator.java │ ├── BasicFurnaceCreator.java │ ├── BeehiveCreator.java │ ├── BlockEntityCreator.java │ ├── BrewingStandCreator.java │ ├── ChestCreator.java │ ├── ItemFrameCreator.java │ ├── LecternCreator.java │ └── MobSpawnerCreator.java └── resources ├── config.yml └── plugin.yml /.github/images/banner.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/KCodeYT/VanillaGenerator/10254c70a678c13bce9e9fa66faf570673ad3bca/.github/images/banner.png -------------------------------------------------------------------------------- /.github/workflows/release.yml: -------------------------------------------------------------------------------- 1 | name: Release this plugin 2 | 3 | on: 4 | push: 5 | branches: [ release ] 6 | 7 | jobs: 8 | build: 9 | runs-on: ubuntu-latest 10 | steps: 11 | - name: Checkout github repository 12 | uses: actions/checkout@v3 13 | 14 | - name: Set up JDK 17 15 | uses: actions/setup-java@v3 16 | with: 17 | java-version: '17' 18 | distribution: 'temurin' 19 | cache: maven 20 | 21 | - name: Get name and version from pom.xml 22 | run: | 23 | VER=$(mvn help:evaluate -Dexpression=project.version -q -DforceStdout) 24 | echo "VER=$VER" >> $GITHUB_ENV 25 | NAME=$(mvn help:evaluate -Dexpression=project.artifactId -q -DforceStdout) 26 | echo "NAME=$NAME" >> $GITHUB_ENV 27 | 28 | - name: Build plugin 29 | run: mvn package 30 | 31 | - name: Delete old release 32 | uses: dev-drprasad/delete-tag-and-release@v0.2.0 33 | with: 34 | delete_release: true 35 | tag_name: ${{env.VER}} 36 | env: 37 | GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} 38 | 39 | - name: Create Release 40 | id: create_release 41 | uses: actions/create-release@v1 42 | env: 43 | GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} 44 | with: 45 | tag_name: ${{env.VER}} 46 | release_name: VanillaGenerator v${{env.VER}} 47 | 48 | - name: Upload plugin as release 49 | uses: actions/upload-release-asset@v1 50 | env: 51 | GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} 52 | with: 53 | upload_url: ${{steps.create_release.outputs.upload_url}} 54 | asset_path: target/${{env.NAME}}-${{env.VER}}.jar 55 | asset_name: VanillaGenerator.jar 56 | asset_content_type: application/java-archive 57 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | ![banner](./.github/images/banner.png) 2 | 3 | What is this? 4 | ------------------------------ 5 | 6 | This project is currently only a proof-of-concept work to present that a vanilla generator based on a background server 7 | would theoretically and practically work. 8 | This project adds a vanilla generator to the [powernukkitx](https://github.com/PowerNukkitX/PowerNukkitX/) server 9 | software. 10 | 11 | ⚠️ This plugin only works with powernukkitx for minecraft bedrock edition 1.19.60 (protocol 567) ⚠️ 12 | 13 | How can I download this plugin? 14 | ------------------------------ 15 | 16 | You can find the downloads on the [releases section](https://github.com/KCodeYT/VanillaGenerator/releases) of this 17 | github 18 | page. 19 | There you can find the LATEST jar file of this plugin. 20 | 21 | How can I access the generator? 22 | ------------------------------ 23 | 24 | 0. ⚠️ DO NOT RUN THIS PLUGIN ON A PRODUCTION SERVER ⚠️ 25 | (its not stable and uses much resources) 26 | 1. Add this plugin to your server. 27 | 2. Open the nukkit.yml file of your server. 28 | You need to add a new world to the worlds config in the nukkit.yml file. 29 | This world needs the generator "vanilla" for the overworld. 30 | If you want the world to be nether, then the generator needs to be "vanilla_nether". 31 | If you want the world to be the end, then the generator needs to be "vanilla_the_end". 32 | 3. Save the file and start your server. 33 | 34 | Example nukkit.yml world config (with all 3 world types): 35 | 36 | ```xml 37 | worlds: 38 | world: 39 | seed: 0123456789 40 | generator: vanilla 41 | nether: 42 | seed: 0123456789 43 | generator: vanilla_nether 44 | the_end: 45 | seed: 0123456789 46 | generator: vanilla_the_end 47 | ``` 48 | 49 | How does this plugin work? 50 | ------------------------------ 51 | 52 | This plugin works by adding 3 new generators to the server (vanilla, vanilla_nether, vanilla_the_end). 53 | Those generators start a bedrock dedicated server in the background. After they started bots join those servers and 54 | generate chunks continuously and clone them to the powernukkitx server when they are needed. 55 | As its well known that a bedrock dedicated server uses a lot of resources, with this plugin your server needs those 56 | resources too. 57 | -------------------------------------------------------------------------------- /pom.xml: -------------------------------------------------------------------------------- 1 | 2 | 5 | 4.0.0 6 | 7 | de.kcodeyt 8 | VanillaGenerator 9 | 0.0.14-SNAPSHOT 10 | 11 | 12 | 13 | opencollab-dev-repo 14 | https://repo.opencollab.dev/snapshot/ 15 | 16 | 17 | 18 | 19 | 20 | cn.powernukkitx 21 | powernukkitx 22 | 1.19.60-r1 23 | provided 24 | 25 | 26 | org.projectlombok 27 | lombok 28 | 1.18.24 29 | 30 | 31 | com.google.code.gson 32 | gson 33 | 2.10 34 | 35 | 36 | commons-io 37 | commons-io 38 | 2.11.0 39 | 40 | 41 | org.apache.commons 42 | commons-lang3 43 | 3.12.0 44 | 45 | 46 | it.unimi.dsi 47 | fastutil 48 | 8.5.9 49 | provided 50 | 51 | 52 | com.nukkitx.protocol 53 | bedrock-v567 54 | 2.9.16-SNAPSHOT 55 | compile 56 | 57 | 58 | com.nukkitx.fastutil 59 | * 60 | 61 | 62 | io.netty 63 | * 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | org.apache.maven.plugins 73 | maven-compiler-plugin 74 | 3.8.1 75 | 76 | 17 77 | 17 78 | 79 | 80 | 81 | org.apache.maven.plugins 82 | maven-shade-plugin 83 | 3.3.0 84 | 85 | 86 | package 87 | 88 | shade 89 | 90 | 91 | 92 | 93 | 94 | 95 | 96 | -------------------------------------------------------------------------------- /src/main/java/de/kcodeyt/vanilla/behavior/LootTable.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 KCodeYT 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package de.kcodeyt.vanilla.behavior; 18 | 19 | import cn.nukkit.inventory.Inventory; 20 | import cn.nukkit.item.Item; 21 | import de.kcodeyt.vanilla.VanillaGeneratorPlugin; 22 | import de.kcodeyt.vanilla.behavior.function.LootTableFunction; 23 | import de.kcodeyt.vanilla.util.ItemIdentifier; 24 | 25 | import java.util.ArrayList; 26 | import java.util.Collections; 27 | import java.util.List; 28 | import java.util.Random; 29 | import java.util.stream.Collectors; 30 | import java.util.stream.IntStream; 31 | 32 | /** 33 | * @author Kevims KCodeYT 34 | * @version 1.0-SNAPSHOT 35 | */ 36 | public record LootTable(String path, String name, List pools) { 37 | 38 | public void fillInventory(Inventory inventory, Long randomSeed) { 39 | final List freeSlots = IntStream.range(0, inventory.getSize()).filter(slot -> inventory.getItem(slot).isNull()).boxed().collect(Collectors.toList()); 40 | if(freeSlots.size() < inventory.getSize()) { 41 | VanillaGeneratorPlugin.getInstance().getLogger().warning("Tried to overfill inventory!"); 42 | return; 43 | } 44 | 45 | final Random random = randomSeed != null ? new Random(randomSeed) : new Random(); 46 | 47 | for(Pool pool : this.pools) { 48 | final List entries = new ArrayList<>(pool.entries()); 49 | final int rolls = pool.rolls().getAsInt(); 50 | for(int i = 0; i < rolls; i++) { 51 | Collections.shuffle(entries, random); 52 | 53 | final int fullWeight = entries.stream().mapToInt(PoolEntry::weight).sum(); 54 | int randomWeight = random.nextInt(fullWeight + 1); 55 | for(PoolEntry poolEntry : entries) { 56 | if((randomWeight -= poolEntry.weight()) <= 0) { 57 | final Integer slot; 58 | if(!poolEntry.type().equals("item") || poolEntry.name() == null) continue; 59 | 60 | Item item = Item.get(ItemIdentifier.getItemId(poolEntry.name())); 61 | if(item.getId() == Item.AIR) continue; 62 | 63 | for(LootTableFunction function : poolEntry.functions()) 64 | item = function.invoke(item, random); 65 | 66 | inventory.setItem(slot = freeSlots.get(random.nextInt(freeSlots.size())), item); 67 | freeSlots.remove(slot); 68 | if(freeSlots.isEmpty()) return; 69 | 70 | break; 71 | } 72 | } 73 | } 74 | } 75 | } 76 | 77 | } 78 | -------------------------------------------------------------------------------- /src/main/java/de/kcodeyt/vanilla/behavior/LootTableBuilder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 KCodeYT 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package de.kcodeyt.vanilla.behavior; 18 | 19 | import cn.nukkit.item.Item; 20 | import de.kcodeyt.vanilla.behavior.function.FunctionRegistry; 21 | import de.kcodeyt.vanilla.behavior.function.LootTableFunction; 22 | 23 | import java.util.ArrayList; 24 | import java.util.Collections; 25 | import java.util.List; 26 | import java.util.Map; 27 | 28 | /** 29 | * @author Kevims KCodeYT 30 | * @version 1.0-SNAPSHOT 31 | */ 32 | public class LootTableBuilder { 33 | 34 | public static LootTable build(String path, String name, Map lootTableMap) { 35 | if(!lootTableMap.containsKey("pools")) 36 | return new LootTable(path, name, Collections.emptyList()); 37 | 38 | try { 39 | final List pools = new ArrayList<>(); 40 | for(Object poolObject : ((List) lootTableMap.get("pools"))) { 41 | final Map poolMap = (Map) poolObject; 42 | final LootTableNumber rolls = LootTableNumber.of(poolMap.get("rolls")); 43 | 44 | final List entries = new ArrayList<>(); 45 | final List entriesList = (List) poolMap.get("entries"); 46 | for(Object entryObject : entriesList) { 47 | final Map entryMap = (Map) entryObject; 48 | final String entryType = (String) entryMap.get("type"); 49 | if(entryType == null) continue; 50 | 51 | final String entryName = (String) entryMap.get("name"); 52 | final int entryWeight = entryMap.containsKey("weight") ? (int) (double) (Object) entryMap.get("weight") : 1; 53 | if(!entryMap.containsKey("functions")) { 54 | entries.add(new PoolEntry(entryType, entryName, entryWeight, Collections.emptyList())); 55 | continue; 56 | } 57 | 58 | final List> functions = new ArrayList<>(); 59 | final List functionsList = (List) entryMap.get("functions"); 60 | for(Object functionObject : functionsList) { 61 | final Map functionMap = (Map) functionObject; 62 | final LootTableFunction function = FunctionRegistry.get((String) functionMap.get("function"), functionMap); 63 | 64 | if(function != null) functions.add(function); 65 | } 66 | 67 | entries.add(new PoolEntry(entryType, entryName, entryWeight, Collections.unmodifiableList(functions))); 68 | } 69 | 70 | pools.add(new Pool(rolls, Collections.unmodifiableList(entries))); 71 | } 72 | 73 | return new LootTable(path, name, Collections.unmodifiableList(pools)); 74 | } catch(NullPointerException e) { 75 | e.printStackTrace(); 76 | return null; 77 | } 78 | } 79 | 80 | } 81 | -------------------------------------------------------------------------------- /src/main/java/de/kcodeyt/vanilla/behavior/LootTableManager.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 KCodeYT 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package de.kcodeyt.vanilla.behavior; 18 | 19 | import com.google.gson.Gson; 20 | import lombok.Getter; 21 | import lombok.NoArgsConstructor; 22 | 23 | import java.io.BufferedReader; 24 | import java.io.File; 25 | import java.io.FileReader; 26 | import java.io.IOException; 27 | import java.util.HashSet; 28 | import java.util.Map; 29 | import java.util.Objects; 30 | import java.util.Set; 31 | 32 | /** 33 | * @author Kevims KCodeYT 34 | * @version 1.0-SNAPSHOT 35 | */ 36 | @NoArgsConstructor 37 | public class LootTableManager { 38 | 39 | private static final Gson GSON = new Gson(); 40 | 41 | @Getter 42 | private final Set lootTables = new HashSet<>(); 43 | 44 | public LootTable getLootTable(String name) { 45 | for(LootTable lootTable : this.lootTables) 46 | if(lootTable.path().equalsIgnoreCase(name) || lootTable.name().equalsIgnoreCase(name)) 47 | return lootTable; 48 | 49 | return null; 50 | } 51 | 52 | public void loadPacks(File packsDir) { 53 | if(!packsDir.isDirectory()) return; 54 | 55 | for(File file : Objects.requireNonNull(packsDir.listFiles())) 56 | if(file.isDirectory()) 57 | this.loadPack(file); 58 | } 59 | 60 | private void loadPack(File packFile) { 61 | final File manifestFile = new File(packFile, "manifest.json"); 62 | final File lootTablesDir = new File(packFile, "loot_tables"); 63 | if(manifestFile.exists() && lootTablesDir.exists()) 64 | for(File lootTableFile : Objects.requireNonNull(lootTablesDir.listFiles())) 65 | this.loadLootTable(lootTableFile, "loot_tables"); 66 | } 67 | 68 | private void loadLootTable(File lootTableFile, String currentPath) { 69 | if(lootTableFile.isDirectory()) { 70 | for(File nextLootTableFile : Objects.requireNonNull(lootTableFile.listFiles())) 71 | this.loadLootTable(nextLootTableFile, currentPath + "/" + lootTableFile.getName()); 72 | return; 73 | } 74 | 75 | final String lootTablePath = currentPath + "/" + lootTableFile.getName(); 76 | final String lootTableName = lootTableFile.getName().split("\\.")[0]; 77 | if(!lootTablePath.contains("chest")) return; 78 | 79 | try(final FileReader fileReader = new FileReader(lootTableFile); 80 | final BufferedReader bufferedReader = new BufferedReader(fileReader)) { 81 | this.lootTables.add(LootTableBuilder.build(lootTablePath, lootTableName, GSON.>fromJson(bufferedReader, Map.class))); 82 | } catch(IOException e) { 83 | e.printStackTrace(); 84 | } 85 | } 86 | 87 | } 88 | -------------------------------------------------------------------------------- /src/main/java/de/kcodeyt/vanilla/behavior/LootTableNumber.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 KCodeYT 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package de.kcodeyt.vanilla.behavior; 18 | 19 | import java.util.List; 20 | import java.util.Map; 21 | import java.util.Random; 22 | import java.util.concurrent.ThreadLocalRandom; 23 | 24 | /** 25 | * @author Kevims KCodeYT 26 | * @version 1.0-SNAPSHOT 27 | */ 28 | public class LootTableNumber { 29 | 30 | private final double min; 31 | private final double max; 32 | 33 | private LootTableNumber(double value) { 34 | this(value, value); 35 | } 36 | 37 | private LootTableNumber(double min, double max) { 38 | this.min = min; 39 | this.max = max; 40 | } 41 | 42 | public static LootTableNumber of(Object obj) { 43 | if(obj instanceof Double) return new LootTableNumber((double) obj); 44 | 45 | if(obj instanceof List) { 46 | final double min = (double) (Object) ((List) obj).get(0); 47 | final double max = (double) (Object) ((List) obj).get(1); 48 | return new LootTableNumber(min, max); 49 | } 50 | 51 | if(obj instanceof final Map map) { 52 | final double min = (double) (Object) nonNull(map.get("min")); 53 | final double max = (double) (Object) nonNull(map.get("max")); 54 | return new LootTableNumber(min, max); 55 | } 56 | 57 | throw new RuntimeException("Could not resolve number from object " + obj + "!"); 58 | } 59 | 60 | public static int random(Random random, int min, int max) { 61 | return random.nextInt(max - min + 1) + min; 62 | } 63 | 64 | @SuppressWarnings("unchecked") 65 | private static T nonNull(T value) { 66 | return value == null ? (T) (Object) 0.0 : value; 67 | } 68 | 69 | public int getAsInt() { 70 | return this.getAsInt(ThreadLocalRandom.current()); 71 | } 72 | 73 | public double getAsDouble() { 74 | return this.getAsDouble(ThreadLocalRandom.current()); 75 | } 76 | 77 | public int getAsInt(Random random) { 78 | if(this.min == this.max) return (int) this.min; 79 | return random(random, (int) this.min, (int) this.max); 80 | } 81 | 82 | public double getAsDouble(Random random) { 83 | return this.getAsDouble(random, false); 84 | } 85 | 86 | public double getAsDouble(Random random, boolean percent) { 87 | if(this.min == this.max) return this.min; 88 | 89 | if(percent) return random(random, (int) Math.floor(this.min * 100D), (int) Math.floor(this.max * 100D)) / 100D; 90 | else return random.nextDouble(this.max - this.min + 1) + this.min; 91 | } 92 | 93 | } 94 | -------------------------------------------------------------------------------- /src/main/java/de/kcodeyt/vanilla/behavior/Pool.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 KCodeYT 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package de.kcodeyt.vanilla.behavior; 18 | 19 | import java.util.List; 20 | 21 | /** 22 | * @author Kevims KCodeYT 23 | * @version 1.0-SNAPSHOT 24 | */ 25 | public record Pool(LootTableNumber rolls, 26 | List entries) { 27 | 28 | } 29 | -------------------------------------------------------------------------------- /src/main/java/de/kcodeyt/vanilla/behavior/PoolEntry.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 KCodeYT 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package de.kcodeyt.vanilla.behavior; 18 | 19 | import cn.nukkit.item.Item; 20 | import de.kcodeyt.vanilla.behavior.function.LootTableFunction; 21 | 22 | import java.util.List; 23 | 24 | /** 25 | * @author Kevims KCodeYT 26 | * @version 1.0-SNAPSHOT 27 | */ 28 | public record PoolEntry(String type, String name, int weight, 29 | List> functions) { 30 | 31 | } 32 | -------------------------------------------------------------------------------- /src/main/java/de/kcodeyt/vanilla/behavior/function/EnchantRandomlyFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 KCodeYT 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package de.kcodeyt.vanilla.behavior.function; 18 | 19 | import cn.nukkit.item.Item; 20 | import cn.nukkit.item.ItemID; 21 | import cn.nukkit.item.enchantment.Enchantment; 22 | import de.kcodeyt.vanilla.behavior.LootTableNumber; 23 | import de.kcodeyt.vanilla.enchantment.Enchantments; 24 | import de.kcodeyt.vanilla.enchantment.VanillaEnchantment; 25 | 26 | import java.util.Arrays; 27 | import java.util.List; 28 | import java.util.Map; 29 | import java.util.Random; 30 | 31 | /** 32 | * @author Kevims KCodeYT 33 | * @version 1.0-SNAPSHOT 34 | */ 35 | public class EnchantRandomlyFunction implements LootTableFunction { 36 | 37 | private final boolean treasure; 38 | 39 | public EnchantRandomlyFunction(Map arguments) { 40 | this.treasure = arguments.containsKey("treasure") && (boolean) arguments.get("treasure"); 41 | } 42 | 43 | @Override 44 | public Item invoke(Item item, Random random) { 45 | final List availableEnchantments = Arrays.stream(Enchantments.values()).filter(enchantments -> 46 | (item.getId() == ItemID.BOOK || enchantments.getEnchantment().getType().canEnchant(item)) && 47 | enchantments.getEnchantment().canGenerateInLoot() && 48 | (!enchantments.getEnchantment().isTreasureEnchantment() || this.treasure)).toList(); 49 | 50 | final Item result = item.getId() == ItemID.BOOK ? Item.get(Item.ENCHANT_BOOK) : item; 51 | final Enchantments enchantments = availableEnchantments.get(random.nextInt(availableEnchantments.size())); 52 | final VanillaEnchantment enchantment = enchantments.getEnchantment(); 53 | result.addEnchantment(Enchantment.getEnchantment(enchantments.getNumericId()). 54 | setLevel(LootTableNumber.random(random, enchantment.getMinLevel(), enchantment.getMaxLevel()))); 55 | 56 | return result; 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/de/kcodeyt/vanilla/behavior/function/EnchantWithLevelsFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 KCodeYT 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package de.kcodeyt.vanilla.behavior.function; 18 | 19 | import cn.nukkit.item.Item; 20 | import de.kcodeyt.vanilla.behavior.LootTableNumber; 21 | import de.kcodeyt.vanilla.enchantment.EnchantmentHelper; 22 | 23 | import java.util.Map; 24 | import java.util.Random; 25 | 26 | /** 27 | * @author Kevims KCodeYT 28 | * @version 1.0-SNAPSHOT 29 | */ 30 | public class EnchantWithLevelsFunction implements LootTableFunction { 31 | 32 | private final LootTableNumber levels; 33 | private final boolean treasure; 34 | 35 | public EnchantWithLevelsFunction(Map arguments) { 36 | this.levels = LootTableNumber.of(arguments.get("levels")); 37 | this.treasure = arguments.containsKey("treasure") && (boolean) arguments.get("treasure"); 38 | } 39 | 40 | @Override 41 | public Item invoke(Item item, Random random) { 42 | if(this.levels == null) return item; 43 | 44 | return EnchantmentHelper.addRandomEnchantment(random, item, this.levels.getAsInt(random), this.treasure); 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/de/kcodeyt/vanilla/behavior/function/FunctionRegistry.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 KCodeYT 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package de.kcodeyt.vanilla.behavior.function; 18 | 19 | import cn.nukkit.item.Item; 20 | import de.kcodeyt.vanilla.VanillaGeneratorPlugin; 21 | 22 | import java.lang.reflect.Constructor; 23 | import java.lang.reflect.InvocationTargetException; 24 | import java.util.HashMap; 25 | import java.util.Map; 26 | 27 | /** 28 | * @author Kevims KCodeYT 29 | * @version 1.0-SNAPSHOT 30 | */ 31 | public class FunctionRegistry { 32 | 33 | private static final Map>> FUNCTIONS = new HashMap<>(); 34 | 35 | static { 36 | FUNCTIONS.put("minecraft:enchant_randomly", EnchantRandomlyFunction.class); 37 | FUNCTIONS.put("minecraft:enchant_with_levels", EnchantWithLevelsFunction.class); 38 | FUNCTIONS.put("minecraft:random_aux_value", RandomAuxValueFunction.class); 39 | FUNCTIONS.put("minecraft:set_data", SetDataFunction.class); 40 | FUNCTIONS.put("minecraft:set_count", SetCountFunction.class); 41 | FUNCTIONS.put("minecraft:set_damage", SetDamageFunction.class); 42 | FUNCTIONS.put("minecraft:specific_enchants", SpecificEnchantsFunction.class); 43 | } 44 | 45 | public static LootTableFunction get(String name, Map args) { 46 | final String identifier = name.contains(":") ? name : "minecraft:" + name; 47 | 48 | for(Map.Entry>> entry : FUNCTIONS.entrySet()) { 49 | if(entry.getKey().equalsIgnoreCase(identifier)) { 50 | try { 51 | final Constructor> constructor = entry.getValue().getConstructor(Map.class); 52 | constructor.setAccessible(true); 53 | return constructor.newInstance(args); 54 | } catch(InstantiationException | NoSuchMethodException | IllegalAccessException | 55 | InvocationTargetException e) { 56 | VanillaGeneratorPlugin.getInstance().getLogger().error("Could not initialize function!", e); 57 | } 58 | } 59 | } 60 | 61 | return null; 62 | } 63 | 64 | } 65 | -------------------------------------------------------------------------------- /src/main/java/de/kcodeyt/vanilla/behavior/function/LootTableFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 KCodeYT 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package de.kcodeyt.vanilla.behavior.function; 18 | 19 | import java.util.Random; 20 | 21 | /** 22 | * @author Kevims KCodeYT 23 | * @version 1.0-SNAPSHOT 24 | */ 25 | public interface LootTableFunction { 26 | 27 | E invoke(E object, Random random); 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/de/kcodeyt/vanilla/behavior/function/RandomAuxValueFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 KCodeYT 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package de.kcodeyt.vanilla.behavior.function; 18 | 19 | import cn.nukkit.item.Item; 20 | import de.kcodeyt.vanilla.behavior.LootTableNumber; 21 | 22 | import java.util.Map; 23 | import java.util.Random; 24 | 25 | /** 26 | * @author Kevims KCodeYT 27 | * @version 1.0-SNAPSHOT 28 | */ 29 | public class RandomAuxValueFunction implements LootTableFunction { 30 | 31 | private final LootTableNumber values; 32 | 33 | public RandomAuxValueFunction(Map arguments) { 34 | this.values = LootTableNumber.of(arguments.get("values")); 35 | } 36 | 37 | @Override 38 | public Item invoke(Item item, Random random) { 39 | if(this.values == null) return item; 40 | 41 | item.setDamage(this.values.getAsInt(random)); 42 | return item; 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/de/kcodeyt/vanilla/behavior/function/SetCountFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 KCodeYT 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package de.kcodeyt.vanilla.behavior.function; 18 | 19 | import cn.nukkit.item.Item; 20 | import de.kcodeyt.vanilla.behavior.LootTableNumber; 21 | 22 | import java.util.Map; 23 | import java.util.Random; 24 | 25 | /** 26 | * @author Kevims KCodeYT 27 | * @version 1.0-SNAPSHOT 28 | */ 29 | public class SetCountFunction implements LootTableFunction { 30 | 31 | private final LootTableNumber count; 32 | 33 | public SetCountFunction(Map arguments) { 34 | this.count = LootTableNumber.of(arguments.get("count")); 35 | } 36 | 37 | @Override 38 | public Item invoke(Item item, Random random) { 39 | if(this.count == null) return item; 40 | 41 | item.setCount(this.count.getAsInt(random)); 42 | return item; 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/de/kcodeyt/vanilla/behavior/function/SetDamageFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 KCodeYT 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package de.kcodeyt.vanilla.behavior.function; 18 | 19 | import cn.nukkit.item.Item; 20 | import de.kcodeyt.vanilla.behavior.LootTableNumber; 21 | 22 | import java.util.Map; 23 | import java.util.Random; 24 | 25 | /** 26 | * @author Kevims KCodeYT 27 | * @version 1.0-SNAPSHOT 28 | */ 29 | public class SetDamageFunction implements LootTableFunction { 30 | 31 | private final LootTableNumber damage; 32 | 33 | public SetDamageFunction(Map arguments) { 34 | this.damage = LootTableNumber.of(arguments.get("damage")); 35 | } 36 | 37 | @Override 38 | public Item invoke(Item item, Random random) { 39 | if(this.damage == null) return item; 40 | 41 | item.setDamage((int) (item.getMaxDurability() * (1 - this.damage.getAsDouble(random, true)))); 42 | return item; 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/de/kcodeyt/vanilla/behavior/function/SetDataFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 KCodeYT 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package de.kcodeyt.vanilla.behavior.function; 18 | 19 | import cn.nukkit.item.Item; 20 | import de.kcodeyt.vanilla.behavior.LootTableNumber; 21 | 22 | import java.util.Map; 23 | import java.util.Random; 24 | 25 | /** 26 | * @author Kevims KCodeYT 27 | * @version 1.0-SNAPSHOT 28 | */ 29 | public class SetDataFunction implements LootTableFunction { 30 | 31 | private final LootTableNumber data; 32 | 33 | public SetDataFunction(Map arguments) { 34 | this.data = LootTableNumber.of(arguments.get("data")); 35 | } 36 | 37 | @Override 38 | public Item invoke(Item item, Random random) { 39 | if(this.data == null) return item; 40 | 41 | item.setDamage(this.data.getAsInt(random)); 42 | return item; 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/de/kcodeyt/vanilla/behavior/function/SpecificEnchantsFunction.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 KCodeYT 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package de.kcodeyt.vanilla.behavior.function; 18 | 19 | import cn.nukkit.item.Item; 20 | import cn.nukkit.item.enchantment.Enchantment; 21 | import de.kcodeyt.vanilla.behavior.LootTableNumber; 22 | import de.kcodeyt.vanilla.enchantment.Enchantments; 23 | 24 | import java.util.ArrayList; 25 | import java.util.List; 26 | import java.util.Map; 27 | import java.util.Random; 28 | 29 | /** 30 | * @author Kevims KCodeYT 31 | * @version 1.0-SNAPSHOT 32 | */ 33 | public class SpecificEnchantsFunction implements LootTableFunction { 34 | 35 | private final List enchantments; 36 | 37 | public SpecificEnchantsFunction(Map arguments) { 38 | this.enchantments = new ArrayList<>(); 39 | for(Object enchant : ((List) arguments.get("enchants"))) { 40 | if(enchant instanceof final Map map) { 41 | final String enchantmentId = (String) map.get("id"); 42 | final LootTableNumber level = LootTableNumber.of(map.get("level")); 43 | 44 | final Integer id = Enchantments.getEnchantmentNumericId(enchantmentId); 45 | if(id == null) continue; 46 | 47 | this.enchantments.add(new EnchantmentEntry(id, level)); 48 | } 49 | } 50 | } 51 | 52 | @Override 53 | public Item invoke(Item item, Random random) { 54 | if(this.enchantments.isEmpty()) return item; 55 | 56 | for(EnchantmentEntry entry : this.enchantments) 57 | item.addEnchantment(Enchantment. 58 | getEnchantment(entry.numericId()). 59 | setLevel(entry.level().getAsInt(random)) 60 | ); 61 | 62 | return item; 63 | } 64 | 65 | private record EnchantmentEntry(int numericId, LootTableNumber level) { 66 | 67 | } 68 | 69 | } 70 | -------------------------------------------------------------------------------- /src/main/java/de/kcodeyt/vanilla/command/SudoCommand.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 KCodeYT 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package de.kcodeyt.vanilla.command; 18 | 19 | import cn.nukkit.Player; 20 | import cn.nukkit.Server; 21 | import cn.nukkit.command.Command; 22 | import cn.nukkit.command.CommandSender; 23 | import cn.nukkit.command.data.CommandParamType; 24 | import cn.nukkit.command.data.CommandParameter; 25 | import cn.nukkit.level.Level; 26 | import cn.nukkit.network.protocol.TextPacket; 27 | import com.nukkitx.protocol.bedrock.data.command.CommandOutputMessage; 28 | import de.kcodeyt.vanilla.VanillaGeneratorPlugin; 29 | import de.kcodeyt.vanilla.generator.Vanilla; 30 | 31 | import java.util.Arrays; 32 | 33 | /** 34 | * @author Kevims KCodeYT 35 | * @version 1.0-SNAPSHOT 36 | */ 37 | public class SudoCommand extends Command { 38 | 39 | public SudoCommand() { 40 | super("sudo", "Executes a command on a background server"); 41 | this.setPermission("vanilla.command.sudo"); 42 | this.commandParameters.clear(); 43 | this.commandParameters.put("SudoArgs", new CommandParameter[]{ 44 | CommandParameter.newType("server", false, CommandParamType.STRING), 45 | CommandParameter.newType("command", false, CommandParamType.TEXT) 46 | }); 47 | } 48 | 49 | @Override 50 | public boolean execute(CommandSender sender, String commandLabel, String[] args) { 51 | final String server = args.length > 0 ? args[0] : null; 52 | final String command = args.length > 1 ? String.join(" ", Arrays.copyOfRange(args, 1, args.length)) : null; 53 | 54 | if(server == null) { 55 | sender.sendMessage("§cPlease specify a world name!"); 56 | return false; 57 | } 58 | 59 | if(command == null) { 60 | sender.sendMessage("§cPlease specify a command!"); 61 | return false; 62 | } 63 | 64 | final Level level = Server.getInstance().getLevelByName(server); 65 | if(level == null || !(level.getGenerator() instanceof Vanilla)) { 66 | sender.sendMessage("§cThe world does not exists or does now has a background server!"); 67 | return false; 68 | } 69 | 70 | VanillaGeneratorPlugin.getVanillaServer(level).whenComplete((vanillaServer, throwable) -> { 71 | if(vanillaServer == null) { 72 | sender.sendMessage("§cCould not find the background server for " + level.getFolderName() + "!"); 73 | return; 74 | } 75 | 76 | vanillaServer.getClient().sendCommand(command, commandOutputPacket -> { 77 | sender.sendMessage("§aGot command response:"); 78 | 79 | for(CommandOutputMessage message : commandOutputPacket.getMessages()) { 80 | if(sender instanceof Player) { 81 | final TextPacket textPacket = new TextPacket(); 82 | textPacket.type = TextPacket.TYPE_TRANSLATION; 83 | textPacket.message = message.getMessageId(); 84 | textPacket.parameters = message.getParameters(); 85 | 86 | ((Player) sender).dataPacket(textPacket); 87 | } else { 88 | sender.sendMessage(message.getMessageId() + " [" + Arrays.toString(message.getParameters()) + "]"); 89 | } 90 | } 91 | }); 92 | }); 93 | return true; 94 | } 95 | 96 | } 97 | -------------------------------------------------------------------------------- /src/main/java/de/kcodeyt/vanilla/command/WorldCommand.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 KCodeYT 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package de.kcodeyt.vanilla.command; 18 | 19 | import cn.nukkit.Player; 20 | import cn.nukkit.command.Command; 21 | import cn.nukkit.command.CommandSender; 22 | import cn.nukkit.command.data.CommandParamType; 23 | import cn.nukkit.command.data.CommandParameter; 24 | import cn.nukkit.level.Level; 25 | import cn.nukkit.utils.TextFormat; 26 | 27 | /** 28 | * @author Kevims KCodeYT 29 | * @version 1.0-SNAPSHOT 30 | */ 31 | public class WorldCommand extends Command { 32 | 33 | public WorldCommand() { 34 | super("world", "Teleports to a specific world"); 35 | this.setPermission("vanilla.command.world"); 36 | this.commandParameters.clear(); 37 | this.commandParameters.put("World", new CommandParameter[]{ 38 | CommandParameter.newType("world", false, CommandParamType.STRING) 39 | }); 40 | this.commandParameters.put("Player2World", new CommandParameter[]{ 41 | CommandParameter.newType("player", false, CommandParamType.TARGET), 42 | CommandParameter.newType("world", false, CommandParamType.STRING) 43 | }); 44 | } 45 | 46 | @Override 47 | public boolean execute(CommandSender sender, String commandLabel, String[] args) { 48 | if(!this.testPermission(sender)) 49 | return false; 50 | if(args.length == 0) { 51 | sender.sendMessage("§7Usage§8: §7/world "); 52 | sender.sendMessage("§7Usage§8: §7/world "); 53 | return false; 54 | } 55 | 56 | final String playerName = TextFormat.clean(args.length < 2 ? sender.getName() : args[0]); 57 | final String levelName = args.length < 2 ? args[0] : args[1]; 58 | 59 | final Level level = sender.getServer().getLevelByName(levelName); 60 | if(level == null) { 61 | sender.sendMessage("§cThe specific level \"" + levelName + "§r§c\" does not exists!"); 62 | return false; 63 | } 64 | 65 | if(args.length == 1 && !(sender instanceof Player)) { 66 | sender.sendMessage("§cThis command can only be used by players!"); 67 | sender.sendMessage("§7Usage§8: §7/world "); 68 | return false; 69 | } 70 | 71 | final Player player = args.length < 2 ? (Player) sender : sender.getServer().getPlayer(playerName); 72 | if(player == null) { 73 | sender.sendMessage("§cCan't find player " + playerName + "§r§c!"); 74 | return false; 75 | } 76 | 77 | player.teleport(level.getSafeSpawn()); 78 | sender.sendMessage("§aSuccessfully teleported §6" + player.getName() + "§r§a to §6" + levelName + "§r§a!"); 79 | return true; 80 | } 81 | 82 | } 83 | -------------------------------------------------------------------------------- /src/main/java/de/kcodeyt/vanilla/enchantment/EnchantmentHelper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 KCodeYT 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package de.kcodeyt.vanilla.enchantment; 18 | 19 | import cn.nukkit.item.Item; 20 | import cn.nukkit.item.ItemID; 21 | import cn.nukkit.item.enchantment.Enchantment; 22 | import cn.nukkit.math.MathHelper; 23 | import de.kcodeyt.vanilla.util.WeightedRandom; 24 | 25 | import java.util.ArrayList; 26 | import java.util.List; 27 | import java.util.Random; 28 | 29 | /** 30 | * @author Kevims KCodeYT 31 | * @version 1.0-SNAPSHOT 32 | */ 33 | public class EnchantmentHelper { 34 | 35 | public static Item addRandomEnchantment(Random random, Item nonFinalItem, int level, boolean allowTreasure) { 36 | final List enchantments = buildEnchantmentList(random, nonFinalItem, level, allowTreasure); 37 | final Item item = nonFinalItem.getId() == ItemID.BOOK ? Item.get(Item.ENCHANT_BOOK) : nonFinalItem; 38 | enchantments.forEach(enchantment -> item.addEnchantment( 39 | Enchantment.getEnchantment(enchantment.getEnchantments().getNumericId()). 40 | setLevel(enchantment.getLevel(), false))); 41 | return item; 42 | } 43 | 44 | private static List buildEnchantmentList(Random randomIn, Item item, int level, boolean allowTreasure) { 45 | final List holders = new ArrayList<>(); 46 | final int itemEnchantability = ItemEnchantment.getEnchantment(item).getEnchantability(); 47 | if(itemEnchantability <= 0) 48 | return holders; 49 | level = level + 1 + randomIn.nextInt(itemEnchantability / 4 + 1) + randomIn.nextInt(itemEnchantability / 4 + 1); 50 | final float randomFloat = (randomIn.nextFloat() + randomIn.nextFloat() - 1.0F) * 0.15F; 51 | level = MathHelper.clamp(Math.round((float) level + (float) level * randomFloat), 1, Integer.MAX_VALUE); 52 | final List availableHolders = getEnchantments(level, item, allowTreasure); 53 | if(!availableHolders.isEmpty()) { 54 | holders.add(WeightedRandom.getRandomItem(randomIn, availableHolders)); 55 | while(randomIn.nextInt(50) <= level) { 56 | final VanillaEnchantment lastEntry = (holders.get(holders.size() - 1)).getEnchantment(); 57 | availableHolders.removeIf(enchantment1 -> !lastEntry.isCompatible(enchantment1.getEnchantment())); 58 | if(availableHolders.isEmpty()) 59 | break; 60 | holders.add(WeightedRandom.getRandomItem(randomIn, availableHolders)); 61 | level /= 2; 62 | } 63 | } 64 | 65 | return holders; 66 | } 67 | 68 | private static List getEnchantments(int level, Item item, boolean allowTreasure) { 69 | final List list = new ArrayList<>(); 70 | final boolean isBook = item.getId() == ItemID.BOOK; 71 | 72 | for(Enchantments enchantments : Enchantments.values()) { 73 | final VanillaEnchantment enchantment = enchantments.getEnchantment(); 74 | if((!enchantment.isTreasureEnchantment() || allowTreasure) && enchantment.canGenerateInLoot() && (enchantment.getType().canEnchant(item) || isBook)) { 75 | for(int i = enchantment.getMaxLevel(); i > enchantment.getMinLevel() - 1; --i) { 76 | if(level >= enchantment.getMinEnchantability(i) && level <= enchantment.getMaxEnchantability(i)) { 77 | list.add(new EnchantmentHolder(enchantment, enchantments, i)); 78 | break; 79 | } 80 | } 81 | } 82 | } 83 | 84 | return list; 85 | } 86 | 87 | } 88 | -------------------------------------------------------------------------------- /src/main/java/de/kcodeyt/vanilla/enchantment/EnchantmentHolder.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 KCodeYT 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package de.kcodeyt.vanilla.enchantment; 18 | 19 | import de.kcodeyt.vanilla.util.WeightedRandom; 20 | import lombok.EqualsAndHashCode; 21 | import lombok.Value; 22 | 23 | /** 24 | * @author Kevims KCodeYT 25 | * @version 1.0-SNAPSHOT 26 | */ 27 | @Value 28 | @EqualsAndHashCode(callSuper = true) 29 | public class EnchantmentHolder extends WeightedRandom.Item { 30 | 31 | VanillaEnchantment enchantment; 32 | Enchantments enchantments; 33 | int level; 34 | 35 | EnchantmentHolder(VanillaEnchantment enchantment, Enchantments enchantments, int level) { 36 | super(enchantment.getRarity().getWeight()); 37 | this.enchantment = enchantment; 38 | this.enchantments = enchantments; 39 | this.level = level; 40 | } 41 | 42 | } 43 | -------------------------------------------------------------------------------- /src/main/java/de/kcodeyt/vanilla/enchantment/EnchantmentRarity.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 KCodeYT 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package de.kcodeyt.vanilla.enchantment; 18 | 19 | import lombok.AllArgsConstructor; 20 | import lombok.Getter; 21 | 22 | /** 23 | * @author Kevims KCodeYT 24 | * @version 1.0-SNAPSHOT 25 | */ 26 | @Getter 27 | @AllArgsConstructor 28 | public enum EnchantmentRarity { 29 | 30 | COMMON(10), 31 | UNCOMMON(5), 32 | RARE(2), 33 | VERY_RARE(1); 34 | 35 | private final int weight; 36 | 37 | } 38 | -------------------------------------------------------------------------------- /src/main/java/de/kcodeyt/vanilla/enchantment/EnchantmentType.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 KCodeYT 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package de.kcodeyt.vanilla.enchantment; 18 | 19 | import cn.nukkit.item.*; 20 | 21 | /** 22 | * @author Kevims KCodeYT 23 | * @version 1.0-SNAPSHOT 24 | */ 25 | public enum EnchantmentType { 26 | 27 | ARMOR { 28 | @Override 29 | public boolean canEnchant(Item item) { 30 | return item.isArmor(); 31 | } 32 | }, 33 | ARMOR_HELMET { 34 | @Override 35 | public boolean canEnchant(Item item) { 36 | return item.isHelmet(); 37 | } 38 | }, 39 | ARMOR_CHEST { 40 | @Override 41 | public boolean canEnchant(Item item) { 42 | return item.isChestplate(); 43 | } 44 | }, 45 | ARMOR_LEGGINGS { 46 | @Override 47 | public boolean canEnchant(Item item) { 48 | return item.isLeggings(); 49 | } 50 | }, 51 | ARMOR_BOOTS { 52 | @Override 53 | public boolean canEnchant(Item item) { 54 | return item.isBoots(); 55 | } 56 | }, 57 | WEAPON { 58 | @Override 59 | public boolean canEnchant(Item item) { 60 | return item.isSword(); 61 | } 62 | }, 63 | TOOL { 64 | @Override 65 | public boolean canEnchant(Item item) { 66 | return item.isPickaxe() || item.isAxe() || item.isShovel() || item.isHoe() || item.isShears(); 67 | } 68 | }, 69 | BREAKABLE { 70 | @Override 71 | public boolean canEnchant(Item item) { 72 | return item instanceof ItemDurable; 73 | } 74 | }, 75 | WEARABLE { 76 | @Override 77 | public boolean canEnchant(Item item) { 78 | return item.isArmor(); 79 | } 80 | }, 81 | FISHING_ROD { 82 | @Override 83 | public boolean canEnchant(Item item) { 84 | return item instanceof ItemFishingRod; 85 | } 86 | }, 87 | TRIDENT { 88 | @Override 89 | public boolean canEnchant(Item item) { 90 | return item instanceof ItemTrident; 91 | } 92 | }, 93 | BOW { 94 | @Override 95 | public boolean canEnchant(Item item) { 96 | return item instanceof ItemBow; 97 | } 98 | }, 99 | CROSSBOW { 100 | @Override 101 | public boolean canEnchant(Item item) { 102 | return item.getId() == ItemID.CROSSBOW; 103 | } 104 | }, 105 | VANISH { 106 | @Override 107 | public boolean canEnchant(Item item) { 108 | return true; 109 | } 110 | }; 111 | 112 | public abstract boolean canEnchant(Item item); 113 | 114 | } 115 | -------------------------------------------------------------------------------- /src/main/java/de/kcodeyt/vanilla/enchantment/Enchantments.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 KCodeYT 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package de.kcodeyt.vanilla.enchantment; 18 | 19 | import cn.nukkit.item.enchantment.Enchantment; 20 | import de.kcodeyt.vanilla.enchantment.defaults.*; 21 | import lombok.AllArgsConstructor; 22 | import lombok.Getter; 23 | 24 | /** 25 | * @author Kevims KCodeYT 26 | * @version 1.0-SNAPSHOT 27 | */ 28 | @Getter 29 | @AllArgsConstructor 30 | @SuppressWarnings("SpellCheckingInspection") 31 | public enum Enchantments { 32 | 33 | PROTECTION(Enchantment.NAME_PROTECTION_ALL, Enchantment.ID_PROTECTION_ALL, new ProtectionEnchantment(EnchantmentRarity.COMMON, ProtectionEnchantment.Type.ALL)), 34 | FIRE_PROTECTION(Enchantment.NAME_PROTECTION_FIRE, Enchantment.ID_PROTECTION_FIRE, new ProtectionEnchantment(EnchantmentRarity.UNCOMMON, ProtectionEnchantment.Type.FIRE)), 35 | FEATHER_FALLING(Enchantment.NAME_PROTECTION_FALL, Enchantment.ID_PROTECTION_FALL, new ProtectionEnchantment(EnchantmentRarity.UNCOMMON, ProtectionEnchantment.Type.FALL)), 36 | BLAST_PROTECTION(Enchantment.NAME_PROTECTION_EXPLOSION, Enchantment.ID_PROTECTION_EXPLOSION, new ProtectionEnchantment(EnchantmentRarity.RARE, ProtectionEnchantment.Type.EXPLOSION)), 37 | PROJECTILE_PROTECTION(Enchantment.NAME_PROTECTION_PROJECTILE, Enchantment.ID_PROTECTION_PROJECTILE, new ProtectionEnchantment(EnchantmentRarity.UNCOMMON, ProtectionEnchantment.Type.PROJECTILE)), 38 | THORNS(Enchantment.NAME_THORNS, Enchantment.ID_THORNS, new ThornsEnchantment(EnchantmentRarity.VERY_RARE)), 39 | RESPIRATION(Enchantment.NAME_WATER_BREATHING, Enchantment.ID_WATER_BREATHING, new RespirationEnchantment(EnchantmentRarity.RARE)), 40 | DEPTH_STRIDER(Enchantment.NAME_WATER_WALKER, Enchantment.ID_WATER_WALKER, new DepthStriderEnchantment(EnchantmentRarity.RARE)), 41 | AQUA_AFFINITY(Enchantment.NAME_WATER_WORKER, Enchantment.ID_WATER_WORKER, new AquaAffinityEnchantment(EnchantmentRarity.RARE)), 42 | SHARPNESS(Enchantment.NAME_DAMAGE_ALL, Enchantment.ID_DAMAGE_ALL, new DamageEnchantment(EnchantmentRarity.COMMON, DamageEnchantment.Type.ALL)), 43 | SMITE(Enchantment.NAME_DAMAGE_SMITE, Enchantment.ID_DAMAGE_SMITE, new DamageEnchantment(EnchantmentRarity.UNCOMMON, DamageEnchantment.Type.UNDEAD)), 44 | BANE_OF_ARTHROPODS(Enchantment.NAME_DAMAGE_ARTHROPODS, Enchantment.ID_DAMAGE_ARTHROPODS, new DamageEnchantment(EnchantmentRarity.UNCOMMON, DamageEnchantment.Type.ARTHROPODS)), 45 | KNOCKBACK(Enchantment.NAME_KNOCKBACK, Enchantment.ID_KNOCKBACK, new KnockbackEnchantment(EnchantmentRarity.UNCOMMON)), 46 | FIRE_ASPECT(Enchantment.NAME_FIRE_ASPECT, Enchantment.ID_FIRE_ASPECT, new FireAspectEnchantment(EnchantmentRarity.RARE)), 47 | LOOTING(Enchantment.NAME_LOOTING, Enchantment.ID_LOOTING, new LootBonusEnchantment(EnchantmentRarity.RARE, EnchantmentType.WEAPON)), 48 | EFFICIENCY(Enchantment.NAME_EFFICIENCY, Enchantment.ID_EFFICIENCY, new EfficiencyEnchantment(EnchantmentRarity.COMMON)), 49 | SILK_TOUCH(Enchantment.NAME_SILK_TOUCH, Enchantment.ID_SILK_TOUCH, new SilkTouchEnchantment(EnchantmentRarity.VERY_RARE)), 50 | UNBREAKING(Enchantment.NAME_DURABILITY, Enchantment.ID_DURABILITY, new UnbreakingEnchantment(EnchantmentRarity.UNCOMMON)), 51 | FORTUNE(Enchantment.NAME_FORTUNE_DIGGING, Enchantment.ID_FORTUNE_DIGGING, new LootBonusEnchantment(EnchantmentRarity.RARE, EnchantmentType.TOOL)), 52 | POWER(Enchantment.NAME_BOW_POWER, Enchantment.ID_BOW_POWER, new PowerEnchantment(EnchantmentRarity.COMMON)), 53 | PUNCH(Enchantment.NAME_BOW_KNOCKBACK, Enchantment.ID_BOW_KNOCKBACK, new PunchEnchantment(EnchantmentRarity.RARE)), 54 | FLAME(Enchantment.NAME_BOW_FLAME, Enchantment.ID_BOW_FLAME, new FlameEnchantment(EnchantmentRarity.RARE)), 55 | INFINITY(Enchantment.NAME_BOW_INFINITY, Enchantment.ID_BOW_INFINITY, new InfinityEnchantment(EnchantmentRarity.VERY_RARE)), 56 | LUCK_OF_THE_SEA(Enchantment.NAME_FORTUNE_FISHING, Enchantment.ID_FORTUNE_FISHING, new LootBonusEnchantment(EnchantmentRarity.RARE, EnchantmentType.FISHING_ROD)), 57 | LURE(Enchantment.NAME_LURE, Enchantment.ID_LURE, new LureEnchantment(EnchantmentRarity.RARE)), 58 | FROST_WALKER(Enchantment.NAME_FROST_WALKER, Enchantment.ID_FROST_WALKER, new FrostWalkerEnchantment(EnchantmentRarity.RARE)), 59 | MENDING(Enchantment.NAME_MENDING, Enchantment.ID_MENDING, new MendingEnchantment(EnchantmentRarity.RARE)), 60 | BINDING(Enchantment.NAME_BINDING_CURSE, Enchantment.ID_BINDING_CURSE, new BindingCurseEnchantment(EnchantmentRarity.VERY_RARE)), 61 | VANISHING(Enchantment.NAME_VANISHING_CURSE, Enchantment.ID_VANISHING_CURSE, new VanishingCurseEnchantment(EnchantmentRarity.VERY_RARE)), 62 | IMPALING(Enchantment.NAME_TRIDENT_IMPALING, Enchantment.ID_TRIDENT_IMPALING, new ImpalingEnchantment(EnchantmentRarity.RARE)), 63 | RIPTIDE(Enchantment.NAME_TRIDENT_RIPTIDE, Enchantment.ID_TRIDENT_RIPTIDE, new RiptideEnchantment(EnchantmentRarity.RARE)), 64 | LOYALTY(Enchantment.NAME_TRIDENT_LOYALTY, Enchantment.ID_TRIDENT_LOYALTY, new LoyaltyEnchantment(EnchantmentRarity.RARE)), 65 | CHANNELING(Enchantment.NAME_TRIDENT_CHANNELING, Enchantment.ID_TRIDENT_CHANNELING, new ChannelingEnchantment(EnchantmentRarity.VERY_RARE)), 66 | MULTISHOT(Enchantment.NAME_CROSSBOW_MULTISHOT, Enchantment.ID_CROSSBOW_MULTISHOT, new MultishotEnchantment(EnchantmentRarity.RARE)), 67 | PIERCING(Enchantment.NAME_CROSSBOW_PIERCING, Enchantment.ID_CROSSBOW_PIERCING, new PiercingEnchantment(EnchantmentRarity.COMMON)), 68 | QUICK_CHARGE(Enchantment.NAME_CROSSBOW_QUICK_CHARGE, Enchantment.ID_CROSSBOW_QUICK_CHARGE, new QuickChargeEnchantment(EnchantmentRarity.UNCOMMON)), 69 | SOUL_SPEED(Enchantment.NAME_SOUL_SPEED, Enchantment.ID_SOUL_SPEED, new SoulSpeedEnchantment(EnchantmentRarity.VERY_RARE)), 70 | SWITFT_SNEAK(Enchantment.NAME_SWIFT_SNEAK, Enchantment.ID_SWIFT_SNEAK, new SwiftSneakEnchantment(EnchantmentRarity.VERY_RARE)); 71 | 72 | private final String identifier; 73 | private final int numericId; 74 | private final VanillaEnchantment enchantment; 75 | 76 | public static Integer getEnchantmentNumericId(String identifier) { 77 | final int indexOfSplitter = identifier.indexOf(':'); 78 | final String namespaced = indexOfSplitter != -1 ? identifier.substring(indexOfSplitter + 1) : identifier; 79 | 80 | for(Enchantments value : values()) { 81 | if(value.getIdentifier().equals(namespaced)) 82 | return value.getNumericId(); 83 | } 84 | 85 | return null; 86 | } 87 | 88 | } 89 | -------------------------------------------------------------------------------- /src/main/java/de/kcodeyt/vanilla/enchantment/ItemEnchantment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 KCodeYT 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package de.kcodeyt.vanilla.enchantment; 18 | 19 | import cn.nukkit.item.Item; 20 | import cn.nukkit.item.ItemArmor; 21 | import cn.nukkit.item.ItemID; 22 | import cn.nukkit.item.ItemTool; 23 | import lombok.AllArgsConstructor; 24 | import lombok.Getter; 25 | 26 | import java.util.Arrays; 27 | 28 | /** 29 | * @author Kevims KCodeYT 30 | * @version 1.0-SNAPSHOT 31 | */ 32 | @Getter 33 | @AllArgsConstructor 34 | public enum ItemEnchantment { 35 | 36 | DEFAULT(0) { 37 | @Override 38 | public boolean isItem(Item item) { 39 | return false; 40 | } 41 | }, 42 | LEATHER_ARMOR(15) { 43 | @Override 44 | public boolean isItem(Item item) { 45 | return item.isArmor() && item.getTier() == ItemArmor.TIER_LEATHER; 46 | } 47 | }, 48 | CHAIN_ARMOR(12) { 49 | @Override 50 | public boolean isItem(Item item) { 51 | return item.isArmor() && item.getTier() == ItemArmor.TIER_CHAIN; 52 | } 53 | }, 54 | IRON_ARMOR(9) { 55 | @Override 56 | public boolean isItem(Item item) { 57 | return item.isArmor() && item.getTier() == ItemArmor.TIER_IRON; 58 | } 59 | }, 60 | GOLD_ARMOR(25) { 61 | @Override 62 | public boolean isItem(Item item) { 63 | return item.isArmor() && item.getTier() == ItemArmor.TIER_GOLD; 64 | } 65 | }, 66 | DIAMOND_ARMOR(10) { 67 | @Override 68 | public boolean isItem(Item item) { 69 | return item.isArmor() && item.getTier() == ItemArmor.TIER_DIAMOND; 70 | } 71 | }, 72 | TURTLE_ARMOR(9) { 73 | @Override 74 | public boolean isItem(Item item) { 75 | return item.isArmor() && item.getTier() == ItemArmor.TIER_OTHER; 76 | } 77 | }, 78 | NETHERITE(15) { 79 | @Override 80 | public boolean isItem(Item item) { 81 | return (item.isArmor() && item.getTier() == ItemArmor.TIER_NETHERITE) || (item.isTool() && item.getTier() == ItemTool.TIER_NETHERITE); 82 | } 83 | }, 84 | BOOK(1) { 85 | @Override 86 | public boolean isItem(Item item) { 87 | return item.getId() == ItemID.BOOK; 88 | } 89 | }, 90 | FISHING_ROD(1) { 91 | @Override 92 | public boolean isItem(Item item) { 93 | return item.getId() == ItemID.FISHING_ROD; 94 | } 95 | }, 96 | BOW(1) { 97 | @Override 98 | public boolean isItem(Item item) { 99 | return item.getId() == ItemID.BOW || item.getId() == ItemID.CROSSBOW; 100 | } 101 | }, 102 | WOOD_TIER(15) { 103 | @Override 104 | public boolean isItem(Item item) { 105 | return item.isTool() && item.getTier() == ItemTool.TIER_WOODEN; 106 | } 107 | }, 108 | STONE_TIER(5) { 109 | @Override 110 | public boolean isItem(Item item) { 111 | return item.isTool() && item.getTier() == ItemTool.TIER_STONE; 112 | } 113 | }, 114 | IRON_TIER(14) { 115 | @Override 116 | public boolean isItem(Item item) { 117 | return item.isTool() && item.getTier() == ItemTool.TIER_IRON; 118 | } 119 | }, 120 | GOLD_TIER(22) { 121 | @Override 122 | public boolean isItem(Item item) { 123 | return item.isTool() && item.getTier() == ItemTool.TIER_GOLD; 124 | } 125 | }, 126 | DIAMOND_TIER(10) { 127 | @Override 128 | public boolean isItem(Item item) { 129 | return item.isTool() && item.getTier() == ItemTool.TIER_DIAMOND; 130 | } 131 | }, 132 | TRIDENT(1) { 133 | @Override 134 | public boolean isItem(Item item) { 135 | return item.getId() == ItemID.TRIDENT; 136 | } 137 | }; 138 | 139 | private final int enchantability; 140 | 141 | public static ItemEnchantment getEnchantment(Item item) { 142 | return Arrays.stream(values()).filter(enchantment -> enchantment.isItem(item)).findAny().orElse(DEFAULT); 143 | } 144 | 145 | public abstract boolean isItem(Item item); 146 | 147 | } 148 | -------------------------------------------------------------------------------- /src/main/java/de/kcodeyt/vanilla/enchantment/VanillaEnchantment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 KCodeYT 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package de.kcodeyt.vanilla.enchantment; 18 | 19 | import lombok.AllArgsConstructor; 20 | import lombok.Getter; 21 | 22 | /** 23 | * @author Kevims KCodeYT 24 | * @version 1.0-SNAPSHOT 25 | */ 26 | @Getter 27 | @AllArgsConstructor 28 | public abstract class VanillaEnchantment { 29 | 30 | private final EnchantmentRarity rarity; 31 | private final EnchantmentType type; 32 | 33 | public int getMinLevel() { 34 | return 1; 35 | } 36 | 37 | public int getMaxLevel() { 38 | return 1; 39 | } 40 | 41 | public int getMinEnchantability(int level) { 42 | return level * 10 + 1; 43 | } 44 | 45 | public int getMaxEnchantability(int level) { 46 | return this.getMinEnchantability(level) + 5; 47 | } 48 | 49 | public boolean canApplyTogether(VanillaEnchantment enchantment) { 50 | return !this.equals(enchantment); 51 | } 52 | 53 | public boolean isCompatible(VanillaEnchantment enchantment) { 54 | return this.canApplyTogether(enchantment) && enchantment.canApplyTogether(this); 55 | } 56 | 57 | public boolean canGenerateInLoot() { 58 | return true; 59 | } 60 | 61 | public boolean isTreasureEnchantment() { 62 | return false; 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/de/kcodeyt/vanilla/enchantment/defaults/AquaAffinityEnchantment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 KCodeYT 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package de.kcodeyt.vanilla.enchantment.defaults; 18 | 19 | import de.kcodeyt.vanilla.enchantment.EnchantmentRarity; 20 | import de.kcodeyt.vanilla.enchantment.EnchantmentType; 21 | import de.kcodeyt.vanilla.enchantment.VanillaEnchantment; 22 | 23 | /** 24 | * @author Kevims KCodeYT 25 | * @version 1.0-SNAPSHOT 26 | */ 27 | public class AquaAffinityEnchantment extends VanillaEnchantment { 28 | 29 | public AquaAffinityEnchantment(EnchantmentRarity rarity) { 30 | super(rarity, EnchantmentType.ARMOR_HELMET); 31 | } 32 | 33 | @Override 34 | public int getMinEnchantability(int level) { 35 | return 1; 36 | } 37 | 38 | @Override 39 | public int getMaxEnchantability(int level) { 40 | return this.getMinEnchantability(level) + 40; 41 | } 42 | 43 | @Override 44 | public int getMaxLevel() { 45 | return 1; 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/de/kcodeyt/vanilla/enchantment/defaults/BindingCurseEnchantment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 KCodeYT 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package de.kcodeyt.vanilla.enchantment.defaults; 18 | 19 | import de.kcodeyt.vanilla.enchantment.EnchantmentRarity; 20 | import de.kcodeyt.vanilla.enchantment.EnchantmentType; 21 | import de.kcodeyt.vanilla.enchantment.VanillaEnchantment; 22 | 23 | /** 24 | * @author Kevims KCodeYT 25 | * @version 1.0-SNAPSHOT 26 | */ 27 | public class BindingCurseEnchantment extends VanillaEnchantment { 28 | 29 | public BindingCurseEnchantment(EnchantmentRarity rarity) { 30 | super(rarity, EnchantmentType.WEARABLE); 31 | } 32 | 33 | @Override 34 | public int getMinEnchantability(int level) { 35 | return 25; 36 | } 37 | 38 | @Override 39 | public int getMaxEnchantability(int level) { 40 | return 50; 41 | } 42 | 43 | @Override 44 | public int getMaxLevel() { 45 | return 1; 46 | } 47 | 48 | @Override 49 | public boolean isTreasureEnchantment() { 50 | return true; 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/de/kcodeyt/vanilla/enchantment/defaults/ChannelingEnchantment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 KCodeYT 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package de.kcodeyt.vanilla.enchantment.defaults; 18 | 19 | import de.kcodeyt.vanilla.enchantment.EnchantmentRarity; 20 | import de.kcodeyt.vanilla.enchantment.EnchantmentType; 21 | import de.kcodeyt.vanilla.enchantment.VanillaEnchantment; 22 | 23 | /** 24 | * @author Kevims KCodeYT 25 | * @version 1.0-SNAPSHOT 26 | */ 27 | public class ChannelingEnchantment extends VanillaEnchantment { 28 | 29 | public ChannelingEnchantment(EnchantmentRarity rarity) { 30 | super(rarity, EnchantmentType.TRIDENT); 31 | } 32 | 33 | @Override 34 | public int getMinEnchantability(int level) { 35 | return 25; 36 | } 37 | 38 | @Override 39 | public int getMaxEnchantability(int level) { 40 | return 50; 41 | } 42 | 43 | @Override 44 | public int getMaxLevel() { 45 | return 1; 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/de/kcodeyt/vanilla/enchantment/defaults/DamageEnchantment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 KCodeYT 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package de.kcodeyt.vanilla.enchantment.defaults; 18 | 19 | import de.kcodeyt.vanilla.enchantment.EnchantmentRarity; 20 | import de.kcodeyt.vanilla.enchantment.EnchantmentType; 21 | import de.kcodeyt.vanilla.enchantment.VanillaEnchantment; 22 | import lombok.AllArgsConstructor; 23 | import lombok.Getter; 24 | 25 | /** 26 | * @author Kevims KCodeYT 27 | * @version 1.0-SNAPSHOT 28 | */ 29 | @Getter 30 | public class DamageEnchantment extends VanillaEnchantment { 31 | 32 | private final Type damageType; 33 | 34 | public DamageEnchantment(EnchantmentRarity rarity, Type type) { 35 | super(rarity, EnchantmentType.WEAPON); 36 | this.damageType = type; 37 | } 38 | 39 | @Override 40 | public int getMinEnchantability(int level) { 41 | return this.damageType.getMinEnchantability() + (level - 1) * this.damageType.getLevelCost(); 42 | } 43 | 44 | @Override 45 | public int getMaxEnchantability(int level) { 46 | return this.getMinEnchantability(level) + 20; 47 | } 48 | 49 | @Override 50 | public int getMaxLevel() { 51 | return 4; 52 | } 53 | 54 | @Override 55 | public boolean canApplyTogether(VanillaEnchantment enchantment) { 56 | return !(enchantment instanceof DamageEnchantment); 57 | } 58 | 59 | /** 60 | * @author Kevims KCodeYT 61 | * @version 1.0-SNAPSHOT 62 | */ 63 | @Getter 64 | @AllArgsConstructor 65 | public enum Type { 66 | ALL(1, 11), 67 | UNDEAD(5, 8), 68 | ARTHROPODS(5, 8); 69 | 70 | private final int minEnchantability; 71 | private final int levelCost; 72 | } 73 | 74 | } 75 | -------------------------------------------------------------------------------- /src/main/java/de/kcodeyt/vanilla/enchantment/defaults/DepthStriderEnchantment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 KCodeYT 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package de.kcodeyt.vanilla.enchantment.defaults; 18 | 19 | import de.kcodeyt.vanilla.enchantment.EnchantmentRarity; 20 | import de.kcodeyt.vanilla.enchantment.EnchantmentType; 21 | import de.kcodeyt.vanilla.enchantment.VanillaEnchantment; 22 | 23 | /** 24 | * @author Kevims KCodeYT 25 | * @version 1.0-SNAPSHOT 26 | */ 27 | public class DepthStriderEnchantment extends VanillaEnchantment { 28 | 29 | public DepthStriderEnchantment(EnchantmentRarity rarity) { 30 | super(rarity, EnchantmentType.ARMOR_BOOTS); 31 | } 32 | 33 | @Override 34 | public int getMinEnchantability(int level) { 35 | return level * 10; 36 | } 37 | 38 | @Override 39 | public int getMaxEnchantability(int level) { 40 | return this.getMinEnchantability(level) + 15; 41 | } 42 | 43 | @Override 44 | public int getMaxLevel() { 45 | return 3; 46 | } 47 | 48 | @Override 49 | public boolean canApplyTogether(VanillaEnchantment enchantment) { 50 | return super.canApplyTogether(enchantment) && !(enchantment instanceof FrostWalkerEnchantment); 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/de/kcodeyt/vanilla/enchantment/defaults/EfficiencyEnchantment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 KCodeYT 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package de.kcodeyt.vanilla.enchantment.defaults; 18 | 19 | import de.kcodeyt.vanilla.enchantment.EnchantmentRarity; 20 | import de.kcodeyt.vanilla.enchantment.EnchantmentType; 21 | import de.kcodeyt.vanilla.enchantment.VanillaEnchantment; 22 | 23 | /** 24 | * @author Kevims KCodeYT 25 | * @version 1.0-SNAPSHOT 26 | */ 27 | public class EfficiencyEnchantment extends VanillaEnchantment { 28 | 29 | public EfficiencyEnchantment(EnchantmentRarity rarity) { 30 | super(rarity, EnchantmentType.TOOL); 31 | } 32 | 33 | @Override 34 | public int getMinEnchantability(int level) { 35 | return 1 + 10 * (level - 1); 36 | } 37 | 38 | @Override 39 | public int getMaxEnchantability(int level) { 40 | return super.getMinEnchantability(level) + 50; 41 | } 42 | 43 | @Override 44 | public int getMaxLevel() { 45 | return 5; 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/de/kcodeyt/vanilla/enchantment/defaults/FireAspectEnchantment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 KCodeYT 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package de.kcodeyt.vanilla.enchantment.defaults; 18 | 19 | import de.kcodeyt.vanilla.enchantment.EnchantmentRarity; 20 | import de.kcodeyt.vanilla.enchantment.EnchantmentType; 21 | import de.kcodeyt.vanilla.enchantment.VanillaEnchantment; 22 | 23 | /** 24 | * @author Kevims KCodeYT 25 | * @version 1.0-SNAPSHOT 26 | */ 27 | public class FireAspectEnchantment extends VanillaEnchantment { 28 | 29 | public FireAspectEnchantment(EnchantmentRarity rarity) { 30 | super(rarity, EnchantmentType.WEAPON); 31 | } 32 | 33 | @Override 34 | public int getMinEnchantability(int level) { 35 | return 10 + 20 * (level - 1); 36 | } 37 | 38 | @Override 39 | public int getMaxEnchantability(int level) { 40 | return super.getMinEnchantability(level) + 50; 41 | } 42 | 43 | @Override 44 | public int getMaxLevel() { 45 | return 2; 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/de/kcodeyt/vanilla/enchantment/defaults/FlameEnchantment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 KCodeYT 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package de.kcodeyt.vanilla.enchantment.defaults; 18 | 19 | import de.kcodeyt.vanilla.enchantment.EnchantmentRarity; 20 | import de.kcodeyt.vanilla.enchantment.EnchantmentType; 21 | import de.kcodeyt.vanilla.enchantment.VanillaEnchantment; 22 | 23 | /** 24 | * @author Kevims KCodeYT 25 | * @version 1.0-SNAPSHOT 26 | */ 27 | public class FlameEnchantment extends VanillaEnchantment { 28 | 29 | public FlameEnchantment(EnchantmentRarity rarity) { 30 | super(rarity, EnchantmentType.BOW); 31 | } 32 | 33 | @Override 34 | public int getMinEnchantability(int level) { 35 | return 20; 36 | } 37 | 38 | @Override 39 | public int getMaxEnchantability(int level) { 40 | return 50; 41 | } 42 | 43 | @Override 44 | public int getMaxLevel() { 45 | return 1; 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/de/kcodeyt/vanilla/enchantment/defaults/FrostWalkerEnchantment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 KCodeYT 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package de.kcodeyt.vanilla.enchantment.defaults; 18 | 19 | import de.kcodeyt.vanilla.enchantment.EnchantmentRarity; 20 | import de.kcodeyt.vanilla.enchantment.EnchantmentType; 21 | import de.kcodeyt.vanilla.enchantment.VanillaEnchantment; 22 | 23 | /** 24 | * @author Kevims KCodeYT 25 | * @version 1.0-SNAPSHOT 26 | */ 27 | public class FrostWalkerEnchantment extends VanillaEnchantment { 28 | 29 | public FrostWalkerEnchantment(EnchantmentRarity rarity) { 30 | super(rarity, EnchantmentType.ARMOR_BOOTS); 31 | } 32 | 33 | @Override 34 | public int getMinEnchantability(int level) { 35 | return level * 10; 36 | } 37 | 38 | @Override 39 | public int getMaxEnchantability(int level) { 40 | return this.getMinEnchantability(level) + 15; 41 | } 42 | 43 | @Override 44 | public int getMaxLevel() { 45 | return 2; 46 | } 47 | 48 | @Override 49 | public boolean isTreasureEnchantment() { 50 | return true; 51 | } 52 | 53 | @Override 54 | public boolean canApplyTogether(VanillaEnchantment enchantment) { 55 | return super.canApplyTogether(enchantment) && !(enchantment instanceof DepthStriderEnchantment); 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/de/kcodeyt/vanilla/enchantment/defaults/ImpalingEnchantment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 KCodeYT 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package de.kcodeyt.vanilla.enchantment.defaults; 18 | 19 | import de.kcodeyt.vanilla.enchantment.EnchantmentRarity; 20 | import de.kcodeyt.vanilla.enchantment.EnchantmentType; 21 | import de.kcodeyt.vanilla.enchantment.VanillaEnchantment; 22 | 23 | /** 24 | * @author Kevims KCodeYT 25 | * @version 1.0-SNAPSHOT 26 | */ 27 | public class ImpalingEnchantment extends VanillaEnchantment { 28 | 29 | public ImpalingEnchantment(EnchantmentRarity rarity) { 30 | super(rarity, EnchantmentType.TRIDENT); 31 | } 32 | 33 | @Override 34 | public int getMinEnchantability(int level) { 35 | return 1 + (level - 1) * 8; 36 | } 37 | 38 | @Override 39 | public int getMaxEnchantability(int level) { 40 | return this.getMinEnchantability(level) + 20; 41 | } 42 | 43 | @Override 44 | public int getMaxLevel() { 45 | return 5; 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/de/kcodeyt/vanilla/enchantment/defaults/InfinityEnchantment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 KCodeYT 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package de.kcodeyt.vanilla.enchantment.defaults; 18 | 19 | import de.kcodeyt.vanilla.enchantment.EnchantmentRarity; 20 | import de.kcodeyt.vanilla.enchantment.EnchantmentType; 21 | import de.kcodeyt.vanilla.enchantment.VanillaEnchantment; 22 | 23 | /** 24 | * @author Kevims KCodeYT 25 | * @version 1.0-SNAPSHOT 26 | */ 27 | public class InfinityEnchantment extends VanillaEnchantment { 28 | 29 | public InfinityEnchantment(EnchantmentRarity rarity) { 30 | super(rarity, EnchantmentType.BOW); 31 | } 32 | 33 | @Override 34 | public int getMinEnchantability(int level) { 35 | return 20; 36 | } 37 | 38 | @Override 39 | public int getMaxEnchantability(int level) { 40 | return 50; 41 | } 42 | 43 | @Override 44 | public int getMaxLevel() { 45 | return 1; 46 | } 47 | 48 | @Override 49 | public boolean canApplyTogether(VanillaEnchantment enchantment) { 50 | return !(enchantment instanceof MendingEnchantment) && super.canApplyTogether(enchantment); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/de/kcodeyt/vanilla/enchantment/defaults/KnockbackEnchantment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 KCodeYT 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package de.kcodeyt.vanilla.enchantment.defaults; 18 | 19 | import de.kcodeyt.vanilla.enchantment.EnchantmentRarity; 20 | import de.kcodeyt.vanilla.enchantment.EnchantmentType; 21 | import de.kcodeyt.vanilla.enchantment.VanillaEnchantment; 22 | 23 | /** 24 | * @author Kevims KCodeYT 25 | * @version 1.0-SNAPSHOT 26 | */ 27 | public class KnockbackEnchantment extends VanillaEnchantment { 28 | 29 | public KnockbackEnchantment(EnchantmentRarity rarity) { 30 | super(rarity, EnchantmentType.WEAPON); 31 | } 32 | 33 | @Override 34 | public int getMinEnchantability(int level) { 35 | return 5 + 20 * (level - 1); 36 | } 37 | 38 | @Override 39 | public int getMaxEnchantability(int level) { 40 | return super.getMinEnchantability(level) + 50; 41 | } 42 | 43 | @Override 44 | public int getMaxLevel() { 45 | return 2; 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/de/kcodeyt/vanilla/enchantment/defaults/LootBonusEnchantment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 KCodeYT 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package de.kcodeyt.vanilla.enchantment.defaults; 18 | 19 | import de.kcodeyt.vanilla.enchantment.EnchantmentRarity; 20 | import de.kcodeyt.vanilla.enchantment.EnchantmentType; 21 | import de.kcodeyt.vanilla.enchantment.VanillaEnchantment; 22 | 23 | /** 24 | * @author Kevims KCodeYT 25 | * @version 1.0-SNAPSHOT 26 | */ 27 | public class LootBonusEnchantment extends VanillaEnchantment { 28 | 29 | public LootBonusEnchantment(EnchantmentRarity rarity, EnchantmentType type) { 30 | super(rarity, type); 31 | } 32 | 33 | @Override 34 | public int getMinEnchantability(int level) { 35 | return 15 + (level - 1) * 9; 36 | } 37 | 38 | @Override 39 | public int getMaxEnchantability(int level) { 40 | return super.getMinEnchantability(level) + 50; 41 | } 42 | 43 | @Override 44 | public int getMaxLevel() { 45 | return 3; 46 | } 47 | 48 | @Override 49 | public boolean canApplyTogether(VanillaEnchantment enchantment) { 50 | return super.canApplyTogether(enchantment) && !(enchantment instanceof SilkTouchEnchantment); 51 | } 52 | } 53 | -------------------------------------------------------------------------------- /src/main/java/de/kcodeyt/vanilla/enchantment/defaults/LoyaltyEnchantment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 KCodeYT 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package de.kcodeyt.vanilla.enchantment.defaults; 18 | 19 | import de.kcodeyt.vanilla.enchantment.EnchantmentRarity; 20 | import de.kcodeyt.vanilla.enchantment.EnchantmentType; 21 | import de.kcodeyt.vanilla.enchantment.VanillaEnchantment; 22 | 23 | /** 24 | * @author Kevims KCodeYT 25 | * @version 1.0-SNAPSHOT 26 | */ 27 | public class LoyaltyEnchantment extends VanillaEnchantment { 28 | 29 | public LoyaltyEnchantment(EnchantmentRarity rarity) { 30 | super(rarity, EnchantmentType.TRIDENT); 31 | } 32 | 33 | @Override 34 | public int getMinEnchantability(int level) { 35 | return 5 + level * 7; 36 | } 37 | 38 | @Override 39 | public int getMaxEnchantability(int level) { 40 | return 50; 41 | } 42 | 43 | @Override 44 | public int getMaxLevel() { 45 | return 3; 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/de/kcodeyt/vanilla/enchantment/defaults/LureEnchantment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 KCodeYT 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package de.kcodeyt.vanilla.enchantment.defaults; 18 | 19 | import de.kcodeyt.vanilla.enchantment.EnchantmentRarity; 20 | import de.kcodeyt.vanilla.enchantment.EnchantmentType; 21 | import de.kcodeyt.vanilla.enchantment.VanillaEnchantment; 22 | 23 | /** 24 | * @author Kevims KCodeYT 25 | * @version 1.0-SNAPSHOT 26 | */ 27 | public class LureEnchantment extends VanillaEnchantment { 28 | 29 | public LureEnchantment(EnchantmentRarity rarity) { 30 | super(rarity, EnchantmentType.FISHING_ROD); 31 | } 32 | 33 | @Override 34 | public int getMinEnchantability(int level) { 35 | return 15 + (level - 1) * 9; 36 | } 37 | 38 | @Override 39 | public int getMaxEnchantability(int level) { 40 | return super.getMinEnchantability(level) + 50; 41 | } 42 | 43 | @Override 44 | public int getMaxLevel() { 45 | return 3; 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/de/kcodeyt/vanilla/enchantment/defaults/MendingEnchantment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 KCodeYT 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package de.kcodeyt.vanilla.enchantment.defaults; 18 | 19 | import de.kcodeyt.vanilla.enchantment.EnchantmentRarity; 20 | import de.kcodeyt.vanilla.enchantment.EnchantmentType; 21 | import de.kcodeyt.vanilla.enchantment.VanillaEnchantment; 22 | 23 | /** 24 | * @author Kevims KCodeYT 25 | * @version 1.0-SNAPSHOT 26 | */ 27 | public class MendingEnchantment extends VanillaEnchantment { 28 | 29 | public MendingEnchantment(EnchantmentRarity rarity) { 30 | super(rarity, EnchantmentType.BREAKABLE); 31 | } 32 | 33 | @Override 34 | public int getMinEnchantability(int level) { 35 | return level * 25; 36 | } 37 | 38 | @Override 39 | public int getMaxEnchantability(int level) { 40 | return this.getMinEnchantability(level) + 50; 41 | } 42 | 43 | @Override 44 | public int getMaxLevel() { 45 | return 1; 46 | } 47 | 48 | @Override 49 | public boolean isTreasureEnchantment() { 50 | return true; 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/de/kcodeyt/vanilla/enchantment/defaults/MultishotEnchantment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 KCodeYT 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package de.kcodeyt.vanilla.enchantment.defaults; 18 | 19 | import de.kcodeyt.vanilla.enchantment.EnchantmentRarity; 20 | import de.kcodeyt.vanilla.enchantment.EnchantmentType; 21 | import de.kcodeyt.vanilla.enchantment.VanillaEnchantment; 22 | 23 | /** 24 | * @author Kevims KCodeYT 25 | * @version 1.0-SNAPSHOT 26 | */ 27 | public class MultishotEnchantment extends VanillaEnchantment { 28 | 29 | public MultishotEnchantment(EnchantmentRarity rarity) { 30 | super(rarity, EnchantmentType.CROSSBOW); 31 | } 32 | 33 | @Override 34 | public int getMinEnchantability(int level) { 35 | return 20; 36 | } 37 | 38 | @Override 39 | public int getMaxEnchantability(int level) { 40 | return 50; 41 | } 42 | 43 | @Override 44 | public int getMaxLevel() { 45 | return 1; 46 | } 47 | 48 | @Override 49 | public boolean canApplyTogether(VanillaEnchantment enchantment) { 50 | return super.canApplyTogether(enchantment) && !(enchantment instanceof PiercingEnchantment); 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/de/kcodeyt/vanilla/enchantment/defaults/PiercingEnchantment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 KCodeYT 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package de.kcodeyt.vanilla.enchantment.defaults; 18 | 19 | import de.kcodeyt.vanilla.enchantment.EnchantmentRarity; 20 | import de.kcodeyt.vanilla.enchantment.EnchantmentType; 21 | import de.kcodeyt.vanilla.enchantment.VanillaEnchantment; 22 | 23 | /** 24 | * @author Kevims KCodeYT 25 | * @version 1.0-SNAPSHOT 26 | */ 27 | public class PiercingEnchantment extends VanillaEnchantment { 28 | 29 | public PiercingEnchantment(EnchantmentRarity rarity) { 30 | super(rarity, EnchantmentType.CROSSBOW); 31 | } 32 | 33 | @Override 34 | public int getMinEnchantability(int level) { 35 | return 1 + (level - 1) * 10; 36 | } 37 | 38 | @Override 39 | public int getMaxEnchantability(int level) { 40 | return 50; 41 | } 42 | 43 | @Override 44 | public int getMaxLevel() { 45 | return 1; 46 | } 47 | 48 | @Override 49 | public boolean canApplyTogether(VanillaEnchantment enchantment) { 50 | return super.canApplyTogether(enchantment) && !(enchantment instanceof MultishotEnchantment); 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/de/kcodeyt/vanilla/enchantment/defaults/PowerEnchantment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 KCodeYT 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package de.kcodeyt.vanilla.enchantment.defaults; 18 | 19 | import de.kcodeyt.vanilla.enchantment.EnchantmentRarity; 20 | import de.kcodeyt.vanilla.enchantment.EnchantmentType; 21 | import de.kcodeyt.vanilla.enchantment.VanillaEnchantment; 22 | 23 | /** 24 | * @author Kevims KCodeYT 25 | * @version 1.0-SNAPSHOT 26 | */ 27 | public class PowerEnchantment extends VanillaEnchantment { 28 | 29 | public PowerEnchantment(EnchantmentRarity rarity) { 30 | super(rarity, EnchantmentType.BOW); 31 | } 32 | 33 | @Override 34 | public int getMinEnchantability(int level) { 35 | return 1 + (level - 1) * 10; 36 | } 37 | 38 | @Override 39 | public int getMaxEnchantability(int level) { 40 | return this.getMinEnchantability(level) + 15; 41 | } 42 | 43 | @Override 44 | public int getMaxLevel() { 45 | return 5; 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/de/kcodeyt/vanilla/enchantment/defaults/ProtectionEnchantment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 KCodeYT 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package de.kcodeyt.vanilla.enchantment.defaults; 18 | 19 | import de.kcodeyt.vanilla.enchantment.EnchantmentRarity; 20 | import de.kcodeyt.vanilla.enchantment.EnchantmentType; 21 | import de.kcodeyt.vanilla.enchantment.VanillaEnchantment; 22 | import lombok.AllArgsConstructor; 23 | import lombok.Getter; 24 | 25 | /** 26 | * @author Kevims KCodeYT 27 | * @version 1.0-SNAPSHOT 28 | */ 29 | @Getter 30 | public class ProtectionEnchantment extends VanillaEnchantment { 31 | 32 | private final Type protectionType; 33 | 34 | public ProtectionEnchantment(EnchantmentRarity rarity, Type type) { 35 | super(rarity, type == Type.FALL ? EnchantmentType.ARMOR_BOOTS : EnchantmentType.ARMOR); 36 | this.protectionType = type; 37 | } 38 | 39 | @Override 40 | public int getMinEnchantability(int level) { 41 | return this.protectionType.getMinEnchantability() + (level - 1) * this.protectionType.getLevelCost(); 42 | } 43 | 44 | @Override 45 | public int getMaxEnchantability(int level) { 46 | return this.getMinEnchantability(level) + this.protectionType.getLevelCost(); 47 | } 48 | 49 | @Override 50 | public int getMaxLevel() { 51 | return 4; 52 | } 53 | 54 | @Override 55 | public boolean canApplyTogether(VanillaEnchantment enchantment) { 56 | return enchantment instanceof ProtectionEnchantment ? 57 | this.protectionType != ((ProtectionEnchantment) enchantment).protectionType && 58 | (this.protectionType == Type.FALL || ((ProtectionEnchantment) enchantment).protectionType == Type.FALL) : 59 | super.canApplyTogether(enchantment); 60 | } 61 | 62 | /** 63 | * @author Kevims KCodeYT 64 | * @version 1.0-SNAPSHOT 65 | */ 66 | @Getter 67 | @AllArgsConstructor 68 | public enum Type { 69 | ALL(1, 11), 70 | FIRE(10, 8), 71 | FALL(5, 6), 72 | EXPLOSION(5, 8), 73 | PROJECTILE(3, 6); 74 | 75 | private final int minEnchantability; 76 | private final int levelCost; 77 | } 78 | 79 | } 80 | -------------------------------------------------------------------------------- /src/main/java/de/kcodeyt/vanilla/enchantment/defaults/PunchEnchantment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 KCodeYT 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package de.kcodeyt.vanilla.enchantment.defaults; 18 | 19 | import de.kcodeyt.vanilla.enchantment.EnchantmentRarity; 20 | import de.kcodeyt.vanilla.enchantment.EnchantmentType; 21 | import de.kcodeyt.vanilla.enchantment.VanillaEnchantment; 22 | 23 | /** 24 | * @author Kevims KCodeYT 25 | * @version 1.0-SNAPSHOT 26 | */ 27 | public class PunchEnchantment extends VanillaEnchantment { 28 | 29 | public PunchEnchantment(EnchantmentRarity rarity) { 30 | super(rarity, EnchantmentType.BOW); 31 | } 32 | 33 | @Override 34 | public int getMinEnchantability(int level) { 35 | return 12 + (level - 1) * 20; 36 | } 37 | 38 | @Override 39 | public int getMaxEnchantability(int level) { 40 | return this.getMinEnchantability(level) + 25; 41 | } 42 | 43 | @Override 44 | public int getMaxLevel() { 45 | return 2; 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/de/kcodeyt/vanilla/enchantment/defaults/QuickChargeEnchantment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 KCodeYT 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package de.kcodeyt.vanilla.enchantment.defaults; 18 | 19 | import de.kcodeyt.vanilla.enchantment.EnchantmentRarity; 20 | import de.kcodeyt.vanilla.enchantment.EnchantmentType; 21 | import de.kcodeyt.vanilla.enchantment.VanillaEnchantment; 22 | 23 | /** 24 | * @author Kevims KCodeYT 25 | * @version 1.0-SNAPSHOT 26 | */ 27 | public class QuickChargeEnchantment extends VanillaEnchantment { 28 | 29 | public QuickChargeEnchantment(EnchantmentRarity rarity) { 30 | super(rarity, EnchantmentType.CROSSBOW); 31 | } 32 | 33 | @Override 34 | public int getMinEnchantability(int level) { 35 | return 12 + (level - 1) * 20; 36 | } 37 | 38 | @Override 39 | public int getMaxEnchantability(int level) { 40 | return 50; 41 | } 42 | 43 | @Override 44 | public int getMaxLevel() { 45 | return 3; 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/de/kcodeyt/vanilla/enchantment/defaults/RespirationEnchantment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 KCodeYT 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package de.kcodeyt.vanilla.enchantment.defaults; 18 | 19 | import de.kcodeyt.vanilla.enchantment.EnchantmentRarity; 20 | import de.kcodeyt.vanilla.enchantment.EnchantmentType; 21 | import de.kcodeyt.vanilla.enchantment.VanillaEnchantment; 22 | 23 | /** 24 | * @author Kevims KCodeYT 25 | * @version 1.0-SNAPSHOT 26 | */ 27 | public class RespirationEnchantment extends VanillaEnchantment { 28 | 29 | public RespirationEnchantment(EnchantmentRarity rarity) { 30 | super(rarity, EnchantmentType.ARMOR_HELMET); 31 | } 32 | 33 | @Override 34 | public int getMinEnchantability(int level) { 35 | return 10 * level; 36 | } 37 | 38 | @Override 39 | public int getMaxEnchantability(int level) { 40 | return this.getMinEnchantability(level) + 30; 41 | } 42 | 43 | @Override 44 | public int getMaxLevel() { 45 | return 3; 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/de/kcodeyt/vanilla/enchantment/defaults/RiptideEnchantment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 KCodeYT 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package de.kcodeyt.vanilla.enchantment.defaults; 18 | 19 | import de.kcodeyt.vanilla.enchantment.EnchantmentRarity; 20 | import de.kcodeyt.vanilla.enchantment.EnchantmentType; 21 | import de.kcodeyt.vanilla.enchantment.VanillaEnchantment; 22 | 23 | /** 24 | * @author Kevims KCodeYT 25 | * @version 1.0-SNAPSHOT 26 | */ 27 | public class RiptideEnchantment extends VanillaEnchantment { 28 | 29 | public RiptideEnchantment(EnchantmentRarity rarity) { 30 | super(rarity, EnchantmentType.TRIDENT); 31 | } 32 | 33 | @Override 34 | public int getMinEnchantability(int level) { 35 | return 10 + level * 7; 36 | } 37 | 38 | @Override 39 | public int getMaxEnchantability(int level) { 40 | return 50; 41 | } 42 | 43 | @Override 44 | public int getMaxLevel() { 45 | return 3; 46 | } 47 | 48 | @Override 49 | public boolean canApplyTogether(VanillaEnchantment enchantment) { 50 | return super.canApplyTogether(enchantment) && !(enchantment instanceof LoyaltyEnchantment) && !(enchantment instanceof ChannelingEnchantment); 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/de/kcodeyt/vanilla/enchantment/defaults/SilkTouchEnchantment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 KCodeYT 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package de.kcodeyt.vanilla.enchantment.defaults; 18 | 19 | import de.kcodeyt.vanilla.enchantment.EnchantmentRarity; 20 | import de.kcodeyt.vanilla.enchantment.EnchantmentType; 21 | import de.kcodeyt.vanilla.enchantment.VanillaEnchantment; 22 | 23 | /** 24 | * @author Kevims KCodeYT 25 | * @version 1.0-SNAPSHOT 26 | */ 27 | public class SilkTouchEnchantment extends VanillaEnchantment { 28 | 29 | public SilkTouchEnchantment(EnchantmentRarity rarity) { 30 | super(rarity, EnchantmentType.TOOL); 31 | } 32 | 33 | @Override 34 | public int getMinEnchantability(int level) { 35 | return 15; 36 | } 37 | 38 | @Override 39 | public int getMaxEnchantability(int level) { 40 | return super.getMinEnchantability(level) + 50; 41 | } 42 | 43 | @Override 44 | public int getMaxLevel() { 45 | return 1; 46 | } 47 | 48 | @Override 49 | public boolean canApplyTogether(VanillaEnchantment enchantment) { 50 | return super.canApplyTogether(enchantment) && !(enchantment instanceof LootBonusEnchantment && enchantment.getType() == this.getType()); 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/de/kcodeyt/vanilla/enchantment/defaults/SoulSpeedEnchantment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 KCodeYT 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package de.kcodeyt.vanilla.enchantment.defaults; 18 | 19 | import de.kcodeyt.vanilla.enchantment.EnchantmentRarity; 20 | import de.kcodeyt.vanilla.enchantment.EnchantmentType; 21 | import de.kcodeyt.vanilla.enchantment.VanillaEnchantment; 22 | 23 | /** 24 | * @author Kevims KCodeYT 25 | * @version 1.0-SNAPSHOT 26 | */ 27 | public class SoulSpeedEnchantment extends VanillaEnchantment { 28 | 29 | public SoulSpeedEnchantment(EnchantmentRarity rarity) { 30 | super(rarity, EnchantmentType.ARMOR_BOOTS); 31 | } 32 | 33 | @Override 34 | public int getMinEnchantability(int level) { 35 | return level * 10; 36 | } 37 | 38 | @Override 39 | public int getMaxEnchantability(int level) { 40 | return this.getMinEnchantability(level) + 15; 41 | } 42 | 43 | @Override 44 | public int getMaxLevel() { 45 | return 3; 46 | } 47 | 48 | @Override 49 | public boolean isTreasureEnchantment() { 50 | return true; 51 | } 52 | 53 | @Override 54 | public boolean canGenerateInLoot() { 55 | return false; 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/de/kcodeyt/vanilla/enchantment/defaults/SwiftSneakEnchantment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 KCodeYT 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package de.kcodeyt.vanilla.enchantment.defaults; 18 | 19 | import de.kcodeyt.vanilla.enchantment.EnchantmentRarity; 20 | import de.kcodeyt.vanilla.enchantment.EnchantmentType; 21 | import de.kcodeyt.vanilla.enchantment.VanillaEnchantment; 22 | 23 | /** 24 | * @author Kevims KCodeYT 25 | * @version 1.0-SNAPSHOT 26 | */ 27 | public class SwiftSneakEnchantment extends VanillaEnchantment { 28 | 29 | public SwiftSneakEnchantment(EnchantmentRarity rarity) { 30 | super(rarity, EnchantmentType.ARMOR_LEGGINGS); 31 | } 32 | 33 | @Override 34 | public int getMinEnchantability(int level) { 35 | return level * 25; 36 | } 37 | 38 | @Override 39 | public int getMaxEnchantability(int level) { 40 | return this.getMinEnchantability(level) + 50; 41 | } 42 | 43 | @Override 44 | public int getMaxLevel() { 45 | return 3; 46 | } 47 | 48 | @Override 49 | public boolean isTreasureEnchantment() { 50 | return true; 51 | } 52 | 53 | @Override 54 | public boolean canGenerateInLoot() { 55 | return false; 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/de/kcodeyt/vanilla/enchantment/defaults/ThornsEnchantment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 KCodeYT 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package de.kcodeyt.vanilla.enchantment.defaults; 18 | 19 | import de.kcodeyt.vanilla.enchantment.EnchantmentRarity; 20 | import de.kcodeyt.vanilla.enchantment.EnchantmentType; 21 | import de.kcodeyt.vanilla.enchantment.VanillaEnchantment; 22 | 23 | /** 24 | * @author Kevims KCodeYT 25 | * @version 1.0-SNAPSHOT 26 | */ 27 | public class ThornsEnchantment extends VanillaEnchantment { 28 | 29 | public ThornsEnchantment(EnchantmentRarity rarity) { 30 | super(rarity, EnchantmentType.ARMOR); 31 | } 32 | 33 | @Override 34 | public int getMinEnchantability(int level) { 35 | return 10 + 20 * (level - 1); 36 | } 37 | 38 | @Override 39 | public int getMaxEnchantability(int level) { 40 | return super.getMinEnchantability(level) + 50; 41 | } 42 | 43 | @Override 44 | public int getMaxLevel() { 45 | return 3; 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/de/kcodeyt/vanilla/enchantment/defaults/UnbreakingEnchantment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 KCodeYT 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package de.kcodeyt.vanilla.enchantment.defaults; 18 | 19 | import de.kcodeyt.vanilla.enchantment.EnchantmentRarity; 20 | import de.kcodeyt.vanilla.enchantment.EnchantmentType; 21 | import de.kcodeyt.vanilla.enchantment.VanillaEnchantment; 22 | 23 | /** 24 | * @author Kevims KCodeYT 25 | * @version 1.0-SNAPSHOT 26 | */ 27 | public class UnbreakingEnchantment extends VanillaEnchantment { 28 | 29 | public UnbreakingEnchantment(EnchantmentRarity rarity) { 30 | super(rarity, EnchantmentType.BREAKABLE); 31 | } 32 | 33 | @Override 34 | public int getMinEnchantability(int level) { 35 | return 5 + (level - 1) * 8; 36 | } 37 | 38 | @Override 39 | public int getMaxEnchantability(int level) { 40 | return super.getMinEnchantability(level) + 50; 41 | } 42 | 43 | @Override 44 | public int getMaxLevel() { 45 | return 3; 46 | } 47 | 48 | } 49 | -------------------------------------------------------------------------------- /src/main/java/de/kcodeyt/vanilla/enchantment/defaults/VanishingCurseEnchantment.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 KCodeYT 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package de.kcodeyt.vanilla.enchantment.defaults; 18 | 19 | import de.kcodeyt.vanilla.enchantment.EnchantmentRarity; 20 | import de.kcodeyt.vanilla.enchantment.EnchantmentType; 21 | import de.kcodeyt.vanilla.enchantment.VanillaEnchantment; 22 | 23 | /** 24 | * @author Kevims KCodeYT 25 | * @version 1.0-SNAPSHOT 26 | */ 27 | public class VanishingCurseEnchantment extends VanillaEnchantment { 28 | 29 | public VanishingCurseEnchantment(EnchantmentRarity rarity) { 30 | super(rarity, EnchantmentType.VANISH); 31 | } 32 | 33 | @Override 34 | public int getMinEnchantability(int level) { 35 | return 25; 36 | } 37 | 38 | @Override 39 | public int getMaxEnchantability(int level) { 40 | return 50; 41 | } 42 | 43 | @Override 44 | public int getMaxLevel() { 45 | return 1; 46 | } 47 | 48 | @Override 49 | public boolean isTreasureEnchantment() { 50 | return true; 51 | } 52 | 53 | } 54 | -------------------------------------------------------------------------------- /src/main/java/de/kcodeyt/vanilla/generator/Vanilla.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 KCodeYT 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package de.kcodeyt.vanilla.generator; 18 | 19 | import cn.nukkit.level.ChunkManager; 20 | import cn.nukkit.level.format.generic.BaseFullChunk; 21 | import cn.nukkit.level.generator.Generator; 22 | import cn.nukkit.math.NukkitRandom; 23 | import cn.nukkit.math.Vector3; 24 | import de.kcodeyt.vanilla.VanillaGeneratorPlugin; 25 | import de.kcodeyt.vanilla.generator.server.VanillaServer; 26 | 27 | import java.util.Collections; 28 | import java.util.Map; 29 | 30 | /** 31 | * @author Kevims KCodeYT 32 | * @version 1.0-SNAPSHOT 33 | */ 34 | public abstract class Vanilla extends Generator { 35 | 36 | private static final Vector3 SPAWN_VECTOR = new Vector3(0.5, 128, 0.5); 37 | 38 | private VanillaServer vanillaServer; 39 | 40 | @Override 41 | public void init(ChunkManager chunkManager, NukkitRandom nukkitRandom) { 42 | if(this.level.getServer().isPrimaryThread()) 43 | this.vanillaServer = VanillaGeneratorPlugin.getVanillaServer(this.level).join(); 44 | } 45 | 46 | @Override 47 | public void generateChunk(int chunkX, int chunkZ) { 48 | final BaseFullChunk fullChunk = this.chunkManager.getChunk(chunkX, chunkZ); 49 | if(this.vanillaServer == null) this.vanillaServer = VanillaGeneratorPlugin.getVanillaServer(this.level).join(); 50 | 51 | this.vanillaServer.requestChunk(fullChunk); 52 | } 53 | 54 | @Override 55 | public void populateChunk(int chunkX, int chunkZ) { 56 | 57 | } 58 | 59 | @Override 60 | public Map getSettings() { 61 | return Collections.emptyMap(); 62 | } 63 | 64 | @Override 65 | public Vector3 getSpawn() { 66 | return SPAWN_VECTOR; 67 | } 68 | 69 | } -------------------------------------------------------------------------------- /src/main/java/de/kcodeyt/vanilla/generator/VanillaNether.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 KCodeYT 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package de.kcodeyt.vanilla.generator; 18 | 19 | import cn.nukkit.level.DimensionData; 20 | import cn.nukkit.level.DimensionEnum; 21 | 22 | import java.util.Map; 23 | 24 | /** 25 | * @author Kevims KCodeYT 26 | * @version 1.0-SNAPSHOT 27 | */ 28 | public class VanillaNether extends Vanilla { 29 | 30 | public static final int TYPE = 101; 31 | 32 | public VanillaNether(Map options) { 33 | 34 | } 35 | 36 | @Override 37 | public int getId() { 38 | return VanillaNether.TYPE; 39 | } 40 | 41 | @Override 42 | public DimensionData getDimensionData() { 43 | return DimensionEnum.NETHER.getDimensionData(); 44 | } 45 | 46 | @Override 47 | public String getName() { 48 | return "vanilla_nether"; 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/de/kcodeyt/vanilla/generator/VanillaOverworld.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 KCodeYT 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package de.kcodeyt.vanilla.generator; 18 | 19 | import cn.nukkit.level.DimensionData; 20 | import cn.nukkit.level.DimensionEnum; 21 | import cn.nukkit.level.Level; 22 | 23 | import java.util.Map; 24 | 25 | /** 26 | * @author Kevims KCodeYT 27 | * @version 1.0-SNAPSHOT 28 | */ 29 | public class VanillaOverworld extends Vanilla { 30 | 31 | public static final int TYPE = 100; 32 | 33 | public VanillaOverworld(Map options) { 34 | } 35 | 36 | @Override 37 | public int getId() { 38 | return VanillaOverworld.TYPE; 39 | } 40 | 41 | @Override 42 | public DimensionData getDimensionData() { 43 | return DimensionEnum.OVERWORLD.getDimensionData(); 44 | } 45 | 46 | @Override 47 | public String getName() { 48 | return "vanilla"; 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/de/kcodeyt/vanilla/generator/VanillaTheEnd.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 KCodeYT 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package de.kcodeyt.vanilla.generator; 18 | 19 | import cn.nukkit.level.DimensionData; 20 | import cn.nukkit.level.DimensionEnum; 21 | 22 | import java.util.Map; 23 | 24 | /** 25 | * @author Kevims KCodeYT 26 | * @version 1.0-SNAPSHOT 27 | */ 28 | public class VanillaTheEnd extends Vanilla { 29 | 30 | public static final int TYPE = 102; 31 | 32 | public VanillaTheEnd(Map options) { 33 | } 34 | 35 | @Override 36 | public int getId() { 37 | return VanillaTheEnd.TYPE; 38 | } 39 | 40 | @Override 41 | public DimensionData getDimensionData() { 42 | return DimensionEnum.END.getDimensionData(); 43 | } 44 | 45 | @Override 46 | public String getName() { 47 | return "vanilla_the_end"; 48 | } 49 | 50 | } 51 | -------------------------------------------------------------------------------- /src/main/java/de/kcodeyt/vanilla/generator/chunk/ChunkData.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 KCodeYT 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package de.kcodeyt.vanilla.generator.chunk; 18 | 19 | import cn.nukkit.blockstate.BlockState; 20 | import cn.nukkit.blockstate.BlockStateRegistry; 21 | import cn.nukkit.level.format.anvil.Chunk; 22 | import cn.nukkit.level.format.generic.BaseFullChunk; 23 | import cn.nukkit.nbt.NBTIO; 24 | import cn.nukkit.nbt.tag.CompoundTag; 25 | import cn.nukkit.utils.BinaryStream; 26 | import com.nukkitx.protocol.bedrock.data.SubChunkData; 27 | import com.nukkitx.protocol.bedrock.data.SubChunkRequestResult; 28 | import de.kcodeyt.vanilla.VanillaGeneratorPlugin; 29 | import de.kcodeyt.vanilla.generator.server.VanillaServer; 30 | import de.kcodeyt.vanilla.util.Palette; 31 | import de.kcodeyt.vanilla.world.BlockEntityData; 32 | import de.kcodeyt.vanilla.world.World; 33 | import it.unimi.dsi.fastutil.ints.Int2ObjectMap; 34 | import it.unimi.dsi.fastutil.io.FastByteArrayInputStream; 35 | import lombok.Getter; 36 | import lombok.RequiredArgsConstructor; 37 | 38 | import java.nio.ByteOrder; 39 | import java.util.List; 40 | 41 | /** 42 | * @author Kevims KCodeYT 43 | * @version 1.0-SNAPSHOT 44 | */ 45 | @Getter 46 | @RequiredArgsConstructor 47 | public class ChunkData { 48 | 49 | private final World world; 50 | private final int x; 51 | private final int z; 52 | private final List data; 53 | private final Int2ObjectMap biomes; 54 | 55 | public void build(VanillaServer vanillaServer, BaseFullChunk fullChunk) { 56 | try { 57 | if(!(fullChunk instanceof final Chunk anvilChunk)) return; 58 | 59 | final long startTime = System.currentTimeMillis(); 60 | 61 | anvilChunk.setGenerated(); 62 | anvilChunk.setPopulated(); 63 | 64 | for(Int2ObjectMap.Entry entry : this.biomes.int2ObjectEntrySet()) { 65 | final int[] biomes = entry.getValue(); 66 | final int subY = entry.getIntKey(); 67 | 68 | for(int i = 0; i < biomes.length; i++) 69 | fullChunk.setBiomeId((i >> 8) & 0xF, (subY << 4) + (i & 0xF), (i >> 4) & 0xF, biomes[i]); 70 | } 71 | 72 | for(SubChunkData chunkData : this.data) { 73 | if(chunkData.getResult() != SubChunkRequestResult.SUCCESS) continue; 74 | 75 | final BinaryStream binaryStream = new BinaryStream(chunkData.getData()); 76 | final int subChunkVersion = binaryStream.getByte(); 77 | final byte layers = (byte) binaryStream.getByte(); 78 | final byte subY = (byte) binaryStream.getByte(); 79 | 80 | for(byte layer = 0; layer < layers; layer++) { 81 | final int header = binaryStream.getByte(); 82 | final int version = header >> 1; 83 | 84 | if(version == 0) { 85 | BlockState blockState; 86 | try { 87 | blockState = BlockStateRegistry.getBlockStateByRuntimeId(binaryStream.getVarInt()); 88 | } catch(Exception e) { 89 | blockState = BlockStateRegistry.getFallbackBlockState(); 90 | } 91 | 92 | for(int i = 0; i < Palette.SIZE; i++) 93 | anvilChunk.setBlockStateAtLayer((i >> 8) & 0xF, (subY << 4) + (i & 0xF), (i >> 4) & 0xF, layer, blockState); 94 | } else { 95 | final short[] indices = Palette.parseIndices(binaryStream, version); 96 | final BlockState[] blockStates = new BlockState[binaryStream.getVarInt()]; 97 | for(int i = 0; i < blockStates.length; i++) 98 | try { 99 | blockStates[i] = BlockStateRegistry.getBlockStateByRuntimeId(binaryStream.getVarInt()); 100 | } catch(Exception e) { 101 | blockStates[i] = BlockStateRegistry.getFallbackBlockState(); 102 | } 103 | 104 | for(int i = 0; i < Palette.SIZE; i++) { 105 | final BlockState blockState = blockStates[indices[i]]; 106 | if(blockState != null) 107 | anvilChunk.setBlockStateAtLayer((i >> 8) & 0xF, (subY << 4) + (i & 0xF), (i >> 4) & 0xF, layer, blockState); 108 | } 109 | } 110 | } 111 | 112 | try(final FastByteArrayInputStream inputStream = new FastByteArrayInputStream(binaryStream.get())) { 113 | while(true) { 114 | try { 115 | final CompoundTag compoundTag = NBTIO.read(inputStream, ByteOrder.LITTLE_ENDIAN, true); 116 | if(compoundTag != null && compoundTag.containsString("id")) 117 | BlockEntityData.direct(vanillaServer, fullChunk, compoundTag); 118 | } catch(Exception e) { 119 | break; 120 | } 121 | } 122 | } 123 | } 124 | 125 | final long timeTook = System.currentTimeMillis() - startTime; 126 | if(timeTook > 1500) 127 | VanillaGeneratorPlugin.getInstance().getLogger().warning("Build chunk take too long! Took " + timeTook + "ms!"); 128 | } catch(Throwable throwable) { 129 | VanillaGeneratorPlugin.getInstance().getLogger().error("GOT EXCEPTION", throwable); 130 | } 131 | } 132 | 133 | } 134 | -------------------------------------------------------------------------------- /src/main/java/de/kcodeyt/vanilla/generator/chunk/ChunkRequest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 KCodeYT 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package de.kcodeyt.vanilla.generator.chunk; 18 | 19 | import cn.nukkit.math.BlockVector3; 20 | import lombok.Getter; 21 | 22 | import java.util.Objects; 23 | import java.util.concurrent.CompletableFuture; 24 | 25 | /** 26 | * @author Kevims KCodeYT 27 | * @version 1.0-SNAPSHOT 28 | */ 29 | @Getter 30 | public class ChunkRequest { 31 | 32 | private final int x; 33 | private final int z; 34 | private final CompletableFuture future; 35 | 36 | public ChunkRequest(int x, int z, CompletableFuture future) { 37 | this.x = x; 38 | this.z = z; 39 | this.future = future; 40 | } 41 | 42 | @Override 43 | public boolean equals(Object o) { 44 | if(this == o) return true; 45 | if(o == null || getClass() != o.getClass()) return false; 46 | ChunkRequest that = (ChunkRequest) o; 47 | return x == that.x && 48 | z == that.z; 49 | } 50 | 51 | @Override 52 | public int hashCode() { 53 | return Objects.hash(this.x, this.z); 54 | } 55 | 56 | public BlockVector3 getCenterPosition() { 57 | return new BlockVector3((this.x << 4) + 8, 260, (this.z << 4) + 8); 58 | } 59 | 60 | } 61 | -------------------------------------------------------------------------------- /src/main/java/de/kcodeyt/vanilla/generator/chunk/ChunkWaiter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 KCodeYT 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package de.kcodeyt.vanilla.generator.chunk; 18 | 19 | import cn.nukkit.Server; 20 | import cn.nukkit.level.Level; 21 | import cn.nukkit.level.Position; 22 | import cn.nukkit.level.format.FullChunk; 23 | import cn.nukkit.level.format.generic.BaseFullChunk; 24 | 25 | import java.util.function.Consumer; 26 | 27 | /** 28 | * @author Kevims KCodeYT 29 | * @version 1.0-SNAPSHOT 30 | */ 31 | public class ChunkWaiter { 32 | 33 | private final Runnable task; 34 | 35 | private ChunkWaiter(Level level, int x, int z, Consumer chunkConsumer) { 36 | this.task = () -> { 37 | final BaseFullChunk fullChunk = level.getChunk(x, z); 38 | if(fullChunk == null || !fullChunk.isGenerated() || !fullChunk.isPopulated()) 39 | this.scheduleTask(); 40 | else 41 | chunkConsumer.accept(fullChunk); 42 | }; 43 | 44 | this.scheduleDirectTask(); 45 | } 46 | 47 | public static void waitFor(Position position, Consumer chunkConsumer) { 48 | new ChunkWaiter(position.getLevel(), position.getChunkX(), position.getChunkZ(), chunkConsumer); 49 | } 50 | 51 | private void scheduleTask() { 52 | Server.getInstance().getScheduler().scheduleDelayedTask(null, this.task, 1); 53 | } 54 | 55 | private void scheduleDirectTask() { 56 | Server.getInstance().getScheduler().scheduleTask(null, this.task); 57 | } 58 | 59 | } 60 | -------------------------------------------------------------------------------- /src/main/java/de/kcodeyt/vanilla/generator/client/ConnectionState.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 KCodeYT 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package de.kcodeyt.vanilla.generator.client; 18 | 19 | import com.nukkitx.protocol.bedrock.handler.BedrockPacketHandler; 20 | import de.kcodeyt.vanilla.generator.client.handler.LoginHandler; 21 | import de.kcodeyt.vanilla.generator.client.handler.NetworkHandler; 22 | import de.kcodeyt.vanilla.generator.client.handler.PlayingHandler; 23 | import de.kcodeyt.vanilla.generator.client.handler.ResourcePackHandler; 24 | import lombok.RequiredArgsConstructor; 25 | 26 | import java.util.function.Function; 27 | 28 | /** 29 | * @author Kevims KCodeYT 30 | * @version 1.0-SNAPSHOT 31 | */ 32 | @RequiredArgsConstructor 33 | public enum ConnectionState { 34 | 35 | NETWORK_INIT(NetworkHandler::new), 36 | LOGIN(LoginHandler::new), 37 | RESOURCE_PACK(ResourcePackHandler::new), 38 | PLAYING(PlayingHandler::new); 39 | 40 | private final Function constructor; 41 | 42 | public BedrockPacketHandler newPacketHandler(Client client) { 43 | return this.constructor.apply(client); 44 | } 45 | 46 | } 47 | -------------------------------------------------------------------------------- /src/main/java/de/kcodeyt/vanilla/generator/client/MojangLoginForger.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 KCodeYT 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package de.kcodeyt.vanilla.generator.client; 18 | 19 | import com.nimbusds.jose.*; 20 | import com.nimbusds.jose.shaded.json.JSONObject; 21 | import com.nimbusds.jose.shaded.json.JSONStyle; 22 | import com.nukkitx.protocol.bedrock.util.EncryptionUtils; 23 | import de.kcodeyt.vanilla.generator.client.clientdata.LoginData; 24 | import lombok.experimental.UtilityClass; 25 | 26 | import java.net.URI; 27 | import java.security.KeyPair; 28 | import java.security.interfaces.ECPrivateKey; 29 | import java.util.Base64; 30 | import java.util.Collections; 31 | 32 | /** 33 | * @author Kevims KCodeYT 34 | * @version 1.0-SNAPSHOT 35 | */ 36 | @UtilityClass 37 | public class MojangLoginForger { 38 | 39 | private static final String TITLE_ID_MINECRAFT_PE = "1739947436"; 40 | 41 | public String forge(KeyPair keyPair, JSONObject jsonObject) throws JOSEException { 42 | final JWSObject jwsObject = new JWSObject( 43 | new JWSHeader.Builder(JWSAlgorithm.ES384). 44 | x509CertURL(URI.create(Base64.getEncoder().encodeToString(keyPair.getPublic().getEncoded()))). 45 | build(), 46 | new Payload(jsonObject) 47 | ); 48 | 49 | EncryptionUtils.signJwt(jwsObject, (ECPrivateKey) keyPair.getPrivate()); 50 | 51 | return jwsObject.serialize(); 52 | } 53 | 54 | public String forgeLoginChain(KeyPair keyPair, LoginData loginData) throws JOSEException { 55 | final long timestamp = System.currentTimeMillis() / 1000; 56 | 57 | final JSONObject extraData = new JSONObject(). 58 | appendField("displayName", loginData.getName()). 59 | appendField("identity", loginData.getUniqueId().toString()). 60 | appendField("XUID", loginData.getXuid()). 61 | appendField("titleId", TITLE_ID_MINECRAFT_PE); 62 | 63 | final JSONObject chainData = new JSONObject(). 64 | appendField("nbf", timestamp - 60 * 60). 65 | appendField("exp", timestamp + 24 * 60 * 60). 66 | appendField("iat", timestamp). 67 | appendField("iss", "self"). 68 | appendField("certificateAuthority", true). 69 | appendField("identityPublicKey", Base64.getEncoder().encodeToString(keyPair.getPublic().getEncoded())). 70 | appendField("extraData", extraData); 71 | 72 | final JSONObject loginChain = new JSONObject(). 73 | appendField("chain", Collections.singletonList(MojangLoginForger.forge(keyPair, chainData))); 74 | 75 | return loginChain.toJSONString(JSONStyle.LT_COMPRESS); 76 | } 77 | 78 | } 79 | -------------------------------------------------------------------------------- /src/main/java/de/kcodeyt/vanilla/generator/client/Network.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 KCodeYT 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package de.kcodeyt.vanilla.generator.client; 18 | 19 | import com.nukkitx.protocol.bedrock.BedrockPacketCodec; 20 | import com.nukkitx.protocol.bedrock.v567.Bedrock_v567; 21 | 22 | /** 23 | * @author Kevims KCodeYT 24 | * @version 1.0-SNAPSHOT 25 | */ 26 | public class Network { 27 | 28 | public static final BedrockPacketCodec CODEC = Bedrock_v567.V567_CODEC; 29 | 30 | } 31 | -------------------------------------------------------------------------------- /src/main/java/de/kcodeyt/vanilla/generator/client/clientdata/DeviceOS.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 KCodeYT 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package de.kcodeyt.vanilla.generator.client.clientdata; 18 | 19 | /** 20 | * @author Kevims KCodeYT 21 | * @version 1.0-SNAPSHOT 22 | */ 23 | @SuppressWarnings("unused") 24 | public enum DeviceOS { 25 | 26 | UNKNOWN, 27 | ANDROID, 28 | IOS, 29 | MAC_OS, 30 | FIRE_OS, 31 | GEAR_VR, 32 | HOLO_LENS, 33 | WINDOWS_10, 34 | WINDOWS, 35 | DEDICATED, 36 | TV_OS, 37 | PLAY_STATION_4, 38 | SWITCH, 39 | XBOX_ONE, 40 | WINDOWS_PHONE, 41 | LINUX 42 | 43 | } 44 | -------------------------------------------------------------------------------- /src/main/java/de/kcodeyt/vanilla/generator/client/clientdata/LoginData.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 KCodeYT 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package de.kcodeyt.vanilla.generator.client.clientdata; 18 | 19 | import com.nimbusds.jose.shaded.json.JSONObject; 20 | import de.kcodeyt.vanilla.generator.client.Network; 21 | import lombok.Value; 22 | 23 | import java.net.InetSocketAddress; 24 | import java.nio.charset.StandardCharsets; 25 | import java.util.*; 26 | 27 | /** 28 | * @author Kevims KCodeYT 29 | * @version 1.0-SNAPSHOT 30 | */ 31 | @Value 32 | public class LoginData { 33 | 34 | String name; 35 | String xuid; 36 | UUID uniqueId; 37 | Skin skin; 38 | DeviceOS deviceOS; 39 | UIProfile uiProfile; 40 | 41 | public JSONObject buildSkinData(Random random, InetSocketAddress serverAddress) { 42 | final UUID deviceId = UUID.randomUUID(); 43 | final Map map = new LinkedHashMap<>(); 44 | map.put("AnimatedImageData", new ArrayList<>()); 45 | map.put("ArmSize", ""); 46 | map.put("CapeData", ""); 47 | map.put("CapeId", ""); 48 | map.put("CapeImageHeight", 0); 49 | map.put("CapeImageWidth", 0); 50 | map.put("CapeOnClassicSkin", false); 51 | map.put("ClientRandomId", random.nextInt()); 52 | map.put("CurrentInputMode", 1); 53 | map.put("DefaultInputMode", 1); 54 | map.put("DeviceId", deviceId.toString()); 55 | map.put("DeviceModel", ""); 56 | map.put("DeviceOS", this.deviceOS.ordinal()); 57 | map.put("GameVersion", Network.CODEC.getMinecraftVersion()); 58 | map.put("GuiScale", 0); 59 | map.put("LanguageCode", "en_US"); 60 | map.put("PersonaPieces", new ArrayList<>()); 61 | map.put("PersonaSkin", false); 62 | map.put("PieceTintColors", new ArrayList<>()); 63 | map.put("PlatformOfflineId", ""); 64 | map.put("PlatformOnlineId", ""); 65 | map.put("PlayFabId", UUID.randomUUID().toString()); 66 | map.put("PremiumSkin", false); 67 | map.put("SelfSignedId", this.uniqueId.toString()); 68 | map.put("ServerAddress", serverAddress.getAddress().getHostAddress() + ":" + serverAddress.getPort()); 69 | map.put("SkinAnimationData", ""); 70 | map.put("SkinColor", "#0"); 71 | map.put("SkinData", new String(Base64.getEncoder().encode(this.skin.getSkinData()))); 72 | map.put("SkinGeometryData", new String(Base64.getEncoder().encode(this.skin.getGeometryData().getBytes(StandardCharsets.UTF_8)))); 73 | map.put("SkinGeometryDataEngineVersion", new String(Base64.getEncoder().encode(this.skin.getGeometryDataEngineVersion().getBytes(StandardCharsets.UTF_8)))); 74 | map.put("SkinId", UUID.randomUUID() + ".Custom" + deviceId); 75 | map.put("SkinImageHeight", this.skin.getImage().getHeight()); 76 | map.put("SkinImageWidth", this.skin.getImage().getWidth()); 77 | map.put("SkinResourcePatch", new String(Base64.getEncoder().encode(("{\"geometry\":{\"default\":\"" + this.skin.getGeometryName() + "\"}}").getBytes()))); 78 | map.put("ThirdPartyName", this.name); 79 | map.put("ThirdPartyNameOnly", false); 80 | map.put("UIProfile", this.uiProfile.ordinal()); 81 | return new JSONObject(map); 82 | } 83 | 84 | } 85 | -------------------------------------------------------------------------------- /src/main/java/de/kcodeyt/vanilla/generator/client/clientdata/Skin.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 KCodeYT 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package de.kcodeyt.vanilla.generator.client.clientdata; 18 | 19 | import lombok.AllArgsConstructor; 20 | import lombok.Getter; 21 | 22 | import java.awt.*; 23 | import java.awt.image.BufferedImage; 24 | import java.io.ByteArrayOutputStream; 25 | 26 | /** 27 | * @author Kevims KCodeYT 28 | * @version 1.0-SNAPSHOT 29 | */ 30 | @Getter 31 | @AllArgsConstructor 32 | public class Skin { 33 | 34 | private final BufferedImage image; 35 | private final String geometryName; 36 | private final String geometryData; 37 | private final String geometryDataEngineVersion; 38 | 39 | public byte[] getSkinData() { 40 | final ByteArrayOutputStream outputStream = new ByteArrayOutputStream(); 41 | for(int y = 0; y < this.image.getHeight(); ++y) { 42 | for(int x = 0; x < this.image.getWidth(); ++x) { 43 | final Color color = new Color(this.image.getRGB(x, y), true); 44 | outputStream.write(color.getRed()); 45 | outputStream.write(color.getGreen()); 46 | outputStream.write(color.getBlue()); 47 | outputStream.write(color.getAlpha()); 48 | } 49 | } 50 | 51 | return outputStream.toByteArray(); 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/de/kcodeyt/vanilla/generator/client/clientdata/UIProfile.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 KCodeYT 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package de.kcodeyt.vanilla.generator.client.clientdata; 18 | 19 | /** 20 | * @author Kevims KCodeYT 21 | * @version 1.0-SNAPSHOT 22 | */ 23 | @SuppressWarnings("unused") 24 | public enum UIProfile { 25 | 26 | CLASSIC, 27 | POCKET 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/de/kcodeyt/vanilla/generator/client/handler/LoginHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 KCodeYT 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package de.kcodeyt.vanilla.generator.client.handler; 18 | 19 | import com.nimbusds.jose.JOSEException; 20 | import com.nimbusds.jwt.SignedJWT; 21 | import com.nukkitx.protocol.bedrock.handler.BedrockPacketHandler; 22 | import com.nukkitx.protocol.bedrock.packet.*; 23 | import com.nukkitx.protocol.bedrock.util.EncryptionUtils; 24 | import de.kcodeyt.vanilla.generator.client.Client; 25 | import de.kcodeyt.vanilla.generator.client.ConnectionState; 26 | import lombok.RequiredArgsConstructor; 27 | 28 | import javax.crypto.SecretKey; 29 | import java.security.InvalidKeyException; 30 | import java.security.NoSuchAlgorithmException; 31 | import java.security.interfaces.ECPublicKey; 32 | import java.security.spec.InvalidKeySpecException; 33 | import java.text.ParseException; 34 | import java.util.Base64; 35 | 36 | /** 37 | * @author Kevims KCodeYT 38 | */ 39 | @RequiredArgsConstructor 40 | public class LoginHandler implements BedrockPacketHandler { 41 | 42 | private final Client client; 43 | 44 | @Override 45 | public boolean handle(DisconnectPacket disconnectPacket) { 46 | this.client.close(); 47 | return true; 48 | } 49 | 50 | @Override 51 | public boolean handle(ServerToClientHandshakePacket serverToClientHandshakePacket) { 52 | try { 53 | final SignedJWT signedJWT = SignedJWT.parse(serverToClientHandshakePacket.getJwt()); 54 | final ECPublicKey serverKey = EncryptionUtils.generateKey(signedJWT.getHeader().getX509CertURL().toASCIIString()); 55 | 56 | if(EncryptionUtils.verifyJwt(signedJWT, serverKey)) { 57 | final SecretKey sharedSecretKey = EncryptionUtils.getSecretKey( 58 | this.client.getKeyPair().getPrivate(), 59 | serverKey, 60 | Base64.getDecoder().decode(signedJWT.getJWTClaimsSet().getStringClaim("salt")) 61 | ); 62 | this.client.getClientSession().enableEncryption(sharedSecretKey); 63 | 64 | this.client.sendPacket(new ClientToServerHandshakePacket()); 65 | 66 | final ClientCacheStatusPacket cacheStatus = new ClientCacheStatusPacket(); 67 | cacheStatus.setSupported(false); 68 | this.client.sendPacket(cacheStatus); 69 | 70 | this.client.setState(ConnectionState.RESOURCE_PACK); 71 | return true; 72 | } 73 | 74 | this.client.close(); 75 | } catch(ParseException | JOSEException | NoSuchAlgorithmException | InvalidKeySpecException | 76 | InvalidKeyException e) { 77 | throw new RuntimeException(e); 78 | } 79 | 80 | return true; 81 | } 82 | 83 | @Override 84 | public boolean handle(PlayStatusPacket playStatusPacket) { 85 | if(playStatusPacket.getStatus() != PlayStatusPacket.Status.LOGIN_SUCCESS) { 86 | this.client.close(); 87 | return true; 88 | } 89 | 90 | return true; 91 | } 92 | 93 | } 94 | -------------------------------------------------------------------------------- /src/main/java/de/kcodeyt/vanilla/generator/client/handler/NetworkHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 KCodeYT 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package de.kcodeyt.vanilla.generator.client.handler; 18 | 19 | import com.nukkitx.protocol.bedrock.handler.BedrockPacketHandler; 20 | import com.nukkitx.protocol.bedrock.packet.DisconnectPacket; 21 | import com.nukkitx.protocol.bedrock.packet.NetworkSettingsPacket; 22 | import de.kcodeyt.vanilla.generator.client.Client; 23 | import de.kcodeyt.vanilla.generator.client.ConnectionState; 24 | import lombok.RequiredArgsConstructor; 25 | 26 | /** 27 | * @author Kevims KCodeYT 28 | */ 29 | @RequiredArgsConstructor 30 | public class NetworkHandler implements BedrockPacketHandler { 31 | 32 | private final Client client; 33 | 34 | @Override 35 | public boolean handle(DisconnectPacket disconnectPacket) { 36 | this.client.close(); 37 | return true; 38 | } 39 | 40 | @Override 41 | public boolean handle(NetworkSettingsPacket networkSettingsPacket) { 42 | this.client.getClientSession().setCompression(networkSettingsPacket.getCompressionAlgorithm()); 43 | this.client.login(); 44 | 45 | this.client.setState(ConnectionState.LOGIN); 46 | return true; 47 | } 48 | 49 | } 50 | -------------------------------------------------------------------------------- /src/main/java/de/kcodeyt/vanilla/generator/client/handler/ResourcePackHandler.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 KCodeYT 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package de.kcodeyt.vanilla.generator.client.handler; 18 | 19 | import cn.nukkit.Server; 20 | import cn.nukkit.level.Location; 21 | import com.nukkitx.protocol.bedrock.data.Ability; 22 | import com.nukkitx.protocol.bedrock.data.AbilityType; 23 | import com.nukkitx.protocol.bedrock.handler.BedrockPacketHandler; 24 | import com.nukkitx.protocol.bedrock.packet.*; 25 | import de.kcodeyt.vanilla.generator.client.Client; 26 | import de.kcodeyt.vanilla.generator.client.ConnectionState; 27 | import lombok.RequiredArgsConstructor; 28 | 29 | /** 30 | * @author Kevims KCodeYT 31 | * @version 1.0-SNAPSHOT 32 | */ 33 | @RequiredArgsConstructor 34 | public class ResourcePackHandler implements BedrockPacketHandler { 35 | 36 | private final Client client; 37 | 38 | @Override 39 | public boolean handle(DisconnectPacket disconnectPacket) { 40 | this.client.close(); 41 | return true; 42 | } 43 | 44 | @Override 45 | public boolean handle(ResourcePacksInfoPacket resourcePacksInfoPacket) { 46 | final ResourcePackClientResponsePacket resourcePackClientResponsePacket = new ResourcePackClientResponsePacket(); 47 | resourcePackClientResponsePacket.setStatus(ResourcePackClientResponsePacket.Status.HAVE_ALL_PACKS); 48 | 49 | this.client.sendPacket(resourcePackClientResponsePacket); 50 | return true; 51 | } 52 | 53 | @Override 54 | public boolean handle(ResourcePackStackPacket resourcePackStackPacket) { 55 | final ResourcePackClientResponsePacket resourcePackClientResponsePacket = new ResourcePackClientResponsePacket(); 56 | resourcePackClientResponsePacket.setStatus(ResourcePackClientResponsePacket.Status.COMPLETED); 57 | this.client.sendPacket(resourcePackClientResponsePacket); 58 | return true; 59 | } 60 | 61 | @Override 62 | public boolean handle(StartGamePacket startGamePacket) { 63 | this.client.setSpawnPosition(new Location(startGamePacket.getDefaultSpawn().getX(), startGamePacket.getDefaultSpawn().getY(), startGamePacket.getDefaultSpawn().getZ())); 64 | this.client.setCurrentDimension(startGamePacket.getDimensionId()); 65 | this.client.setUniqueEntityId(startGamePacket.getUniqueEntityId()); 66 | this.client.setRuntimeEntityId(startGamePacket.getRuntimeEntityId()); 67 | 68 | final RespawnPacket respawnPacket = new RespawnPacket(); 69 | respawnPacket.setPosition(startGamePacket.getPlayerPosition()); 70 | respawnPacket.setState(RespawnPacket.State.CLIENT_READY); 71 | this.client.sendPacket(respawnPacket); 72 | 73 | final RequestChunkRadiusPacket requestChunkRadiusPacket = new RequestChunkRadiusPacket(); 74 | requestChunkRadiusPacket.setRadius(Server.getInstance().getViewDistance()); 75 | this.client.sendPacket(requestChunkRadiusPacket); 76 | return true; 77 | } 78 | 79 | @Override 80 | public boolean handle(PlayStatusPacket playStatusPacket) { 81 | if(playStatusPacket.getStatus() != PlayStatusPacket.Status.PLAYER_SPAWN) return true; 82 | 83 | final SetLocalPlayerAsInitializedPacket setLocalPlayerAsInitializedPacket = new SetLocalPlayerAsInitializedPacket(); 84 | setLocalPlayerAsInitializedPacket.setRuntimeEntityId(this.client.getUniqueEntityId()); 85 | this.client.sendPacket(setLocalPlayerAsInitializedPacket); 86 | 87 | final Location spawnPosition = this.client.getSpawnPosition(); 88 | this.client.move(spawnPosition.x, spawnPosition.y, spawnPosition.z, spawnPosition.yaw, spawnPosition.pitch); 89 | 90 | final RequestAbilityPacket requestAbilityPacket = new RequestAbilityPacket(); 91 | requestAbilityPacket.setType(AbilityType.BOOLEAN); 92 | requestAbilityPacket.setAbility(Ability.FLYING); 93 | requestAbilityPacket.setBoolValue(true); 94 | 95 | this.client.sendPacket(requestAbilityPacket); 96 | 97 | final Location currentPosition = this.client.getCurrentPosition(); 98 | this.client.move(currentPosition.getX(), 255, currentPosition.getZ(), 0, 0); 99 | this.client.checkReadyState(); 100 | 101 | this.client.setState(ConnectionState.PLAYING); 102 | return true; 103 | } 104 | 105 | } 106 | -------------------------------------------------------------------------------- /src/main/java/de/kcodeyt/vanilla/generator/server/ProcessWrapper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 KCodeYT 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package de.kcodeyt.vanilla.generator.server; 18 | 19 | import java.io.BufferedReader; 20 | import java.io.IOException; 21 | import java.io.InputStreamReader; 22 | import java.util.function.Consumer; 23 | 24 | /** 25 | * @author Kevims KCodeYT 26 | * @version 1.0-SNAPSHOT 27 | */ 28 | public class ProcessWrapper { 29 | 30 | private final Process process; 31 | 32 | ProcessWrapper(ProcessBuilder builder, Consumer stdoutConsumer) throws IOException { 33 | this.process = builder.start(); 34 | final Thread stdReader = new Thread(() -> { 35 | try(final BufferedReader reader = new BufferedReader(new InputStreamReader(this.process.getInputStream()))) { 36 | String line; 37 | while((line = reader.readLine()) != null) stdoutConsumer.accept(line); 38 | } catch(Exception ignored) { 39 | } 40 | }); 41 | stdReader.setDaemon(true); 42 | stdReader.start(); 43 | 44 | Runtime.getRuntime().addShutdownHook(new Thread(() -> { 45 | if(ProcessWrapper.this.isAlive()) 46 | kill(); 47 | })); 48 | } 49 | 50 | private boolean isAlive() { 51 | return this.process.isAlive(); 52 | } 53 | 54 | public void kill() { 55 | this.process.destroyForcibly(); 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/de/kcodeyt/vanilla/generator/server/VanillaServer.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 KCodeYT 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package de.kcodeyt.vanilla.generator.server; 18 | 19 | import cn.nukkit.level.Level; 20 | import cn.nukkit.level.format.generic.BaseFullChunk; 21 | import de.kcodeyt.vanilla.VanillaGeneratorPlugin; 22 | import de.kcodeyt.vanilla.behavior.LootTableManager; 23 | import de.kcodeyt.vanilla.generator.chunk.ChunkRequest; 24 | import de.kcodeyt.vanilla.generator.client.Client; 25 | import de.kcodeyt.vanilla.generator.client.clientdata.DeviceOS; 26 | import de.kcodeyt.vanilla.generator.client.clientdata.LoginData; 27 | import de.kcodeyt.vanilla.generator.client.clientdata.UIProfile; 28 | import de.kcodeyt.vanilla.world.World; 29 | import lombok.Getter; 30 | import org.apache.commons.lang3.SystemUtils; 31 | 32 | import java.io.File; 33 | import java.io.IOException; 34 | import java.net.DatagramSocket; 35 | import java.net.InetSocketAddress; 36 | import java.net.SocketException; 37 | import java.util.List; 38 | import java.util.Queue; 39 | import java.util.UUID; 40 | import java.util.concurrent.*; 41 | import java.util.concurrent.atomic.AtomicBoolean; 42 | 43 | /** 44 | * @author Kevims KCodeYT 45 | * @version 1.0-SNAPSHOT 46 | */ 47 | public class VanillaServer { 48 | 49 | @Getter 50 | private final long startupTime; 51 | @Getter 52 | private final World world; 53 | private final Queue queue = new ConcurrentLinkedQueue<>(); 54 | private final List clients = new CopyOnWriteArrayList<>(); 55 | private final AtomicBoolean manualClose = new AtomicBoolean(false); 56 | private final int port; 57 | 58 | private ProcessWrapper processWrapper; 59 | @Getter 60 | private LootTableManager lootTableManager; 61 | 62 | private boolean firstSeen = true; 63 | 64 | public VanillaServer(World world) { 65 | this.startupTime = System.currentTimeMillis(); 66 | this.world = world; 67 | this.port = findFreePort(); 68 | 69 | final File tempServer = BedrockDedicatedServer.createTempServer(this.world, this.port); 70 | if(tempServer == null) return; 71 | 72 | final String tempPath = tempServer.getAbsolutePath() + File.separator; 73 | final ProcessBuilder builder = new ProcessBuilder((SystemUtils.IS_OS_WINDOWS ? tempPath + "bedrock_server.exe" : tempPath + "start.sh")); 74 | builder.directory(tempServer); 75 | 76 | this.lootTableManager = new LootTableManager(); 77 | final File behaviorPacksDir = new File(tempServer, "behavior_packs"); 78 | if(behaviorPacksDir.exists() && behaviorPacksDir.isDirectory()) 79 | this.lootTableManager.loadPacks(behaviorPacksDir); 80 | 81 | try { 82 | final long startTime = System.currentTimeMillis(); 83 | this.processWrapper = new ProcessWrapper(builder, line -> { 84 | if(line.contains("Server started.") && this.firstSeen) { 85 | VanillaGeneratorPlugin.getInstance().getLogger().info("Server " + this.world.getWorldName() + " bound to " + this.port + " (Started in " + (Math.round(((System.currentTimeMillis() - startTime) / 1000f) * 100) / 100f) + "s!)"); 86 | this.firstSeen = false; 87 | 88 | this.connect(); 89 | } 90 | }); 91 | } catch(IOException e) { 92 | VanillaGeneratorPlugin.getInstance().getLogger().error("Could not start BDS", e); 93 | } 94 | } 95 | 96 | private void connect() { 97 | for(int i = 0; i < VanillaGeneratorPlugin.getInstance().getFakePlayersPerGenerator(); i++) 98 | this.world.getPlugin() 99 | .getExecutorService() 100 | .schedule(this::connectClient, (i + 1) * 2000L, TimeUnit.MILLISECONDS); 101 | } 102 | 103 | public Client getClient() { 104 | return this.clients.isEmpty() ? null : this.clients.get(0); 105 | } 106 | 107 | private LoginData generateLoginData() { 108 | return new LoginData( 109 | "GenBot_" + (this.clients.size() + 1), 110 | Long.toString(ThreadLocalRandom.current().nextLong()), 111 | UUID.randomUUID(), 112 | VanillaGeneratorPlugin.STEVE_SKIN, 113 | DeviceOS.DEDICATED, 114 | UIProfile.CLASSIC 115 | ); 116 | } 117 | 118 | private void connectClient() { 119 | final LoginData loginData = this.generateLoginData(); 120 | final Client client = new Client(this, loginData, this.queue); 121 | this.clients.add(client.onDisconnect(reason -> { 122 | final ChunkRequest chunkRequest = client.getCurrent(); 123 | if(chunkRequest != null) this.queue.offer(chunkRequest); 124 | 125 | this.clients.remove(client); 126 | if(this.manualClose.get()) return; 127 | 128 | this.world.getPlugin().getExecutorService().schedule(this::connectClient, 500, TimeUnit.MILLISECONDS); 129 | }).connect(new InetSocketAddress(VanillaGeneratorPlugin.getInstance().getLocalIpAddress(), this.port)).join()); 130 | } 131 | 132 | public void requestChunk(BaseFullChunk fullChunk) { 133 | final ChunkRequest request = new ChunkRequest(fullChunk.getX(), fullChunk.getZ(), new CompletableFuture<>()); 134 | this.queue.offer(request); 135 | 136 | try { 137 | request.getFuture().join().build(this, fullChunk); 138 | } catch(Exception e) { 139 | this.world.getPlugin().getLogger().error("Error whilst generating chunk [" + fullChunk.getX() + "," + fullChunk.getZ() + "]", e); 140 | } 141 | } 142 | 143 | public boolean isLevel(Level level) { 144 | return this.world.getLevel().equals(level); 145 | } 146 | 147 | public void close() { 148 | this.manualClose.set(true); 149 | for(Client client : this.clients) client.close(); 150 | this.processWrapper.kill(); 151 | } 152 | 153 | private static int findFreePort() { 154 | try(final DatagramSocket datagramSocket = new DatagramSocket()) { 155 | return datagramSocket.getLocalPort(); 156 | } catch(SocketException e) { 157 | throw new RuntimeException(e); 158 | } 159 | } 160 | 161 | } 162 | -------------------------------------------------------------------------------- /src/main/java/de/kcodeyt/vanilla/util/GameVersion.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 KCodeYT 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package de.kcodeyt.vanilla.util; 18 | 19 | import lombok.Value; 20 | 21 | /** 22 | * @author Kevims KCodeYT 23 | * @version 1.0-SNAPSHOT 24 | */ 25 | @Value 26 | public class GameVersion { 27 | 28 | public static final GameVersion NULL_VERSION = new GameVersion(0, 0, 0, 0, "0.0.0.0"); 29 | 30 | int major, minor, patch, build; 31 | String versionString; 32 | 33 | public static GameVersion of(String version) { 34 | final String[] split = version.split("\\."); 35 | 36 | try { 37 | final int major, minor, patch, build; 38 | if(split.length == 0) 39 | throw new UnsupportedOperationException("Could not parse major of version: " + version); 40 | major = Integer.parseInt(split[0]); 41 | 42 | if(split.length == 1) 43 | throw new UnsupportedOperationException("Could not parse minor of version: " + version); 44 | minor = Integer.parseInt(split[1]); 45 | 46 | if(split.length == 2) 47 | throw new UnsupportedOperationException("Could not parse patch of version: " + version); 48 | patch = Integer.parseInt(split[2]); 49 | 50 | if(split.length == 3) build = 0; 51 | else build = Integer.parseInt(split[3]); 52 | 53 | return new GameVersion(major, minor, patch, build, version); 54 | } catch(NumberFormatException e) { 55 | throw new UnsupportedOperationException("Could not parse version: " + version); 56 | } 57 | } 58 | 59 | @Override 60 | public String toString() { 61 | return this.versionString; 62 | } 63 | 64 | public boolean isOlderThan(GameVersion other) { 65 | if(this.major < other.major) return true; 66 | if(this.major > other.major) return false; 67 | 68 | if(this.minor < other.minor) return true; 69 | if(this.minor > other.minor) return false; 70 | 71 | if(this.patch < other.patch) return true; 72 | if(this.patch > other.patch) return false; 73 | 74 | return this.build < other.build; 75 | } 76 | 77 | } 78 | -------------------------------------------------------------------------------- /src/main/java/de/kcodeyt/vanilla/util/ItemIdentifier.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 KCodeYT 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package de.kcodeyt.vanilla.util; 18 | 19 | import cn.nukkit.item.Item; 20 | import com.google.gson.Gson; 21 | 22 | import java.util.LinkedHashMap; 23 | import java.util.Map; 24 | 25 | /** 26 | * @author Kevims KCodeYT 27 | * @version 1.0-SNAPSHOT 28 | */ 29 | public class ItemIdentifier { 30 | 31 | private static final String RUNTIME_ITEM_STATES_URL = "https://raw.githubusercontent.com/CloudburstMC/Data/master/legacy_item_ids.json"; 32 | private static final Map RUNTIME_ITEM_MAP = new LinkedHashMap<>(); 33 | 34 | static { 35 | (new Gson()).>fromJson(WebRequest.request(RUNTIME_ITEM_STATES_URL), Map.class). 36 | forEach((key, value) -> RUNTIME_ITEM_MAP.put(key, (int) (double) value)); 37 | } 38 | 39 | public static int getItemId(String itemName) { 40 | final String name = itemName.contains(":") ? itemName : "minecraft:" + itemName; 41 | final int itemId = Item.fromString(name).getId(); 42 | if(itemId == Item.AIR) return RUNTIME_ITEM_MAP.getOrDefault(name, Item.AIR); 43 | return itemId; 44 | } 45 | 46 | } -------------------------------------------------------------------------------- /src/main/java/de/kcodeyt/vanilla/util/NbtConverter.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 KCodeYT 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package de.kcodeyt.vanilla.util; 18 | 19 | import cn.nukkit.nbt.tag.*; 20 | import com.nukkitx.nbt.NbtList; 21 | import com.nukkitx.nbt.NbtMap; 22 | import com.nukkitx.nbt.NbtType; 23 | 24 | import java.util.Objects; 25 | import java.util.stream.Collectors; 26 | 27 | /** 28 | * @author Kevims KCodeYT 29 | * @version 1.0-SNAPSHOT 30 | */ 31 | public class NbtConverter { 32 | 33 | public static CompoundTag convert(NbtMap nbtMap) { 34 | return convert(null, nbtMap); 35 | } 36 | 37 | public static CompoundTag convert(String baseName, NbtMap nbtMap) { 38 | final CompoundTag baseTag = new CompoundTag(baseName == null ? "" : baseName); 39 | for(String tagName : nbtMap.keySet()) { 40 | final Object value = nbtMap.get(tagName); 41 | final Tag newTag; 42 | if(value != null && ((newTag = convertTag(tagName, value)) != null)) 43 | baseTag.put(tagName, newTag); 44 | } 45 | return baseTag; 46 | } 47 | 48 | private static Tag convertTag(String name, Object value) { 49 | final Class clazz = value.getClass(); 50 | return switch(NbtType.byClass(clazz).getEnum()) { 51 | case BYTE -> new ByteTag(name, (byte) value); 52 | case SHORT -> new ShortTag(name, (short) value); 53 | case INT -> new IntTag(name, (int) value); 54 | case LONG -> new LongTag(name, (long) value); 55 | case FLOAT -> new FloatTag(name, (float) value); 56 | case DOUBLE -> new DoubleTag(name, (double) value); 57 | case BYTE_ARRAY -> new ByteArrayTag(name, (byte[]) value); 58 | case STRING -> new StringTag(name, (String) value); 59 | case LIST -> convertList(name, (NbtList) value); 60 | case COMPOUND -> convert(name, (NbtMap) value); 61 | case INT_ARRAY -> new IntArrayTag(name, (int[]) value); 62 | default -> null; 63 | }; 64 | } 65 | 66 | private static ListTag convertList(String name, NbtList list) { 67 | final ListTag listTag = new ListTag<>(name); 68 | listTag.setAll(list.stream().map(o -> convertTag("", o)).filter(Objects::nonNull).collect(Collectors.toList())); 69 | return listTag; 70 | } 71 | 72 | } 73 | -------------------------------------------------------------------------------- /src/main/java/de/kcodeyt/vanilla/util/Palette.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 KCodeYT 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package de.kcodeyt.vanilla.util; 18 | 19 | import cn.nukkit.utils.BinaryStream; 20 | 21 | import java.util.HashMap; 22 | import java.util.Map; 23 | 24 | /** 25 | * @author Kevims KCodeYT 26 | * @version 1.0-SNAPSHOT 27 | */ 28 | public class Palette { 29 | 30 | public static final int SIZE = 4096; 31 | private static final Map WORDS_MAP = new HashMap<>(); 32 | 33 | static { 34 | WORDS_MAP.put(0, 0); 35 | WORDS_MAP.put(1, 32); 36 | WORDS_MAP.put(2, 16); 37 | WORDS_MAP.put(3, 10); 38 | WORDS_MAP.put(4, 8); 39 | WORDS_MAP.put(5, 6); 40 | WORDS_MAP.put(6, 5); 41 | WORDS_MAP.put(8, 4); 42 | WORDS_MAP.put(16, 2); 43 | } 44 | 45 | public static short[] parseIndices(BinaryStream binaryStream, int version) { 46 | final short[] indices = new short[SIZE]; 47 | final int words = WORDS_MAP.get(version); 48 | final int iterations = SimpleMath.ceil(SIZE / (float) words); 49 | for(int i = 0; i < iterations; i++) { 50 | final int data = binaryStream.getLInt(); 51 | int rIndex = 0; 52 | 53 | for(byte w = 0; w < words; w++) { 54 | short val = 0; 55 | 56 | for(byte v = 0; v < version; v++) { 57 | if((data & (1 << rIndex++)) != 0) 58 | val ^= 1 << v; 59 | } 60 | 61 | final int index = (i * words) + w; 62 | if(index < SIZE) 63 | indices[index] = val; 64 | } 65 | } 66 | 67 | return indices; 68 | } 69 | 70 | } 71 | -------------------------------------------------------------------------------- /src/main/java/de/kcodeyt/vanilla/util/SimpleMath.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 KCodeYT 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package de.kcodeyt.vanilla.util; 18 | 19 | import lombok.experimental.UtilityClass; 20 | 21 | @UtilityClass 22 | public class SimpleMath { 23 | 24 | public int ceil(float floatNumber) { 25 | final int truncated = (int) floatNumber; 26 | return floatNumber > truncated ? truncated + 1 : truncated; 27 | } 28 | 29 | } 30 | -------------------------------------------------------------------------------- /src/main/java/de/kcodeyt/vanilla/util/WebRequest.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 KCodeYT 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package de.kcodeyt.vanilla.util; 18 | 19 | import java.io.BufferedReader; 20 | import java.io.InputStreamReader; 21 | import java.net.HttpURLConnection; 22 | import java.net.URL; 23 | 24 | /** 25 | * @author Kevims KCodeYT 26 | * @version 1.0-SNAPSHOT 27 | */ 28 | public class WebRequest { 29 | 30 | public static String request(String urlString) { 31 | try { 32 | final HttpURLConnection httpConnection = (HttpURLConnection) new URL(urlString).openConnection(); 33 | httpConnection.setRequestProperty("User-Agent", "Chrome"); 34 | final BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(httpConnection.getInputStream())); 35 | final StringBuilder resultLine = new StringBuilder(); 36 | String line; 37 | while((line = bufferedReader.readLine()) != null) 38 | resultLine.append(line).append("\n"); 39 | bufferedReader.close(); 40 | httpConnection.disconnect(); 41 | return resultLine.toString(); 42 | } catch(Throwable throwable) { 43 | return "{}"; 44 | } 45 | } 46 | 47 | } 48 | -------------------------------------------------------------------------------- /src/main/java/de/kcodeyt/vanilla/util/WeightedRandom.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 KCodeYT 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package de.kcodeyt.vanilla.util; 18 | 19 | import lombok.AllArgsConstructor; 20 | import lombok.EqualsAndHashCode; 21 | import lombok.Getter; 22 | 23 | import java.util.List; 24 | import java.util.Random; 25 | 26 | /** 27 | * @author Kevims KCodeYT 28 | * @version 1.0-SNAPSHOT 29 | */ 30 | public class WeightedRandom { 31 | 32 | private static int getTotalWeight(List weightedList) { 33 | return weightedList.stream().mapToInt(Item::getWeight).sum(); 34 | } 35 | 36 | private static T getRandomItem(Random random, List weightedList, int totalWeight) { 37 | return totalWeight <= 0 ? null : getRandomItem(weightedList, random.nextInt(totalWeight)); 38 | } 39 | 40 | private static T getRandomItem(List weightedList, int weight) { 41 | int i = 0; 42 | for(int j = weightedList.size(); i < j; ++i) { 43 | final T weightItem = weightedList.get(i); 44 | weight -= weightItem.weight; 45 | if(weight < 0) 46 | return weightItem; 47 | } 48 | 49 | return null; 50 | } 51 | 52 | public static T getRandomItem(Random random, List weightedList) { 53 | return getRandomItem(random, weightedList, getTotalWeight(weightedList)); 54 | } 55 | 56 | @Getter 57 | @EqualsAndHashCode 58 | @AllArgsConstructor 59 | public static class Item { 60 | final int weight; 61 | } 62 | 63 | } 64 | -------------------------------------------------------------------------------- /src/main/java/de/kcodeyt/vanilla/util/ZipHelper.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 KCodeYT 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package de.kcodeyt.vanilla.util; 18 | 19 | import lombok.experimental.UtilityClass; 20 | 21 | import java.io.File; 22 | import java.io.FileInputStream; 23 | import java.io.FileOutputStream; 24 | import java.io.IOException; 25 | import java.util.zip.ZipEntry; 26 | import java.util.zip.ZipInputStream; 27 | 28 | /** 29 | * @author Kevims KCodeYT 30 | * @version 1.0-SNAPSHOT 31 | */ 32 | @UtilityClass 33 | public class ZipHelper { 34 | 35 | public void unzip(File fileZip, File destDir) throws IOException { 36 | if(!destDir.exists() && !destDir.mkdirs()) return; 37 | 38 | try(final ZipInputStream inputStream = new ZipInputStream(new FileInputStream(fileZip))) { 39 | ZipEntry zipEntry; 40 | while((zipEntry = inputStream.getNextEntry()) != null) { 41 | final File newFile = newFile(destDir, zipEntry); 42 | if(zipEntry.isDirectory()) { 43 | if(!newFile.mkdirs()) { 44 | inputStream.closeEntry(); 45 | return; 46 | } 47 | } else { 48 | try(final FileOutputStream outputStream = new FileOutputStream(newFile)) { 49 | inputStream.transferTo(outputStream); 50 | } 51 | } 52 | } 53 | 54 | inputStream.closeEntry(); 55 | } 56 | } 57 | 58 | private File newFile(File destinationDir, ZipEntry zipEntry) throws IOException { 59 | final File destFile = new File(destinationDir, zipEntry.getName()); 60 | final String destDirPath = destinationDir.getCanonicalPath(); 61 | final String destFilePath = destFile.getCanonicalPath(); 62 | if(!destFilePath.startsWith(destDirPath + File.separator)) 63 | throw new IOException("Entry is outside of the target dir: " + zipEntry.getName()); 64 | return destFile; 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/de/kcodeyt/vanilla/world/BlockEntityData.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 KCodeYT 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package de.kcodeyt.vanilla.world; 18 | 19 | import cn.nukkit.blockentity.BlockEntity; 20 | import cn.nukkit.level.Level; 21 | import cn.nukkit.level.Position; 22 | import cn.nukkit.level.format.FullChunk; 23 | import cn.nukkit.nbt.tag.CompoundTag; 24 | import com.nukkitx.math.vector.Vector3i; 25 | import com.nukkitx.protocol.bedrock.packet.BlockEntityDataPacket; 26 | import de.kcodeyt.vanilla.generator.chunk.ChunkWaiter; 27 | import de.kcodeyt.vanilla.generator.server.VanillaServer; 28 | import de.kcodeyt.vanilla.util.NbtConverter; 29 | import de.kcodeyt.vanilla.world.blockentity.*; 30 | 31 | import java.util.HashMap; 32 | import java.util.Map; 33 | 34 | /** 35 | * @author Kevims KCodeYT 36 | * @version 1.0-SNAPSHOT 37 | */ 38 | public class BlockEntityData { 39 | 40 | private static final BasicCreator BASIC_CREATOR = new BasicCreator(); 41 | private static final Map CREATOR_MAP = new HashMap<>(); 42 | 43 | static { 44 | CREATOR_MAP.put(BlockEntity.BREWING_STAND, new BrewingStandCreator()); 45 | CREATOR_MAP.put(BlockEntity.ITEM_FRAME, new ItemFrameCreator()); 46 | CREATOR_MAP.put(BlockEntity.BEEHIVE, new BeehiveCreator()); 47 | CREATOR_MAP.put(BlockEntity.LECTERN, new LecternCreator()); 48 | CREATOR_MAP.put(BlockEntity.FURNACE, new BasicFurnaceCreator()); 49 | CREATOR_MAP.put(BlockEntity.SMOKER, new BasicFurnaceCreator()); 50 | CREATOR_MAP.put(BlockEntity.BLAST_FURNACE, new BasicFurnaceCreator()); 51 | CREATOR_MAP.put(BlockEntity.CHEST, new ChestCreator()); 52 | CREATOR_MAP.put(BlockEntity.MOB_SPAWNER, new MobSpawnerCreator()); 53 | } 54 | 55 | public static void direct(VanillaServer vanillaServer, FullChunk fullChunk, CompoundTag baseTag) { 56 | CREATOR_MAP.getOrDefault(baseTag.getString("id"), BASIC_CREATOR).createBlockEntity(vanillaServer, fullChunk, baseTag); 57 | } 58 | 59 | public static void from(VanillaServer vanillaServer, Level level, CompoundTag baseTag) { 60 | if(!baseTag.containsString("id")) return; 61 | 62 | ChunkWaiter.waitFor(new Position(baseTag.getInt("x"), baseTag.getInt("y"), baseTag.getInt("z"), level), 63 | fullChunk -> BlockEntityData.direct(vanillaServer, fullChunk, baseTag)); 64 | } 65 | 66 | public static void from(VanillaServer vanillaServer, Level level, BlockEntityDataPacket dataPacket) { 67 | final CompoundTag compoundTag = NbtConverter.convert(dataPacket.getData()); 68 | if(!compoundTag.containsString("id")) return; 69 | 70 | final Vector3i blockPos = dataPacket.getBlockPosition(); 71 | ChunkWaiter.waitFor(new Position(blockPos.getX(), blockPos.getY(), blockPos.getZ(), level), 72 | fullChunk -> BlockEntityData.direct(vanillaServer, fullChunk, compoundTag)); 73 | } 74 | 75 | } 76 | -------------------------------------------------------------------------------- /src/main/java/de/kcodeyt/vanilla/world/World.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 KCodeYT 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package de.kcodeyt.vanilla.world; 18 | 19 | import cn.nukkit.level.Level; 20 | import de.kcodeyt.vanilla.VanillaGeneratorPlugin; 21 | import lombok.AllArgsConstructor; 22 | import lombok.Getter; 23 | 24 | /** 25 | * @author Kevims KCodeYT 26 | * @version 1.0-SNAPSHOT 27 | */ 28 | @Getter 29 | @AllArgsConstructor 30 | public class World { 31 | 32 | private final VanillaGeneratorPlugin plugin; 33 | private final Level level; 34 | private final int dimension; 35 | private final int minY; 36 | private final int maxY; 37 | 38 | public String getWorldName() { 39 | return this.level.getName(); 40 | } 41 | 42 | public long getSeed() { 43 | return this.level.getSeed(); 44 | } 45 | 46 | } -------------------------------------------------------------------------------- /src/main/java/de/kcodeyt/vanilla/world/blockentity/BasicCreator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 KCodeYT 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package de.kcodeyt.vanilla.world.blockentity; 18 | 19 | import cn.nukkit.blockentity.BlockEntity; 20 | import cn.nukkit.level.format.FullChunk; 21 | import cn.nukkit.nbt.tag.CompoundTag; 22 | import de.kcodeyt.vanilla.generator.server.VanillaServer; 23 | 24 | /** 25 | * @author Kevims KCodeYT 26 | * @version 1.0-SNAPSHOT 27 | */ 28 | public class BasicCreator implements BlockEntityCreator { 29 | 30 | @Override 31 | public void createBlockEntity(VanillaServer generator, FullChunk fullChunk, CompoundTag baseTag) { 32 | try { 33 | BlockEntity.createBlockEntity(baseTag.getString("id"), fullChunk, baseTag); 34 | } catch(Exception ignored) { 35 | } 36 | } 37 | 38 | } 39 | -------------------------------------------------------------------------------- /src/main/java/de/kcodeyt/vanilla/world/blockentity/BasicFurnaceCreator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 KCodeYT 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package de.kcodeyt.vanilla.world.blockentity; 18 | 19 | import cn.nukkit.blockentity.BlockEntity; 20 | import cn.nukkit.item.Item; 21 | import cn.nukkit.level.format.FullChunk; 22 | import cn.nukkit.nbt.NBTIO; 23 | import cn.nukkit.nbt.tag.CompoundTag; 24 | import cn.nukkit.nbt.tag.ListTag; 25 | import de.kcodeyt.vanilla.generator.server.VanillaServer; 26 | 27 | /** 28 | * @author Kevims KCodeYT 29 | * @version 1.0-SNAPSHOT 30 | */ 31 | public class BasicFurnaceCreator implements BlockEntityCreator { 32 | 33 | @Override 34 | public void createBlockEntity(VanillaServer generator, FullChunk fullChunk, CompoundTag baseTag) { 35 | final short cookTime = (short) (baseTag.containsShort("CookTime") ? baseTag.getShort("CookTime") : 0); 36 | final short burnTime = (short) (baseTag.containsShort("BurnTime") ? baseTag.getShort("BurnTime") : 0); 37 | final short burnDuration = (short) (baseTag.containsShort("BurnDuration") ? baseTag.getShort("BurnDuration") : 0); 38 | final int storedXPInt = baseTag.containsInt("StoredXPInt") ? baseTag.getInt("StoredXPInt") : 0; 39 | final ListTag itemsTag = baseTag.containsList("Items") ? this.rewriteItemsTag(baseTag.getList("Items", CompoundTag.class)) : new ListTag<>("Items"); 40 | BlockEntity.createBlockEntity(baseTag.getString("id"), fullChunk, 41 | this.createBaseBlockEntityTag(baseTag) 42 | .putShort("CookTime", cookTime) 43 | .putShort("BurnTime", burnTime) 44 | .putShort("BurnDuration", burnDuration) 45 | .putInt("StoredXPInt", storedXPInt) 46 | .putList(itemsTag) 47 | ); 48 | } 49 | 50 | private ListTag rewriteItemsTag(ListTag items) { 51 | final ListTag itemsTag = new ListTag<>("Items"); 52 | for(int i = 0; i < 3; i++) 53 | itemsTag.add(new CompoundTag()); 54 | for(CompoundTag itemTag : items.getAll()) { 55 | final Item item = this.createItem(itemTag); 56 | if(item == null || item.getId() == Item.AIR) 57 | continue; 58 | final byte slot = (byte) (itemTag.containsByte("Slot") ? itemTag.getByte("Slot") : -1); 59 | if(slot == -1) 60 | itemsTag.add(NBTIO.putItemHelper(item)); 61 | else 62 | itemsTag.add(slot, NBTIO.putItemHelper(item, (int) slot)); 63 | } 64 | return itemsTag; 65 | } 66 | 67 | } 68 | -------------------------------------------------------------------------------- /src/main/java/de/kcodeyt/vanilla/world/blockentity/BeehiveCreator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 KCodeYT 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package de.kcodeyt.vanilla.world.blockentity; 18 | 19 | import cn.nukkit.blockentity.BlockEntity; 20 | import cn.nukkit.level.format.FullChunk; 21 | import cn.nukkit.nbt.tag.CompoundTag; 22 | import cn.nukkit.nbt.tag.ListTag; 23 | import de.kcodeyt.vanilla.generator.server.VanillaServer; 24 | 25 | /** 26 | * @author Kevims KCodeYT 27 | * @version 1.0-SNAPSHOT 28 | */ 29 | public class BeehiveCreator implements BlockEntityCreator { 30 | 31 | @Override 32 | public void createBlockEntity(VanillaServer generator, FullChunk fullChunk, CompoundTag baseTag) { 33 | final byte shouldSpawnBees = (byte) (baseTag.containsByte("ShouldSpawnBees") ? baseTag.getByte("ShouldSpawnBees") : 1); 34 | final ListTag occupantsTag = baseTag.containsList("Occupants", CompoundTag.TAG_Compound) ? 35 | this.rewriteOccupants(baseTag.getList("Occupants", CompoundTag.class)) : new ListTag<>("Occupants"); 36 | BlockEntity.createBlockEntity(BlockEntity.BEEHIVE, fullChunk, 37 | this.createBaseBlockEntityTag(baseTag) 38 | .putByte("ShouldSpawnBees", shouldSpawnBees) 39 | .putList(occupantsTag) 40 | ); 41 | } 42 | 43 | private ListTag rewriteOccupants(ListTag occupantsTag) { 44 | final ListTag newOccupantsTag = new ListTag<>("Occupants"); 45 | for(int i = 0; i < occupantsTag.size(); i++) { 46 | final CompoundTag occupantTag = occupantsTag.get(i); 47 | if(occupantTag == null) 48 | continue; 49 | newOccupantsTag.add(occupantTag.putString("ActorIdentifier", this.validIdentifier(occupantTag.getString("ActorIdentifier")))); 50 | } 51 | return newOccupantsTag; 52 | } 53 | 54 | private String validIdentifier(String actorIdentifier) { 55 | return actorIdentifier.contains("<") ? actorIdentifier.substring(0, actorIdentifier.indexOf("<")) : actorIdentifier; 56 | } 57 | 58 | } 59 | -------------------------------------------------------------------------------- /src/main/java/de/kcodeyt/vanilla/world/blockentity/BlockEntityCreator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 KCodeYT 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package de.kcodeyt.vanilla.world.blockentity; 18 | 19 | import cn.nukkit.item.Item; 20 | import cn.nukkit.level.format.FullChunk; 21 | import cn.nukkit.nbt.tag.CompoundTag; 22 | import de.kcodeyt.vanilla.generator.server.VanillaServer; 23 | import de.kcodeyt.vanilla.util.ItemIdentifier; 24 | 25 | /** 26 | * @author Kevims KCodeYT 27 | * @version 1.0-SNAPSHOT 28 | */ 29 | public interface BlockEntityCreator { 30 | 31 | void createBlockEntity(VanillaServer generator, FullChunk fullChunk, CompoundTag baseTag); 32 | 33 | default CompoundTag createBaseBlockEntityTag(CompoundTag baseTag) { 34 | return new CompoundTag() 35 | .putString("id", baseTag.getString("id")) 36 | .putByte("isMovable", baseTag.getByte("isMovable")) 37 | .putInt("x", baseTag.getInt("x")) 38 | .putInt("y", baseTag.getInt("y")) 39 | .putInt("z", baseTag.getInt("z")); 40 | } 41 | 42 | default Item createItem(CompoundTag itemTag) { 43 | final int itemId = ItemIdentifier.getItemId(itemTag.getString("Name")); 44 | if(itemId == Item.AIR) return null; 45 | 46 | final Item item = Item.get(itemId); 47 | item.setDamage(itemTag.containsShort("Damage") ? itemTag.getShort("Damage") : 0); 48 | item.setCount(itemTag.containsByte("Count") ? itemTag.getByte("Count") : 0); 49 | if(itemTag.containsCompound("tag")) 50 | item.setNamedTag(itemTag.getCompound("tag")); 51 | return item; 52 | } 53 | 54 | } 55 | -------------------------------------------------------------------------------- /src/main/java/de/kcodeyt/vanilla/world/blockentity/BrewingStandCreator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 KCodeYT 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package de.kcodeyt.vanilla.world.blockentity; 18 | 19 | import cn.nukkit.blockentity.BlockEntity; 20 | import cn.nukkit.item.Item; 21 | import cn.nukkit.level.format.FullChunk; 22 | import cn.nukkit.nbt.NBTIO; 23 | import cn.nukkit.nbt.tag.CompoundTag; 24 | import cn.nukkit.nbt.tag.ListTag; 25 | import de.kcodeyt.vanilla.generator.server.VanillaServer; 26 | 27 | /** 28 | * @author Kevims KCodeYT 29 | * @version 1.0-SNAPSHOT 30 | */ 31 | public class BrewingStandCreator implements BlockEntityCreator { 32 | 33 | @Override 34 | public void createBlockEntity(VanillaServer generator, FullChunk fullChunk, CompoundTag baseTag) { 35 | final short cookTime = (short) (baseTag.containsShort("CookTime") ? baseTag.getShort("CookTime") : 0); 36 | final short fuelTotal = (short) (baseTag.containsShort("FuelTotal") ? baseTag.getShort("FuelTotal") : 0); 37 | final short fuelAmount = (short) (baseTag.containsShort("FuelAmount") ? baseTag.getShort("FuelAmount") : 0); 38 | final ListTag itemsTag = baseTag.containsList("Items") ? this.rewriteItemsTag(baseTag.getList("Items", CompoundTag.class)) : new ListTag<>("Items"); 39 | BlockEntity.createBlockEntity(BlockEntity.BREWING_STAND, fullChunk, 40 | this.createBaseBlockEntityTag(baseTag) 41 | .putShort("CookTime", cookTime) 42 | .putShort("FuelTotal", fuelTotal) 43 | .putShort("FuelAmount", fuelAmount) 44 | .putList(itemsTag) 45 | ); 46 | } 47 | 48 | private ListTag rewriteItemsTag(ListTag items) { 49 | final ListTag itemsTag = new ListTag<>("Items"); 50 | for(int i = 0; i < 5; i++) 51 | itemsTag.add(new CompoundTag()); 52 | for(CompoundTag itemTag : items.getAll()) { 53 | final Item item = this.createItem(itemTag); 54 | if(item == null || item.getId() == Item.AIR) 55 | continue; 56 | final byte slot = (byte) (itemTag.containsByte("Slot") ? itemTag.getByte("Slot") : -1); 57 | if(slot == -1) 58 | itemsTag.add(NBTIO.putItemHelper(item)); 59 | else 60 | itemsTag.add(slot, NBTIO.putItemHelper(item, (int) slot)); 61 | } 62 | return itemsTag; 63 | } 64 | 65 | } 66 | -------------------------------------------------------------------------------- /src/main/java/de/kcodeyt/vanilla/world/blockentity/ChestCreator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 KCodeYT 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package de.kcodeyt.vanilla.world.blockentity; 18 | 19 | import cn.nukkit.blockentity.BlockEntity; 20 | import cn.nukkit.blockentity.BlockEntityChest; 21 | import cn.nukkit.level.format.FullChunk; 22 | import cn.nukkit.nbt.tag.CompoundTag; 23 | import cn.nukkit.nbt.tag.LongTag; 24 | import de.kcodeyt.vanilla.VanillaGeneratorPlugin; 25 | import de.kcodeyt.vanilla.behavior.LootTable; 26 | import de.kcodeyt.vanilla.generator.server.VanillaServer; 27 | 28 | /** 29 | * @author Kevims KCodeYT 30 | * @version 1.0-SNAPSHOT 31 | */ 32 | public class ChestCreator implements BlockEntityCreator { 33 | 34 | @Override 35 | public void createBlockEntity(VanillaServer generator, FullChunk fullChunk, CompoundTag baseTag) { 36 | final String lootTableIdentifier = baseTag.containsString("LootTable") ? baseTag.getString("LootTable") : null; 37 | final Long lootTableSeed = baseTag.get("LootTableSeed") instanceof LongTag ? baseTag.getLong("LootTableSeed") : null; 38 | 39 | final BlockEntity blockEntity = BlockEntity.createBlockEntity(BlockEntity.CHEST, fullChunk, this.createBaseBlockEntityTag(baseTag)); 40 | if(blockEntity instanceof BlockEntityChest && lootTableIdentifier != null) { 41 | final LootTable lootTable = generator.getLootTableManager().getLootTable(lootTableIdentifier); 42 | if(lootTable == null) { 43 | VanillaGeneratorPlugin.getInstance().getLogger().warning("Could not find loot table with name \"" + lootTableIdentifier + "\"!"); 44 | return; 45 | } 46 | 47 | lootTable.fillInventory(((BlockEntityChest) blockEntity).getInventory(), lootTableSeed); 48 | } 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /src/main/java/de/kcodeyt/vanilla/world/blockentity/ItemFrameCreator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 KCodeYT 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package de.kcodeyt.vanilla.world.blockentity; 18 | 19 | import cn.nukkit.blockentity.BlockEntity; 20 | import cn.nukkit.item.Item; 21 | import cn.nukkit.level.format.FullChunk; 22 | import cn.nukkit.nbt.NBTIO; 23 | import cn.nukkit.nbt.tag.CompoundTag; 24 | import de.kcodeyt.vanilla.generator.server.VanillaServer; 25 | 26 | /** 27 | * @author Kevims KCodeYT 28 | * @version 1.0-SNAPSHOT 29 | */ 30 | public class ItemFrameCreator implements BlockEntityCreator { 31 | 32 | @Override 33 | public void createBlockEntity(VanillaServer generator, FullChunk fullChunk, CompoundTag baseTag) { 34 | final float itemDropChance = baseTag.containsFloat("ItemDropChance") ? baseTag.getFloat("ItemDropChance") : 0; 35 | final float itemRotation = baseTag.containsFloat("ItemRotation") ? baseTag.getFloat("ItemRotation") : 0; 36 | final Item item = baseTag.containsCompound("Item") ? this.createItem(baseTag.getCompound("Item")) : null; 37 | BlockEntity.createBlockEntity(BlockEntity.ITEM_FRAME, fullChunk, 38 | this.createBaseBlockEntityTag(baseTag) 39 | .putFloat("ItemDropChance", itemDropChance) 40 | .putFloat("ItemRotation", itemRotation) 41 | .putCompound("Item", item != null ? NBTIO.putItemHelper(item) : new CompoundTag()) 42 | ); 43 | } 44 | 45 | } 46 | -------------------------------------------------------------------------------- /src/main/java/de/kcodeyt/vanilla/world/blockentity/LecternCreator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 KCodeYT 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package de.kcodeyt.vanilla.world.blockentity; 18 | 19 | import cn.nukkit.blockentity.BlockEntity; 20 | import cn.nukkit.item.Item; 21 | import cn.nukkit.level.format.FullChunk; 22 | import cn.nukkit.nbt.NBTIO; 23 | import cn.nukkit.nbt.tag.CompoundTag; 24 | import de.kcodeyt.vanilla.generator.server.VanillaServer; 25 | 26 | /** 27 | * @author Kevims KCodeYT 28 | * @version 1.0-SNAPSHOT 29 | */ 30 | public class LecternCreator implements BlockEntityCreator { 31 | 32 | @Override 33 | public void createBlockEntity(VanillaServer generator, FullChunk fullChunk, CompoundTag baseTag) { 34 | final Item bookItem = baseTag.containsCompound("book") ? this.createItem(baseTag.getCompound("book")) : null; 35 | if(bookItem != null) 36 | baseTag.putCompound("book", NBTIO.putItemHelper(bookItem)); 37 | BlockEntity.createBlockEntity(BlockEntity.LECTERN, fullChunk, baseTag); 38 | } 39 | 40 | } 41 | -------------------------------------------------------------------------------- /src/main/java/de/kcodeyt/vanilla/world/blockentity/MobSpawnerCreator.java: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2022 KCodeYT 3 | * 4 | * Licensed under the Apache License, Version 2.0 (the "License"); 5 | * you may not use this file except in compliance with the License. 6 | * You may obtain a copy of the License at 7 | * 8 | * http://www.apache.org/licenses/LICENSE-2.0 9 | * 10 | * Unless required by applicable law or agreed to in writing, software 11 | * distributed under the License is distributed on an "AS IS" BASIS, 12 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 | * See the License for the specific language governing permissions and 14 | * limitations under the License. 15 | */ 16 | 17 | package de.kcodeyt.vanilla.world.blockentity; 18 | 19 | import cn.nukkit.blockentity.BlockEntity; 20 | import cn.nukkit.level.format.FullChunk; 21 | import cn.nukkit.nbt.tag.CompoundTag; 22 | import cn.nukkit.nbt.tag.StringTag; 23 | import cn.nukkit.network.protocol.AddEntityPacket; 24 | import de.kcodeyt.vanilla.generator.server.VanillaServer; 25 | 26 | import java.util.Map; 27 | 28 | /** 29 | * @author Kevims KCodeYT 30 | * @version 1.0-SNAPSHOT 31 | */ 32 | public class MobSpawnerCreator implements BlockEntityCreator { 33 | 34 | @Override 35 | public void createBlockEntity(VanillaServer generator, FullChunk fullChunk, CompoundTag baseTag) { 36 | final String entityIdentifier = baseTag.removeAndGet("EntityIdentifier").data; 37 | 38 | final int entityNumericId = AddEntityPacket.LEGACY_IDS.entrySet().stream(). 39 | filter(entry -> entry.getValue().equals(entityIdentifier)).map(Map.Entry::getKey). 40 | findFirst().orElse(-1); 41 | 42 | if(entityNumericId == -1) return; 43 | 44 | baseTag.putInt("EntityId", entityNumericId); 45 | baseTag.putShort("MinimumSpawnerCount", 1); 46 | baseTag.put("MaximumSpawnerCount", baseTag.removeAndGet("SpawnCount")); 47 | 48 | BlockEntity.createBlockEntity(BlockEntity.MOB_SPAWNER, fullChunk, baseTag); 49 | } 50 | 51 | } 52 | -------------------------------------------------------------------------------- /src/main/resources/config.yml: -------------------------------------------------------------------------------- 1 | #Whether we should send a debug tip which shows the current tps and the current chunk the player is in 2 | debug-tip: true 3 | 4 | #Fake players per background server, this can increase the load of the server but makes chunk generation faster. 5 | #This number has to be between 1 and 5 6 | fake-players: 2 7 | 8 | #The local ip address of the server running this plugin. 9 | local-address: "127.0.0.1" -------------------------------------------------------------------------------- /src/main/resources/plugin.yml: -------------------------------------------------------------------------------- 1 | main: de.kcodeyt.vanilla.VanillaGeneratorPlugin 2 | name: VanillaGeneratorPlugin 3 | version: "0.0.14-SNAPSHOT" 4 | authors: ["KCodeYT"] 5 | api: ["1.0.0"] 6 | load: STARTUP --------------------------------------------------------------------------------