|
| 1 | +/* |
| 2 | + * MIT License |
| 3 | + * |
| 4 | + * Copyright (c) 2020 Azercoco & Technici4n |
| 5 | + * |
| 6 | + * Permission is hereby granted, free of charge, to any person obtaining a copy |
| 7 | + * of this software and associated documentation files (the "Software"), to deal |
| 8 | + * in the Software without restriction, including without limitation the rights |
| 9 | + * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
| 10 | + * copies of the Software, and to permit persons to whom the Software is |
| 11 | + * furnished to do so, subject to the following conditions: |
| 12 | + * |
| 13 | + * The above copyright notice and this permission notice shall be included in all |
| 14 | + * copies or substantial portions of the Software. |
| 15 | + * |
| 16 | + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
| 19 | + * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
| 20 | + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
| 21 | + * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE |
| 22 | + * SOFTWARE. |
| 23 | + */ |
| 24 | + |
| 25 | +package aztech.modern_industrialization.items; |
| 26 | + |
| 27 | +import net.minecraft.resources.ResourceLocation; |
| 28 | +import net.minecraft.server.level.ServerPlayer; |
| 29 | +import net.minecraft.world.InteractionResult; |
| 30 | +import net.minecraft.world.item.HoneycombItem; |
| 31 | +import net.minecraft.world.item.context.UseOnContext; |
| 32 | + |
| 33 | +/** |
| 34 | + * Grants the vanilla "Wax On" advancement on successful usage. |
| 35 | + */ |
| 36 | +public class WaxItem extends HoneycombItem { |
| 37 | + public WaxItem(Properties properties) { |
| 38 | + super(properties); |
| 39 | + } |
| 40 | + |
| 41 | + @Override |
| 42 | + public InteractionResult useOn(UseOnContext context) { |
| 43 | + var ret = super.useOn(context); |
| 44 | + if (ret.indicateItemUse()) { |
| 45 | + if (context.getPlayer() instanceof ServerPlayer serverPlayer) { |
| 46 | + grantWaxOn(serverPlayer); |
| 47 | + } |
| 48 | + } |
| 49 | + return ret; |
| 50 | + } |
| 51 | + |
| 52 | + private static final ResourceLocation WAX_ON = ResourceLocation.withDefaultNamespace("husbandry/wax_on"); |
| 53 | + |
| 54 | + private static void grantWaxOn(ServerPlayer serverPlayer) { |
| 55 | + var advancement = serverPlayer.server.getAdvancements().get(WAX_ON); |
| 56 | + if (advancement == null) { |
| 57 | + return; |
| 58 | + } |
| 59 | + |
| 60 | + var playerAdvancements = serverPlayer.server.getPlayerList().getPlayerAdvancements(serverPlayer); |
| 61 | + playerAdvancements.award(advancement, "wax_on"); |
| 62 | + } |
| 63 | +} |
0 commit comments