-
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
35 changed files
with
3,367 additions
and
58 deletions.
There are no files selected for viewing
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
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/laser_arm_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/laser_arm_block" | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
src/main/generated/assets/oritech/models/item/laser_arm_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/laser_arm_block" | ||
} |
6 changes: 6 additions & 0 deletions
6
src/main/generated/assets/oritech/models/item/target_designator.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:item/generated", | ||
"textures": { | ||
"layer0": "oritech:item/target_designator" | ||
} | ||
} |
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
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
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
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
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
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
114 changes: 114 additions & 0 deletions
114
src/main/java/rearth/oritech/block/blocks/machines/interaction/LaserArmBlock.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,114 @@ | ||
package rearth.oritech.block.blocks.machines.interaction; | ||
|
||
import com.mojang.serialization.MapCodec; | ||
import net.fabricmc.fabric.api.screenhandler.v1.ExtendedScreenHandlerFactory; | ||
import net.minecraft.block.*; | ||
import net.minecraft.block.AbstractBlock.Settings; | ||
import net.minecraft.block.entity.BlockEntity; | ||
import net.minecraft.block.entity.BlockEntityTicker; | ||
import net.minecraft.block.entity.BlockEntityType; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.item.ItemPlacementContext; | ||
import net.minecraft.state.StateManager; | ||
import net.minecraft.state.property.BooleanProperty; | ||
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; | ||
import org.jetbrains.annotations.Nullable; | ||
import rearth.oritech.block.base.entity.FrameInteractionBlockEntity; | ||
import rearth.oritech.block.base.entity.UpgradableMachineBlockEntity; | ||
import rearth.oritech.block.entity.machines.interaction.DestroyerBlockEntity; | ||
import rearth.oritech.block.entity.machines.interaction.LaserArmBlockEntity; | ||
import rearth.oritech.network.NetworkContent; | ||
import rearth.oritech.util.MachineAddonController; | ||
import rearth.oritech.util.MultiblockMachineController; | ||
|
||
import java.util.Objects; | ||
|
||
public class LaserArmBlock extends Block implements BlockEntityProvider { | ||
|
||
public static final BooleanProperty ASSEMBLED = BooleanProperty.of("machine_assembled"); | ||
|
||
public LaserArmBlock(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 LaserArmBlockEntity laserArm)) { | ||
return ActionResult.SUCCESS; | ||
} | ||
|
||
var wasAssembled = state.get(ASSEMBLED); | ||
var isAssembled = laserArm.initMultiblock(state); | ||
|
||
// first time created | ||
if (isAssembled && !wasAssembled) { | ||
NetworkContent.MACHINE_CHANNEL.serverHandle(entity).send(new NetworkContent.MachineSetupEventPacket(pos)); | ||
return ActionResult.SUCCESS; | ||
} | ||
|
||
if (!isAssembled) { | ||
player.sendMessage(Text.literal("Machine is not assembled. Please add missing core blocks")); | ||
return ActionResult.SUCCESS; | ||
} | ||
|
||
laserArm.initAddons(); | ||
laserArm.testTarget(state); | ||
|
||
} | ||
|
||
return ActionResult.SUCCESS; | ||
} | ||
|
||
@Override | ||
public BlockState onBreak(World world, BlockPos pos, BlockState state, PlayerEntity player) { | ||
|
||
if (!world.isClient() && state.get(ASSEMBLED)) { | ||
|
||
var entity = world.getBlockEntity(pos); | ||
if (entity instanceof MultiblockMachineController machineEntity) { | ||
machineEntity.onControllerBroken(); | ||
} | ||
} | ||
|
||
return super.onBreak(world, pos, state, player); | ||
} | ||
|
||
@Override | ||
public BlockRenderType getRenderType(BlockState state) { | ||
return BlockRenderType.ENTITYBLOCK_ANIMATED; | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public BlockEntity createBlockEntity(BlockPos pos, BlockState state) { | ||
return new LaserArmBlockEntity(pos, state); | ||
} | ||
|
||
@SuppressWarnings({"rawtypes", "unchecked"}) | ||
@Nullable | ||
@Override | ||
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(World world, BlockState state, BlockEntityType<T> type) { | ||
return (world1, pos, state1, blockEntity) -> { | ||
if (blockEntity instanceof BlockEntityTicker ticker) | ||
ticker.tick(world1, pos, state1, blockEntity); | ||
}; | ||
} | ||
} |
Oops, something went wrong.