-
Notifications
You must be signed in to change notification settings - Fork 22
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
18 changed files
with
319 additions
and
77 deletions.
There are no files selected for viewing
5 changes: 4 additions & 1 deletion
5
src/main/generated/.cache/19c08d24c255c2719fbb8ac01f9dff290b763461
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
src/main/generated/assets/oritech/blockstates/assembler_block.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"variants": { | ||
"": { | ||
"model": "oritech:block/assembler_block" | ||
} | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
src/main/generated/assets/oritech/models/block/assembler_block.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
{ | ||
"parent": "minecraft:block/cube_all", | ||
"textures": { | ||
"all": "oritech:block/assembler_block" | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
src/main/generated/assets/oritech/models/item/assembler_block.json
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
{ | ||
"parent": "oritech:block/assembler_block" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
54 changes: 54 additions & 0 deletions
54
src/main/java/rearth/oritech/block/base/MultiblockMachine.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
package rearth.oritech.block.base; | ||
|
||
import net.minecraft.block.Block; | ||
import net.minecraft.block.BlockState; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.state.StateManager; | ||
import net.minecraft.state.property.BooleanProperty; | ||
import net.minecraft.state.property.IntProperty; | ||
import net.minecraft.state.property.Properties; | ||
import net.minecraft.text.Text; | ||
import net.minecraft.util.ActionResult; | ||
import net.minecraft.util.Hand; | ||
import net.minecraft.util.hit.BlockHitResult; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.util.math.Direction; | ||
import net.minecraft.world.World; | ||
|
||
public abstract class MultiblockMachine extends MachineBlock { | ||
|
||
public static final BooleanProperty ASSEMBLED = BooleanProperty.of("machine_assembled"); | ||
|
||
public MultiblockMachine(Settings settings) { | ||
super(settings); | ||
setDefaultState(getDefaultState().with(ASSEMBLED, false)); | ||
} | ||
|
||
@Override | ||
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) { | ||
super.appendProperties(builder); | ||
builder.add(ASSEMBLED); | ||
} | ||
|
||
@Override | ||
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) { | ||
|
||
if (!world.isClient) { | ||
|
||
var entity = world.getBlockEntity(pos); | ||
if (!(entity instanceof MultiblockMachineEntity machineEntity)) { | ||
return ActionResult.FAIL; | ||
} | ||
|
||
var isAssembled = machineEntity.initMultiblock(state); | ||
|
||
if (!isAssembled) { | ||
player.sendMessage(Text.literal("Machine is not assembled")); | ||
return ActionResult.FAIL; | ||
} | ||
|
||
} | ||
|
||
return super.onUse(state, world, pos, player, hand, hit); | ||
} | ||
} |
107 changes: 107 additions & 0 deletions
107
src/main/java/rearth/oritech/block/base/MultiblockMachineEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
package rearth.oritech.block.base; | ||
|
||
import net.minecraft.block.BlockState; | ||
import net.minecraft.block.entity.BlockEntityType; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.util.math.Direction; | ||
import net.minecraft.util.math.Vec3d; | ||
import net.minecraft.util.math.Vec3i; | ||
import rearth.oritech.block.custom.MachineCoreBlock; | ||
import rearth.oritech.client.init.ParticleContent; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
import java.util.Objects; | ||
|
||
public abstract class MultiblockMachineEntity extends MachineBlockEntity { | ||
|
||
public MultiblockMachineEntity(BlockEntityType<?> type, BlockPos pos, BlockState state) { | ||
super(type, pos, state); | ||
} | ||
|
||
|
||
// positive x = forward | ||
// positive y = up | ||
// positive z = right? | ||
public abstract List<Vec3i> getCorePositions(); | ||
|
||
public boolean initMultiblock(BlockState state) { | ||
|
||
// check if multiblock is already created, if so cancel | ||
// call method the get a list of relative positions | ||
// check all positions if the blocks there extend MachineCoreBlock | ||
// if so, add them to list of used blocks | ||
// if not (e.g. block wrong type or air), draw a small particle to indicate the missing position | ||
// when all blocks are valid, multiblock is active | ||
// update all multiblocks state to USED=true, write controller position to block state | ||
|
||
if (state.get(MultiblockMachine.ASSEMBLED)) return true; | ||
|
||
var ownFacing = getFacing(); | ||
|
||
var targetPositions = getCorePositions(); | ||
var coreBlocks = new ArrayList<MultiBlockElement>(targetPositions.size()); | ||
|
||
for (var targetPosition : targetPositions) { | ||
var rotatedPos = rotatePosition(targetPosition, ownFacing); | ||
var checkPos = pos.add(rotatedPos); | ||
var checkState = Objects.requireNonNull(world).getBlockState(checkPos); | ||
|
||
var blockType = checkState.getBlock(); | ||
if (blockType instanceof MachineCoreBlock coreBlock) { | ||
coreBlocks.add(new MultiBlockElement(checkState, coreBlock, checkPos)); | ||
} else { | ||
highlightBlock(checkPos); | ||
} | ||
} | ||
|
||
if (targetPositions.size() == coreBlocks.size()) { | ||
// valid | ||
for (var core : coreBlocks) { | ||
var offset = pos.subtract(core.pos); | ||
var newState = core.state | ||
.with(MachineCoreBlock.USED, true) | ||
.with(MachineCoreBlock.CONTROLLER_X, offset.getX() + 4) | ||
.with(MachineCoreBlock.CONTROLLER_Y, offset.getY() + 4) | ||
.with(MachineCoreBlock.CONTROLLER_Z, offset.getZ() + 4); | ||
world.setBlockState(core.pos, newState); | ||
} | ||
|
||
Objects.requireNonNull(world).setBlockState(pos, state.with(MultiblockMachine.ASSEMBLED, true)); | ||
System.out.println("multiblock valid"); | ||
return true; | ||
} else { | ||
// invalid | ||
System.out.println("multiblock invalid"); | ||
return false; | ||
} | ||
|
||
} | ||
|
||
public void onCoreBroken(BlockPos corePos, BlockState coreState) { | ||
|
||
System.out.println("registering broken core!"); | ||
|
||
// set assembled to false | ||
// go through all existing cores | ||
// set used to false | ||
|
||
} | ||
|
||
private void highlightBlock(BlockPos block) { | ||
ParticleContent.HIGHLIGHT_BLOCK.spawn(world, Vec3d.of(block), null); | ||
} | ||
|
||
private Vec3i rotatePosition(Vec3i relativePos, Direction facing) { | ||
return switch (facing) { | ||
case NORTH -> new BlockPos(relativePos.getZ(), relativePos.getY(), relativePos.getX()); | ||
case EAST -> new BlockPos(-relativePos.getX(), relativePos.getY(), -relativePos.getZ()); | ||
case SOUTH -> new BlockPos(-relativePos.getZ(), relativePos.getY(), -relativePos.getX()); | ||
case WEST -> new BlockPos(relativePos.getX(), relativePos.getY(), relativePos.getZ()); | ||
default -> relativePos; | ||
}; | ||
} | ||
|
||
private record MultiBlockElement(BlockState state, MachineCoreBlock coreBlock, BlockPos pos) { | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/java/rearth/oritech/block/custom/AssemblerBlock.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package rearth.oritech.block.custom; | ||
|
||
import net.minecraft.block.BlockEntityProvider; | ||
import net.minecraft.block.entity.BlockEntity; | ||
import org.jetbrains.annotations.NotNull; | ||
import rearth.oritech.block.base.MachineBlock; | ||
import rearth.oritech.block.base.MultiblockMachine; | ||
import rearth.oritech.block.entity.AssemblerBlockEntity; | ||
|
||
public class AssemblerBlock extends MultiblockMachine implements BlockEntityProvider { | ||
|
||
public AssemblerBlock(Settings settings) { | ||
super(settings); | ||
} | ||
|
||
@Override | ||
public @NotNull Class<? extends BlockEntity> getBlockEntityType() { | ||
return AssemblerBlockEntity.class; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.