Implemented Unit Upgraders. Thanks to Ayutac.

* Started working on upgraders

* debug so game doesn't crash anymore

* orientation is saved now

* duplication bug removed

* added model files, lang entries and recipes+toasts
This commit is contained in:
Ayutac 2022-06-01 05:01:51 +02:00 committed by GitHub
parent d339f61d4d
commit 0bcd2bec03
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
20 changed files with 410 additions and 8 deletions

View file

@ -56,6 +56,7 @@ import techreborn.items.tool.vanilla.*;
import techreborn.utils.InitUtils;
import java.util.Arrays;
import java.util.Optional;
/**
* @author drcrazy
@ -83,6 +84,7 @@ public class ModRegistry {
});
Arrays.stream(SolarPanels.values()).forEach(value -> RebornRegistry.registerBlock(value.block, itemGroup));
Arrays.stream(StorageUnit.values()).forEach(value -> RebornRegistry.registerBlock(value.block, itemGroup));
Arrays.stream(StorageUnit.values()).map(StorageUnit::getUpgrader).filter(Optional::isPresent).forEach(value -> RebornRegistry.registerItem(value.get()));
Arrays.stream(TankUnit.values()).forEach(value -> RebornRegistry.registerBlock(value.block, itemGroup));
Arrays.stream(Cables.values()).forEach(value -> RebornRegistry.registerBlock(value.block, itemGroup));
Arrays.stream(Machine.values()).forEach(value -> RebornRegistry.registerBlock(value.block, itemGroup));

View file

@ -89,6 +89,7 @@ import techreborn.entities.EntityNukePrimed;
import techreborn.events.ModRegistry;
import techreborn.items.DynamicCellItem;
import techreborn.items.UpgradeItem;
import techreborn.items.UpgraderItem;
import techreborn.items.armor.QuantumSuitItem;
import techreborn.utils.InitUtils;
import techreborn.world.OreDistribution;
@ -301,22 +302,23 @@ public class TRContent {
}
public enum StorageUnit implements ItemConvertible {
BUFFER(1),
CRUDE(TechRebornConfig.crudeStorageUnitMaxStorage),
BASIC(TechRebornConfig.basicStorageUnitMaxStorage),
ADVANCED(TechRebornConfig.advancedStorageUnitMaxStorage),
INDUSTRIAL(TechRebornConfig.industrialStorageUnitMaxStorage),
QUANTUM(TechRebornConfig.quantumStorageUnitMaxStorage),
CREATIVE(Integer.MAX_VALUE);
BUFFER(1, false),
CRUDE(TechRebornConfig.crudeStorageUnitMaxStorage, true),
BASIC(TechRebornConfig.basicStorageUnitMaxStorage, true),
ADVANCED(TechRebornConfig.advancedStorageUnitMaxStorage, true),
INDUSTRIAL(TechRebornConfig.industrialStorageUnitMaxStorage, true),
QUANTUM(TechRebornConfig.quantumStorageUnitMaxStorage, false),
CREATIVE(Integer.MAX_VALUE, false);
public final String name;
public final Block block;
public final Item upgrader;
// How many items it can hold
public int capacity;
StorageUnit(int capacity) {
StorageUnit(int capacity, boolean upgradable) {
name = this.toString().toLowerCase(Locale.ROOT);
block = new StorageUnitBlock(this);
this.capacity = capacity;
@ -325,12 +327,38 @@ public class TRContent {
InitUtils.setup(block, "storage_buffer");
else
InitUtils.setup(block, name + "_storage_unit");
if (upgradable) {
if (name.equals("buffer"))
upgrader = InitUtils.setup(new UpgraderItem(), "storage_buffer_upgrader");
else
upgrader = InitUtils.setup(new UpgraderItem(), name + "_unit_upgrader");
}
else
upgrader = null;
}
public Block asBlock() {
return block;
}
@Override
public Item asItem() {
return block.asItem();
}
public Optional<Item> getUpgrader() {
return Optional.ofNullable(upgrader);
}
public static Optional<StorageUnit> getUpgradableFor(UpgraderItem item) {
if (item == null)
return Optional.empty();
for (StorageUnit unit : StorageUnit.values()) {
if (item.equals(unit.getUpgrader().orElse(null)))
return Optional.of(unit);
}
return Optional.empty();
}
}
public enum TankUnit implements ItemConvertible {
@ -355,10 +383,33 @@ public class TRContent {
InitUtils.setup(block, name + "_tank_unit");
}
public Block asBlock() {
return block;
}
@Override
public Item asItem() {
return block.asItem();
}
public Optional<Item> getUpgrader() {
try {
return StorageUnit.valueOf(name()).getUpgrader();
}
catch (IllegalArgumentException ex) {
return Optional.empty();
}
}
public static Optional<TankUnit> getUpgradableFor(UpgraderItem item) {
if (item == null)
return Optional.empty();
for (TankUnit unit : TankUnit.values()) {
if (item.equals(unit.getUpgrader().orElse(null)))
return Optional.of(unit);
}
return Optional.empty();
}
}
public enum Cables implements ItemConvertible {

View file

@ -0,0 +1,48 @@
package techreborn.items;
import net.minecraft.block.BlockState;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.item.Item;
import net.minecraft.item.ItemUsageContext;
import net.minecraft.nbt.NbtCompound;
import net.minecraft.util.ActionResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.registry.Registry;
import net.minecraft.world.World;
import techreborn.TechReborn;
import techreborn.init.TRContent.StorageUnit;
import techreborn.init.TRContent.TankUnit;
public class UpgraderItem extends Item {
public UpgraderItem() {
super(new Item.Settings().group(TechReborn.ITEMGROUP));
}
@Override
public ActionResult useOnBlock(ItemUsageContext context) {
World world = context.getWorld();
BlockPos blockPos = context.getBlockPos();
BlockEntity oldBlockEntity = world.getBlockEntity(blockPos);
BlockState oldBlockState = world.getBlockState(blockPos);
BlockState newBlockState = null;
// if no storage upgrader, the isOf compares with null and returns false
if (oldBlockState.isOf(StorageUnit.getUpgradableFor(this).map(StorageUnit::asBlock).orElse(null))) {
// upgradable is now guaranteed to be present, or something is seriously wrong
// we want to get the next unit in the enum, hence ordinal()+1
newBlockState = StorageUnit.values()[StorageUnit.getUpgradableFor(this).orElseThrow().ordinal()+1].asBlock().getStateWithProperties(oldBlockState);
}
// same for the tank
else if (oldBlockState.isOf(TankUnit.getUpgradableFor(this).map(TankUnit::asBlock).orElse(null))) {
newBlockState = TankUnit.values()[TankUnit.getUpgradableFor(this).orElseThrow().ordinal()+1].asBlock().getDefaultState();
}
if (newBlockState == null)
return ActionResult.PASS;
NbtCompound data = oldBlockEntity.createNbt();
world.getBlockEntity(blockPos).readNbt(new NbtCompound());
world.setBlockState(blockPos, newBlockState);
world.getBlockEntity(blockPos).readNbt(data);
world.getBlockEntity(blockPos).readNbt(data);
return ActionResult.SUCCESS;
}
}

View file

@ -653,6 +653,10 @@
"item.techreborn.compressed_plantball": "Compressed Plantball",
"item.techreborn.sponge_piece": "Piece of Sponge",
"item.techreborn.synthetic_redstone_crystal": "Synthetic Redstone Crystal",
"item.techreborn.crude_unit_upgrader": "Crude Unit Upgrader",
"item.techreborn.basic_unit_upgrader": "Basic Unit Upgrader",
"item.techreborn.advanced_unit_upgrader": "Advanced Unit Upgrader",
"item.techreborn.industrial_unit_upgrader": "Industrial Unit Upgrader",
"_comment14": "Items-Armor",
"item.techreborn.cloaking_device": "Cloaking Device",

View file

@ -0,0 +1,6 @@
{
"parent": "minecraft:item/generated",
"textures": {
"layer0": "techreborn:item/part/advanced_unit_upgrader"
}
}

View file

@ -0,0 +1,6 @@
{
"parent": "minecraft:item/generated",
"textures": {
"layer0": "techreborn:item/part/basic_unit_upgrader"
}
}

View file

@ -0,0 +1,6 @@
{
"parent": "minecraft:item/generated",
"textures": {
"layer0": "techreborn:item/part/crude_unit_upgrader"
}
}

View file

@ -0,0 +1,6 @@
{
"parent": "minecraft:item/generated",
"textures": {
"layer0": "techreborn:item/part/industrial_unit_upgrader"
}
}

Binary file not shown.

After

Width:  |  Height:  |  Size: 425 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 424 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 434 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 429 B

View file

@ -0,0 +1,32 @@
{
"parent": "minecraft:recipes/root",
"rewards": {
"recipes": [
"techreborn:crafting_table/unit/upgrader/advanced_unit_upgrader"
]
},
"criteria": {
"has_advanced_storage_unit": {
"trigger": "minecraft:inventory_changed",
"conditions": {
"items": [
{
"items": ["techreborn:advanced_storage_unit"]
}
]
}
},
"has_the_recipe": {
"trigger": "minecraft:recipe_unlocked",
"conditions": {
"recipe": "techreborn:crafting_table/unit/upgrader/advanced_unit_upgrader"
}
}
},
"requirements": [
[
"has_advanced_storage_unit",
"has_the_recipe"
]
]
}

View file

@ -0,0 +1,43 @@
{
"parent": "minecraft:recipes/root",
"rewards": {
"recipes": [
"techreborn:crafting_table/unit/upgrader/basic_unit_upgrader"
]
},
"criteria": {
"has_basic_storage_unit": {
"trigger": "minecraft:inventory_changed",
"conditions": {
"items": [
{
"items": ["techreborn:basic_storage_unit"]
}
]
}
},
"has_digital_display": {
"trigger": "minecraft:inventory_changed",
"conditions": {
"items": [
{
"items": ["techreborn:digital_display"]
}
]
}
},
"has_the_recipe": {
"trigger": "minecraft:recipe_unlocked",
"conditions": {
"recipe": "techreborn:crafting_table/unit/upgrader/basic_unit_upgrader"
}
}
},
"requirements": [
[
"has_basic_storage_unit",
"has_digital_display",
"has_the_recipe"
]
]
}

View file

@ -0,0 +1,43 @@
{
"parent": "minecraft:recipes/root",
"rewards": {
"recipes": [
"techreborn:crafting_table/unit/upgrader/crude_unit_upgrader"
]
},
"criteria": {
"has_crude_storage_unit": {
"trigger": "minecraft:inventory_changed",
"conditions": {
"items": [
{
"items": ["techreborn:crude_storage_unit"]
}
]
}
},
"has_basic_display": {
"trigger": "minecraft:inventory_changed",
"conditions": {
"items": [
{
"items": ["techreborn:basic_display"]
}
]
}
},
"has_the_recipe": {
"trigger": "minecraft:recipe_unlocked",
"conditions": {
"recipe": "techreborn:crafting_table/unit/upgrader/crude_unit_upgrader"
}
}
},
"requirements": [
[
"has_crude_storage_unit",
"has_basic_display",
"has_the_recipe"
]
]
}

View file

@ -0,0 +1,43 @@
{
"parent": "minecraft:recipes/root",
"rewards": {
"recipes": [
"techreborn:crafting_table/unit/upgrader/industrial_unit_upgrader"
]
},
"criteria": {
"has_industrial_storage_unit": {
"trigger": "minecraft:inventory_changed",
"conditions": {
"items": [
{
"items": ["techreborn:industrial_storage_unit"]
}
]
}
},
"has_data_storage_chip": {
"trigger": "minecraft:inventory_changed",
"conditions": {
"items": [
{
"items": ["techreborn:data_storage_chip"]
}
]
}
},
"has_the_recipe": {
"trigger": "minecraft:recipe_unlocked",
"conditions": {
"recipe": "techreborn:crafting_table/unit/upgrader/industrial_unit_upgrader"
}
}
},
"requirements": [
[
"has_industrial_storage_unit",
"has_data_storage_chip",
"has_the_recipe"
]
]
}

View file

@ -0,0 +1,28 @@
{
"type": "minecraft:crafting_shaped",
"pattern": [
"PPP",
"XB ",
"CDC"
],
"key": {
"P": {
"tag": "c:steel_plates"
},
"B": {
"item": "techreborn:industrial_machine_frame"
},
"D": {
"item": "techreborn:digital_display"
},
"X": {
"item": "techreborn:advanced_storage_unit"
},
"C": {
"item": "techreborn:industrial_circuit"
}
},
"result": {
"item": "techreborn:advanced_unit_upgrader"
}
}

View file

@ -0,0 +1,28 @@
{
"type": "minecraft:crafting_shaped",
"pattern": [
"PPP",
"XB ",
"CDC"
],
"key": {
"P": {
"tag": "c:electrum_plates"
},
"B": {
"item": "techreborn:advanced_machine_frame"
},
"D": {
"item": "techreborn:digital_display"
},
"X": {
"item": "techreborn:basic_storage_unit"
},
"C": {
"item": "techreborn:advanced_circuit"
}
},
"result": {
"item": "techreborn:basic_unit_upgrader"
}
}

View file

@ -0,0 +1,28 @@
{
"type": "minecraft:crafting_shaped",
"pattern": [
"PPP",
"XB ",
"CDC"
],
"key": {
"X": {
"item": "techreborn:crude_storage_unit"
},
"B": {
"item": "techreborn:basic_machine_frame"
},
"P": {
"tag": "c:refined_iron_plates"
},
"D": {
"item": "techreborn:basic_display"
},
"C": {
"item": "techreborn:electronic_circuit"
}
},
"result": {
"item": "techreborn:crude_unit_upgrader"
}
}

View file

@ -0,0 +1,28 @@
{
"type": "minecraft:crafting_shaped",
"pattern": [
"PPP",
"XB ",
"CDC"
],
"key": {
"P": {
"tag": "c:tungsten_plates"
},
"B": {
"item": "techreborn:industrial_machine_frame"
},
"X": {
"item": "techreborn:industrial_storage_unit"
},
"D": {
"item": "techreborn:digital_display"
},
"C": {
"item": "techreborn:data_storage_chip"
}
},
"result": {
"item": "techreborn:industrial_unit_upgrader"
}
}