Skip to content

Commit 6d13471

Browse files
authored
Fix #546: Grant Wax On achievement when using Wax (#1205)
1 parent 21bbcda commit 6d13471

File tree

2 files changed

+64
-1
lines changed

2 files changed

+64
-1
lines changed

src/main/java/aztech/modern_industrialization/MIItem.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ public static void init(IEventBus modBus) {
200200
public static final ItemDefinition<Item> MIXED_PLATE_NUCLEAR = item("Nuclear Mixed Plate", "mixed_plate_nuclear", MATERIALS.and("nuclear"));
201201

202202
// Others
203-
public static final ItemDefinition<Item> WAX = item("Wax", "wax", HoneycombItem::new, ITEMS_ORDERED.next());
203+
public static final ItemDefinition<Item> WAX = item("Wax", "wax", WaxItem::new, ITEMS_ORDERED.next());
204204
public static final ItemDefinition<NuclearComponentItem> SMALL_HEAT_EXCHANGER = NuclearComponentItem.of(
205205
"Small Heat Exchanger", "small_heat_exchanger",
206206
2500, 15 * NuclearConstant.BASE_HEAT_CONDUCTION, INeutronBehaviour.NO_INTERACTION);
Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
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

Comments
 (0)