Skip to content

Commit 19839fe

Browse files
committed
add add upgrade from normal/mega/extended pattern provider -> expanded pattern provider, fixes #39
Signed-off-by: Kolja <[email protected]>
1 parent 01a9eb8 commit 19839fe

15 files changed

Lines changed: 282 additions & 82 deletions

File tree

src/generated/resources/assets/expandedae/lang/en_us.json

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,11 +85,13 @@
8585
"item.expandedae.dual_storage_cell_64m": "64m ME Dual Storage Cell",
8686
"item.expandedae.exp_pattern_provider_part": "Expanded Pattern Provider",
8787
"item.expandedae.exp_pattern_provider_upgrade": "Expanded Pattern Provider Upgrade",
88+
"item.expandedae.ext_pattern_provider_upgrade": "Extended Pattern Provider Upgrade",
8889
"item.expandedae.greater_accel_card": "Greater Acceleration Card",
8990
"item.expandedae.greater_accel_card.tooltip.1": "Even greater acceleration",
9091
"item.expandedae.greater_accel_card.tooltip.2": "Note: Very power hungry!",
9192
"item.expandedae.linked_terminal": "Linked Terminal",
9293
"item.expandedae.mega_dual_cell_housing": "ME MEGA Dual Cell Housing",
94+
"item.expandedae.mega_pattern_provider_upgrade": "Mega Pattern Provider Upgrade",
9395
"item.expandedae.pattern_refiller_card": "Pattern Refiller Card",
9496
"item.expandedae.pattern_refiller_card.tooltip.1": "Automatically refills the blank patterns",
9597
"item.expandedae.priority_card": "Priority Card",
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"parent": "minecraft:item/generated",
3+
"textures": {
4+
"layer0": "expandedae:item/ext_pattern_provider_upgrade"
5+
}
6+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"parent": "minecraft:item/generated",
3+
"textures": {
4+
"layer0": "expandedae:item/mega_pattern_provider_upgrade"
5+
}
6+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"type": "forge:conditional",
3+
"recipes": [
4+
{
5+
"conditions": [
6+
{
7+
"type": "forge:mod_loaded",
8+
"modid": "expatternprovider"
9+
}
10+
],
11+
"recipe": {
12+
"type": "minecraft:crafting_shaped",
13+
"category": "misc",
14+
"key": {
15+
"C": {
16+
"item": "ae2:capacity_card"
17+
},
18+
"E": {
19+
"item": "ae2:engineering_processor"
20+
}
21+
},
22+
"pattern": [
23+
"ECE",
24+
"CEC"
25+
],
26+
"result": {
27+
"item": "expandedae:ext_pattern_provider_upgrade"
28+
},
29+
"show_notification": true
30+
}
31+
}
32+
]
33+
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
{
2+
"type": "forge:conditional",
3+
"recipes": [
4+
{
5+
"conditions": [
6+
{
7+
"type": "forge:mod_loaded",
8+
"modid": "megacells"
9+
}
10+
],
11+
"recipe": {
12+
"type": "minecraft:crafting_shaped",
13+
"category": "misc",
14+
"key": {
15+
"C": {
16+
"item": "ae2:capacity_card"
17+
},
18+
"E": {
19+
"item": "ae2:engineering_processor"
20+
}
21+
},
22+
"pattern": [
23+
"EC",
24+
"CE"
25+
],
26+
"result": {
27+
"item": "expandedae:mega_pattern_provider_upgrade"
28+
},
29+
"show_notification": true
30+
}
31+
}
32+
]
33+
}

src/main/java/lu/kolja/expandedae/datagen/ExpRecipeProvider.java

Lines changed: 24 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,29 @@ protected void buildRecipes(@NotNull Consumer<FinishedRecipe> out) {
6565
.unlockedBy("has_engineering_processor", has(ENGINEERING_PROCESSOR))
6666
.unlockedBy("has_capacity_card", has(CAPACITY_CARD))
6767
.save(out, craftingId("exp_pattern_provider_upgrade"));
68+
conditional(
69+
ShapedRecipeBuilder.shaped(MISC, MEGA_PATTERN_PROVIDER_UPGRADE)
70+
.pattern("EC")
71+
.pattern("CE")
72+
.define('C', CAPACITY_CARD)
73+
.define('E', ENGINEERING_PROCESSOR)
74+
.unlockedBy("has_engineering_processor", has(ENGINEERING_PROCESSOR))
75+
.unlockedBy("has_capacity_card", has(CAPACITY_CARD)),
76+
out, loaded(MEGA.mod),
77+
craftingId("mega_pattern_provider_upgrade")
78+
);
79+
80+
conditional(
81+
ShapedRecipeBuilder.shaped(MISC, EXT_PATTERN_PROVIDER_UPGRADE)
82+
.pattern("ECE")
83+
.pattern("CEC")
84+
.define('C', CAPACITY_CARD)
85+
.define('E', ENGINEERING_PROCESSOR)
86+
.unlockedBy("has_engineering_processor", has(ENGINEERING_PROCESSOR))
87+
.unlockedBy("has_capacity_card", has(CAPACITY_CARD)),
88+
out, loaded(EXT.mod),
89+
craftingId("ext_pattern_provider_upgrade")
90+
);
6891

6992
ShapelessRecipeBuilder.shapeless(MISC, AUTO_COMPLETE_CARD)
7093
.requires(ADVANCED_CARD)
@@ -237,8 +260,8 @@ private static void conditional(RecipeBuilder recipe, Consumer<FinishedRecipe> o
237260
recipe.save(finished ->
238261
ConditionalRecipe
239262
.builder()
240-
.addRecipe(finished)
241263
.addCondition(condition)
264+
.addRecipe(finished)
242265
.build(out, id));
243266
}
244267

src/main/java/lu/kolja/expandedae/datagen/model/ExpItemModelProvider.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
import net.minecraftforge.client.model.generators.ItemModelProvider;
1212
import net.minecraftforge.common.data.ExistingFileHelper;
1313

14+
import static lu.kolja.expandedae.definition.ExpItems.*;
15+
import static lu.kolja.expandedae.definition.ExpItems.GREATER_ACCEL_CARD;
16+
1417
public class ExpItemModelProvider extends ItemModelProvider {
1518
public ExpItemModelProvider(PackOutput output, ExistingFileHelper existingFileHelper) {
1619
super(output, Expandedae.MODID, existingFileHelper);
@@ -24,6 +27,15 @@ protected void registerModels() {
2427
for (var cell : ExpCellModels.cellModels.object2ObjectEntrySet()) {
2528
driveCell(cell.getValue());
2629
}
30+
31+
// General
32+
basicItem(EXP_PATTERN_PROVIDER_UPGRADE.asItem());
33+
basicItem(MEGA_PATTERN_PROVIDER_UPGRADE.asItem());
34+
basicItem(EXT_PATTERN_PROVIDER_UPGRADE.asItem());
35+
// CARDS
36+
basicItem(AUTO_COMPLETE_CARD.asItem());
37+
basicItem(PATTERN_REFILLER_CARD.asItem());
38+
basicItem(GREATER_ACCEL_CARD.asItem());
2739
basicItem(ExpItems.DUAL_CELL_HOUSING.asItem());
2840
basicItem(MegaCells.DUAL_CELL_MEGA_HOUSING.asItem());
2941
basicItem(ExpItems.PRIORITY_CARD.asItem());

src/main/java/lu/kolja/expandedae/datagen/model/ExpModelProvider.java

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -9,29 +9,20 @@
99
import lu.kolja.expandedae.definition.ExpBlocks;
1010
import lu.kolja.expandedae.enums.ExpTiers;
1111
import net.minecraft.data.PackOutput;
12-
import net.minecraft.world.level.ItemLike;
1312
import net.minecraftforge.client.model.generators.ConfiguredModel;
1413
import net.minecraftforge.client.model.generators.ModelFile;
1514
import net.minecraftforge.common.data.ExistingFileHelper;
1615
import org.jetbrains.annotations.NotNull;
1716

1817
import java.util.ArrayList;
1918

20-
import static lu.kolja.expandedae.definition.ExpItems.*;
21-
2219
public class ExpModelProvider extends AE2BlockStateProvider {
2320
public ExpModelProvider(PackOutput output, ExistingFileHelper existingFileHelper) {
2421
super(output, Expandedae.MODID, existingFileHelper);
2522
}
2623

2724
@Override
2825
protected void registerStatesAndModels() {
29-
// General
30-
basicItem(EXP_PATTERN_PROVIDER_UPGRADE);
31-
// CARDS
32-
basicItem(AUTO_COMPLETE_CARD);
33-
basicItem(PATTERN_REFILLER_CARD);
34-
basicItem(GREATER_ACCEL_CARD);
3526
energyCell(ExpBlocks.EXP_ENERGY_CELL, "block/exp_energy_cell");
3627
// CPU
3728
for (var cpu : ExpTiers.values()) {
@@ -50,10 +41,6 @@ protected void registerStatesAndModels() {
5041

5142
}
5243

53-
private void basicItem(ItemLike item) {
54-
itemModels().basicItem(item.asItem());
55-
}
56-
5744
@NotNull
5845
@Override
5946
public String getName() {

src/main/java/lu/kolja/expandedae/definition/ExpItems.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
import lu.kolja.expandedae.enums.Addons;
2020
import lu.kolja.expandedae.item.misc.ExpPatternProviderUpgradeItem;
2121
import lu.kolja.expandedae.item.linked.LinkedTerminalItem;
22+
import lu.kolja.expandedae.item.misc.ExtPatternProviderUpgradeItem;
23+
import lu.kolja.expandedae.item.misc.MegaPatternProviderUpgradeItem;
2224
import lu.kolja.expandedae.item.misc.PriorityCardItem;
2325
import lu.kolja.expandedae.item.part.ExpPatternProviderPartItem;
2426
import lu.kolja.expandedae.part.ExpPatternProviderPart;
@@ -56,6 +58,16 @@ public class ExpItems {
5658
"exp_pattern_provider_upgrade",
5759
ExpPatternProviderUpgradeItem::new
5860
);
61+
public static final ItemDefinition<MegaPatternProviderUpgradeItem> MEGA_PATTERN_PROVIDER_UPGRADE = item(
62+
"Mega Pattern Provider Upgrade",
63+
"mega_pattern_provider_upgrade",
64+
MegaPatternProviderUpgradeItem::new
65+
);
66+
public static final ItemDefinition<ExtPatternProviderUpgradeItem> EXT_PATTERN_PROVIDER_UPGRADE = item(
67+
"Extended Pattern Provider Upgrade",
68+
"ext_pattern_provider_upgrade",
69+
ExtPatternProviderUpgradeItem::new
70+
);
5971

6072
public static final ItemDefinition<UpgradeCardItem> AUTO_COMPLETE_CARD = item(
6173
"Auto Complete Card",

src/main/java/lu/kolja/expandedae/item/abstracts/UpgradeItem.java

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,24 @@
11
package lu.kolja.expandedae.item.abstracts;
22

3+
import appeng.block.AEBaseEntityBlock;
34
import appeng.blockentity.AEBaseBlockEntity;
5+
import appeng.blockentity.networking.CableBusBlockEntity;
6+
import appeng.core.definitions.BlockDefinition;
7+
import appeng.items.parts.PartItem;
8+
import appeng.parts.AEBasePart;
49
import net.minecraft.core.BlockPos;
510
import net.minecraft.nbt.CompoundTag;
11+
import net.minecraft.world.InteractionResult;
612
import net.minecraft.world.item.Item;
13+
import net.minecraft.world.item.context.BlockPlaceContext;
14+
import net.minecraft.world.item.context.UseOnContext;
715
import net.minecraft.world.level.Level;
816
import net.minecraft.world.level.block.entity.BlockEntity;
17+
import net.minecraft.world.level.block.entity.BlockEntityType;
918
import net.minecraft.world.level.block.state.BlockState;
19+
import net.minecraft.world.level.block.state.properties.Property;
20+
import net.minecraft.world.phys.Vec3;
21+
import org.jetbrains.annotations.Nullable;
1022

1123
public abstract class UpgradeItem extends Item {
1224
public UpgradeItem(Properties pProperties) {
@@ -26,4 +38,61 @@ protected void replaceTile(Level world, BlockPos pos, BlockEntity oldTile, Block
2638
newTile.setChanged();
2739
}
2840
}
41+
42+
protected InteractionResult replace(
43+
UseOnContext context,
44+
Class<? extends AEBaseBlockEntity> oldBE, BlockEntityType<?> newBE,
45+
BlockDefinition<? extends AEBaseEntityBlock<?>> newBlock, @Nullable Class<? extends AEBasePart> oldPart, @Nullable PartItem<?> newPart) {
46+
var pos = context.getClickedPos();
47+
var world = context.getLevel();
48+
var entity = world.getBlockEntity(pos);
49+
if (entity != null) {
50+
var ctx = new BlockPlaceContext(context);
51+
var tClazz = entity.getClass();
52+
if (tClazz == oldBE) {
53+
54+
var originState = world.getBlockState(pos);
55+
var state = newBlock.block().getStateForPlacement(ctx);
56+
if (state == null) {
57+
return InteractionResult.PASS;
58+
}
59+
for (var sp : originState.getValues().entrySet()) {
60+
var pt = sp.getKey();
61+
var va = sp.getValue();
62+
try {
63+
if (state.hasProperty(pt)) {
64+
state = state.<Comparable, Comparable>setValue((Property) pt, va);
65+
}
66+
} catch (Exception ignore) {
67+
// NO-OP
68+
}
69+
}
70+
71+
BlockEntity te = newBE.create(pos, state);
72+
replaceTile(world, pos, entity, te, state);
73+
context.getItemInHand().shrink(1);
74+
return InteractionResult.CONSUME;
75+
76+
} else if (oldPart != null && entity instanceof CableBusBlockEntity cable) {
77+
Vec3 hitVec = context.getClickLocation();
78+
Vec3 hitInBlock = new Vec3(hitVec.x - pos.getX(), hitVec.y - pos.getY(), hitVec.z - pos.getZ());
79+
var part = cable.getCableBus().selectPartLocal(hitInBlock).part;
80+
if (part instanceof AEBasePart basePart && part.getClass() == oldPart) {
81+
var side = basePart.getSide();
82+
var contents = new CompoundTag();
83+
84+
part.writeToNBT(contents);
85+
var p = cable.replacePart(newPart, side, context.getPlayer(), null);
86+
if (p != null) {
87+
p.readFromNBT(contents);
88+
}
89+
} else {
90+
return InteractionResult.PASS;
91+
}
92+
context.getItemInHand().shrink(1);
93+
return InteractionResult.sidedSuccess(world.isClientSide);
94+
}
95+
}
96+
return InteractionResult.PASS;
97+
}
2998
}

0 commit comments

Comments
 (0)