Skip to content

Commit

Permalink
Add machine quality levels
Browse files Browse the repository at this point in the history
  • Loading branch information
Rearth committed Feb 20, 2024
1 parent 4b64e20 commit fca30c0
Show file tree
Hide file tree
Showing 32 changed files with 146 additions and 54 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// 1.20.4 2024-02-18T12:13:34.3124678 Oritech/Model Definitions
// 1.20.4 2024-02-19T22:05:27.589798 Oritech/Model Definitions
3d6f377b938592ac22aca17bd64561a6579ad217 assets\oritech\blockstates\grinder_block.json
90e28b721796ff7ee21c8eefe4525f03a251d2fb assets\oritech\models\block\machine_extender.json
16b697f4a40bfdcd8c39629776b97696e80681c7 assets\oritech\blockstates\machine_efficiency_addon.json
Expand All @@ -8,25 +8,24 @@ b5ee97616ae0d2da17dfaecf45aa42f2cf19f691 assets\oritech\blockstates\machine_exte
c9c5614f832a38e30b60d0a15d75292159b16455 assets\oritech\models\item\machine_speed_addon.json
25864df3cd7786f2bf4fe6fa9855b3cf366c28ca assets\oritech\models\item\banana.json
b8bc03092cb1eb686ede01daffc7421253af860c assets\oritech\models\item\machine_extender.json
3bd3ce424e506dbbd4a45a0081e0f04b914abb27 assets\oritech\models\item\machine_core.json
63f14855c688ce7ec236097ce232dd381cbc1538 assets\oritech\blockstates\addon_indicator_block.json
746b98d721e5ae0d96dd769e71b786afa8c2d142 assets\oritech\models\item\banana_block.json
7eb395cd65df72caf43bedc54067cbf53940fd6c assets\oritech\blockstates\machine_speed_addon.json
95eae9b13fb2835f15057d2fd4d9550192064ca4 assets\oritech\models\item\grinder_block.json
11d0ac231a96bb2c0b9b97a490750062630d37cf assets\oritech\blockstates\machine_capacitor_addon.json
8169e036f9cc1d31d7f5da9f25c436dcf05e9df4 assets\oritech\models\block\pulverizer_block.json
a5a8d2e834fc121777ed1a4c0df99e85a6f23613 assets\oritech\models\block\machine_core.json
4f9effc04022c2a77254aba75fcc61198bc6e73e assets\oritech\models\item\machine_capacitor_addon.json
c641d411ad252487b93d779cee9028b9ee920281 assets\oritech\blockstates\machine_core_basic.json
6c9c0c9fbf5c26f5e8146a956b9e0567572acb45 assets\oritech\blockstates\machine_inventory_proxy_addon.json
f29468ff950a191567ab35557334666099ccd7cc assets\oritech\blockstates\assembler_block.json
964457f56e25b66dfef2160c8618bcaba2b640aa assets\oritech\blockstates\pulverizer_block.json
24c3ad5133727ec3d6d075af18fd96cf2687ec03 assets\oritech\models\block\machine_efficiency_addon.json
801af982fe394c02734dd407d3d6b960d9501dba assets\oritech\models\block\machine_speed_addon.json
505d30e3b61ee0ba1f2616e1226689e2cdb7ab58 assets\oritech\models\block\addon_indicator_block.json
e4497bad8afbd4f4b4e830d892284a05718b06dd assets\oritech\models\block\machine_core_basic.json
1b9cd3719105dc1e03398de41f2cab37337816fe assets\oritech\blockstates\machine_core_good.json
5462a2453fcdd2f8b99129894aec60f282d29ca9 assets\oritech\models\item\pulverizer_block.json
a3f9b72f6f36d42af4e5c3a87d7e180b2e36a2ed assets\oritech\models\item\machine_core_good.json
a5651b8d4a27308b40c404f7cd3abcf9769b64b6 assets\oritech\models\item\machine_core_basic.json
469ea8a66c529fe26bc029c21092e7f062ed0e40 assets\oritech\models\block\banana_block.json
d35ecef5df9198b12dc04267780c727c144b1959 assets\oritech\models\item\assembler_block.json
020ab18ae7f8883ba8928eb4a2d93defb0274c6b assets\oritech\models\block\machine_inventory_proxy_addon.json
c48da59250e22665d33524132de2dfd27f0c574f assets\oritech\models\block\grinder_block.json
823e02e06a2ca976d021d4ab1a0b63ffa6a89bea assets\oritech\models\item\machine_efficiency_addon.json
0ecc1bbf5d5fade225709596fe4c8fbbf0caf64f assets\oritech\blockstates\machine_core.json
3166a5959c87c4465c5eed82034d3178c4b8b518 assets\oritech\models\block\machine_core_good.json

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"variants": {
"": {
"model": "oritech:block/machine_core_basic"
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
{
"variants": {
"": {
"model": "oritech:block/machine_core_good"
}
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"parent": "minecraft:block/cube_all",
"textures": {
"all": "oritech:block/models/grinder_block"
"all": "oritech:block/machine_core_basic"
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"parent": "minecraft:block/cube_all",
"textures": {
"all": "oritech:block/machine_core"
"all": "oritech:block/machine_core_good"
}
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"parent": "oritech:block/machine_core_basic"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"parent": "oritech:block/machine_core_good"
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ public abstract class MultiblockMachineEntity extends UpgradableMachineBlockEnti

private final ArrayList<BlockPos> coreBlocksConnected = new ArrayList<>();

private float coreQuality = 1f;

public MultiblockMachineEntity(BlockEntityType<?> type, BlockPos pos, BlockState state) {
super(type, pos, state);
}
Expand All @@ -39,6 +41,7 @@ public void writeNbt(NbtCompound nbt) {
posList.add(posTag);
}
nbt.put("connectedCores", posList);
nbt.putFloat("coreQuality", coreQuality);
}

@Override
Expand All @@ -55,6 +58,8 @@ public void readNbt(NbtCompound nbt) {
var pos = new BlockPos(x, y, z);
coreBlocksConnected.add(pos);
}

coreQuality = nbt.getFloat("coreQuality");
}

// positive x = forward
Expand All @@ -79,6 +84,8 @@ public boolean initMultiblock(BlockState state) {
var targetPositions = getCorePositions();
var coreBlocks = new ArrayList<MultiBlockElement>(targetPositions.size());

var sumCoreQuality = 0f;

for (var targetPosition : targetPositions) {
var rotatedPos = rotatePosition(targetPosition, ownFacing);
var checkPos = pos.add(rotatedPos);
Expand All @@ -87,6 +94,7 @@ public boolean initMultiblock(BlockState state) {
var blockType = checkState.getBlock();
if (blockType instanceof MachineCoreBlock coreBlock && !checkState.get(MachineCoreBlock.USED)) {
coreBlocks.add(new MultiBlockElement(checkState, coreBlock, checkPos));
sumCoreQuality += coreBlock.getCoreQuality();
} else {
highlightBlock(checkPos);
}
Expand All @@ -102,6 +110,8 @@ public boolean initMultiblock(BlockState state) {
coreBlocksConnected.add(core.pos);
}

this.coreQuality = sumCoreQuality / coreBlocks.size();

Objects.requireNonNull(world).setBlockState(pos, state.with(MultiblockMachine.ASSEMBLED, true));
return true;
} else {
Expand All @@ -111,6 +121,11 @@ public boolean initMultiblock(BlockState state) {

}

@Override
public float getCoreQuality() {
return this.coreQuality;
}

public void onCoreBroken(BlockPos corePos, BlockState coreState) {

Objects.requireNonNull(world).setBlockState(pos, world.getBlockState(pos).with(MultiblockMachine.ASSEMBLED, false));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -118,7 +118,7 @@ public void resetAddons() {
private List<AddonBlock> getAllAddons() {

// make this number depend on machine core quality
var maxIterationCount = 6;
var maxIterationCount = (int) getCoreQuality();

// start with base slots (on machine itself)
// repeat N times (dependent on core quality?):
Expand Down Expand Up @@ -232,12 +232,13 @@ private static Vec3i offsetToWorldPosition(Direction facing, Vec3i offset, Vec3i
public void writeScreenOpeningData(ServerPlayerEntity player, PacketByteBuf buf) {
super.writeScreenOpeningData(player, buf);
buf.write(ADDON_UI_ENDEC, getUiData());
buf.writeFloat(getCoreQuality());
}

@Nullable
@Override
public ScreenHandler createMenu(int syncId, PlayerInventory playerInventory, PlayerEntity player) {
return new UpgradableMachineScreenHandler(syncId, playerInventory, this, getUiData());
return new UpgradableMachineScreenHandler(syncId, playerInventory, this, getUiData(), getCoreQuality());
}

private AddonUiData getUiData() {
Expand Down Expand Up @@ -271,6 +272,11 @@ public void setCombinedEfficiency(float combinedEfficiency) {
this.combinedEfficiency = combinedEfficiency;
}

// 1 = basic, higher=better, always rounded down
public float getCoreQuality() {
return 1f;
}

public abstract List<Vec3i> getAddonSlots();

private record AddonBlock(MachineAddonBlock addonBlock, BlockState state, BlockPos pos, AddonBlockEntity addonEntity) {}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,16 @@ public class MachineCoreBlock extends Block implements BlockEntityProvider {

public static final BooleanProperty USED = BooleanProperty.of("core_used");

public MachineCoreBlock(Settings settings) {
private final float coreQuality;

public MachineCoreBlock(Settings settings, float coreQuality) {
super(settings);
this.setDefaultState(getDefaultState().with(USED, false));
this.coreQuality = coreQuality;
}

public float getCoreQuality() {
return coreQuality;
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,11 @@
import net.minecraft.entity.player.PlayerInventory;
import net.minecraft.state.property.Properties;
import net.minecraft.text.Text;
import net.minecraft.util.Identifier;
import net.minecraft.util.math.Vec3i;
import rearth.oritech.Oritech;
import rearth.oritech.block.base.entity.MultiblockMachineEntity;
import rearth.oritech.block.base.entity.UpgradableMachineBlockEntity;
import rearth.oritech.block.custom.machines.addons.CapacitorAddonBlock;
import rearth.oritech.block.custom.machines.addons.MachineAddonBlock;
import rearth.oritech.client.ui.components.BlockPreviewComponent;
Expand All @@ -26,6 +29,8 @@ public class UpgradableMachineScreen extends BasicMachineScreen<UpgradableMachin

private static final float rotationSpeed = 0.2f;

private static final Identifier MACHINE_CORE_CENTER = new Identifier(Oritech.MOD_ID, "textures/gui/modular/machine_core/center.png");

public UpgradableMachineScreen(UpgradableMachineScreenHandler handler, PlayerInventory inventory, Text title) {
super(handler, inventory, title);
}
Expand All @@ -44,6 +49,58 @@ public void addExtensionComponents(FlowLayout container) {
addMachinePreview(container);
}

@Override
public void fillOverlay(FlowLayout overlay) {
super.fillOverlay(overlay);

var offsetX = -6;
var offsetY = -23;

var x = handler.screenData.getEnergyConfiguration().x() + offsetX;
var y = handler.screenData.getEnergyConfiguration().y() + offsetY;

var size = 25;

var level = handler.quality;
var upgradeCount = level - 1;

// the 6th upgrade needs to be rendered behind
if (upgradeCount == 6) {
overlay.child(
Components.texture(getRingIdentifier(6), 64, 64, 64, 64, 64, 64)
.sizing(Sizing.fixed(size))
.positioning(Positioning.absolute(x, y))
);

upgradeCount = 5;
}

overlay.child(
Components.texture(MACHINE_CORE_CENTER, 64, 64, 64, 64, 64, 64)
.sizing(Sizing.fixed(size))
.positioning(Positioning.absolute(x, y))
.tooltip(getQualityTooltip())
);

for (int i = 1; i <= upgradeCount; i++) {
overlay.child(
Components.texture(getRingIdentifier(i), 64, 64, 64, 64, 64, 64)
.sizing(Sizing.fixed(size))
.positioning(Positioning.absolute(x, y))
);
}
}

private Text getQualityTooltip() {
var quality = handler.quality;
var effectiveQuality = (int) handler.quality;
return Text.of(String.format("Machine Quality: %d\n\nControls how many layers of machine\naddons can be added to this block.\n\nUse better cores to increase this\n\nCurrent quality progress: %.2f", effectiveQuality, quality));
}

private Identifier getRingIdentifier(int level) {
return new Identifier(Oritech.MOD_ID, "textures/gui/modular/machine_core/ring_" + level + ".png");
}

public void addMachinePreview(FlowLayout sidePanel) {

var floatingContent = Containers.verticalFlow(Sizing.content(), Sizing.content());
Expand Down Expand Up @@ -94,7 +151,7 @@ public void remove() {
var addonBlockType = (MachineAddonBlock) addonBlock.getBlock();
var pattern = "%+.0f";
var speed = (1 - addonBlockType.getSpeedMultiplier()) * 100;
var efficiency = (1 - addonBlockType.getSpeedMultiplier()) * 100;
var efficiency = (1 - addonBlockType.getEfficiencyMultiplier()) * 100;

var blockSize = addonBlockType.isExtender() ? 15 : 23;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ public class UpgradableMachineScreenHandler extends BasicMachineScreenHandler {

protected final AddonUiData addonUiData;
protected final World worldAccess;
protected final float quality;

// on client, receiving data from writeScreenOpeningData
public UpgradableMachineScreenHandler(int syncId, PlayerInventory inventory, PacketByteBuf buf) {
this(syncId, inventory, Objects.requireNonNull(inventory.player.getWorld().getBlockEntity(buf.readBlockPos())), buf.read(ADDON_UI_ENDEC));
this(syncId, inventory, Objects.requireNonNull(inventory.player.getWorld().getBlockEntity(buf.readBlockPos())), buf.read(ADDON_UI_ENDEC), buf.readFloat());
}

// on server, also called from client constructor
public UpgradableMachineScreenHandler(int syncId, PlayerInventory playerInventory, BlockEntity blockEntity, AddonUiData addonUiData) {
public UpgradableMachineScreenHandler(int syncId, PlayerInventory playerInventory, BlockEntity blockEntity, AddonUiData addonUiData, float coreQuality) {
super(syncId, playerInventory, blockEntity);
this.addonUiData = addonUiData;

Expand All @@ -33,6 +34,7 @@ public UpgradableMachineScreenHandler(int syncId, PlayerInventory playerInventor
}

this.worldAccess = playerInventory.player.getWorld();
this.quality = coreQuality;
}

}
15 changes: 8 additions & 7 deletions src/main/java/rearth/oritech/init/BlockContent.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,18 @@ public class BlockContent implements BlockRegistryContainer {
@NoBlockItem
public static final Block ADDON_INDICATOR_BLOCK = new Block(FabricBlockSettings.copyOf(Blocks.GLASS));

@UseGeoBlockItem(scale = 1f)
@UseGeoBlockItem(scale = 0.7f)
public static final Block PULVERIZER_BLOCK = new PulverizerBlock(FabricBlockSettings.copyOf(Blocks.IRON_BLOCK).nonOpaque());
@UseGeoBlockItem(scale = 0.6f)
@UseGeoBlockItem(scale = 0.7f)
public static final Block GRINDER_BLOCK = new GrinderBlock(FabricBlockSettings.copyOf(Blocks.IRON_BLOCK).nonOpaque());
@UseGeoBlockItem(scale = 0.8f)
@UseGeoBlockItem(scale = 0.7f)
public static final Block ASSEMBLER_BLOCK = new AssemblerBlock(FabricBlockSettings.copyOf(Blocks.IRON_BLOCK).nonOpaque());

public static final Block MACHINE_CORE = new MachineCoreBlock(FabricBlockSettings.copyOf(Blocks.IRON_BLOCK).nonOpaque());
public static final Block MACHINE_SPEED_ADDON = new MachineAddonBlock(FabricBlockSettings.copyOf(Blocks.IRON_BLOCK).nonOpaque(), false, 0.9f, 1.05f);
public static final Block MACHINE_CORE_BASIC = new MachineCoreBlock(FabricBlockSettings.copyOf(Blocks.IRON_BLOCK).nonOpaque(), 1);
public static final Block MACHINE_CORE_GOOD = new MachineCoreBlock(FabricBlockSettings.copyOf(Blocks.IRON_BLOCK).nonOpaque(), 6);
public static final Block MACHINE_SPEED_ADDON = new MachineAddonBlock(FabricBlockSettings.copyOf(Blocks.IRON_BLOCK).nonOpaque(), false, 0.9f, 1.025f);
public static final Block MACHINE_EFFICIENCY_ADDON = new MachineAddonBlock(FabricBlockSettings.copyOf(Blocks.IRON_BLOCK).nonOpaque(), false, 1, 0.9f);
public static final Block MACHINE_CAPACITOR_ADDON = new CapacitorAddonBlock(FabricBlockSettings.copyOf(Blocks.IRON_BLOCK).nonOpaque(), false, 1, 1f, 5000, 100);
public static final Block MACHINE_CAPACITOR_ADDON = new CapacitorAddonBlock(FabricBlockSettings.copyOf(Blocks.IRON_BLOCK).nonOpaque(), false, 1, 1f, 10000, 500);
public static final Block MACHINE_INVENTORY_PROXY_ADDON = new InventoryProxyAddonBlock(FabricBlockSettings.copyOf(Blocks.IRON_BLOCK).nonOpaque(), false, 1, 1f);
public static final Block MACHINE_EXTENDER = new MachineAddonBlock(FabricBlockSettings.copyOf(Blocks.IRON_BLOCK).nonOpaque(), true, 1, 1);

Expand All @@ -66,7 +67,7 @@ public void postProcessField(String namespace, Block value, String identifier, F
}

private BlockItem getGeoBlockItem(Block block, String identifier, float scale) {
return new OritechGeoItem(block, new Item.Settings(), 0.7f, identifier);
return new OritechGeoItem(block, new Item.Settings(), scale, identifier);
}

@Retention(RetentionPolicy.RUNTIME)
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/rearth/oritech/init/BlockEntitiesContent.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,10 @@ public class BlockEntitiesContent implements AutoRegistryContainer<BlockEntityTy
).build();

@AssignSidedEnergy
public static final BlockEntityType<MachineCoreEntity> MACHINE_CORE_ENTITY = FabricBlockEntityTypeBuilder.create(MachineCoreEntity::new, BlockContent.MACHINE_CORE).build();
public static final BlockEntityType<MachineCoreEntity> MACHINE_CORE_ENTITY = FabricBlockEntityTypeBuilder.create(MachineCoreEntity::new,
BlockContent.MACHINE_CORE_BASIC,
BlockContent.MACHINE_CORE_GOOD
).build();

@Override
public Registry<BlockEntityType<?>> getRegistry() {
Expand Down
Loading

0 comments on commit fca30c0

Please sign in to comment.