-
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.
Add large energy storage, add energy storage UI
- Loading branch information
Showing
24 changed files
with
683 additions
and
30 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
7 changes: 7 additions & 0 deletions
7
src/main/generated/assets/oritech/blockstates/large_storage_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/large_storage_block" | ||
} | ||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
src/main/generated/assets/oritech/models/item/large_storage_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/large_storage_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
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
89 changes: 89 additions & 0 deletions
89
src/main/java/rearth/oritech/block/blocks/machines/storage/LargeStorageBlock.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,89 @@ | ||
package rearth.oritech.block.blocks.machines.storage; | ||
|
||
import net.minecraft.block.Block; | ||
import net.minecraft.block.BlockState; | ||
import net.minecraft.block.entity.BlockEntity; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.item.ItemPlacementContext; | ||
import net.minecraft.state.StateManager; | ||
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.world.World; | ||
import org.jetbrains.annotations.Nullable; | ||
import rearth.oritech.block.entity.machines.storage.LargeStorageBlockEntity; | ||
import rearth.oritech.util.MultiblockMachineController; | ||
|
||
import java.util.Objects; | ||
|
||
import static rearth.oritech.block.base.block.MultiblockMachine.ASSEMBLED; | ||
|
||
public class LargeStorageBlock extends SmallStorageBlock { | ||
|
||
public LargeStorageBlock(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 @Nullable BlockEntity createBlockEntity(BlockPos pos, BlockState state) { | ||
return new LargeStorageBlockEntity(pos, state); | ||
} | ||
|
||
@Override | ||
public @Nullable BlockState getPlacementState(ItemPlacementContext ctx) { | ||
return Objects.requireNonNull(super.getPlacementState(ctx)).with(SmallStorageBlock.TARGET_DIR, ctx.getHorizontalPlayerFacing().getOpposite()); | ||
} | ||
|
||
@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 MultiblockMachineController machineEntity)) { | ||
return ActionResult.SUCCESS; | ||
} | ||
|
||
var wasAssembled = state.get(ASSEMBLED); | ||
|
||
var isAssembled = machineEntity.initMultiblock(state); | ||
|
||
// first time created | ||
if (isAssembled && !wasAssembled) { | ||
// NetworkContent.MACHINE_CHANNEL.serverHandle(machineEntity).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; | ||
} | ||
|
||
} | ||
|
||
return super.onUse(state, world, pos, player, hand, hit); | ||
} | ||
|
||
@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); | ||
} | ||
} |
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.