-
Notifications
You must be signed in to change notification settings - Fork 6
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
10 changed files
with
221 additions
and
2 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
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
56 changes: 56 additions & 0 deletions
56
src/main/java/dev/enjarai/minitardis/block/console/ConsoleLeverBlock.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,56 @@ | ||
package dev.enjarai.minitardis.block.console; | ||
|
||
import dev.enjarai.minitardis.block.TardisAware; | ||
import dev.enjarai.minitardis.component.TardisControl; | ||
import eu.pb4.polymer.core.api.block.PolymerBlock; | ||
import net.minecraft.block.Block; | ||
import net.minecraft.block.BlockState; | ||
import net.minecraft.block.Blocks; | ||
import net.minecraft.block.LeverBlock; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.util.math.Direction; | ||
import net.minecraft.world.BlockView; | ||
import net.minecraft.world.World; | ||
|
||
import java.util.function.BiConsumer; | ||
|
||
public class ConsoleLeverBlock extends LeverBlock implements PolymerBlock, TardisAware { | ||
private final BiConsumer<TardisControl, Boolean> controlInput; | ||
|
||
public ConsoleLeverBlock(Settings settings, BiConsumer<TardisControl, Boolean> controlInput) { | ||
super(settings); | ||
this.controlInput = controlInput; | ||
} | ||
|
||
@Override | ||
public BlockState togglePower(BlockState state, World world, BlockPos pos) { | ||
var state2 = super.togglePower(state, world, pos); | ||
getTardis(world).ifPresent(tardis -> controlInput.accept(tardis.getControls(), state2.get(POWERED))); | ||
return state2; | ||
} | ||
|
||
@Override | ||
public int getWeakRedstonePower(BlockState state, BlockView world, BlockPos pos, Direction direction) { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public int getStrongRedstonePower(BlockState state, BlockView world, BlockPos pos, Direction direction) { | ||
return 0; | ||
} | ||
|
||
@Override | ||
public boolean emitsRedstonePower(BlockState state) { | ||
return false; | ||
} | ||
|
||
@Override | ||
public Block getPolymerBlock(BlockState state) { | ||
return Blocks.LEVER; | ||
} | ||
|
||
@Override | ||
public BlockState getPolymerBlockState(BlockState state) { | ||
return Blocks.LEVER.getStateWithProperties(state); | ||
} | ||
} |
99 changes: 99 additions & 0 deletions
99
src/main/java/dev/enjarai/minitardis/block/console/ConsoleScreenBlock.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,99 @@ | ||
package dev.enjarai.minitardis.block.console; | ||
|
||
import dev.enjarai.minitardis.block.ModBlocks; | ||
import dev.enjarai.minitardis.block.TardisAware; | ||
import eu.pb4.polymer.core.api.block.PolymerBlock; | ||
import eu.pb4.polymer.virtualentity.api.BlockWithElementHolder; | ||
import eu.pb4.polymer.virtualentity.api.ElementHolder; | ||
import eu.pb4.polymer.virtualentity.api.elements.TextDisplayElement; | ||
import net.minecraft.block.*; | ||
import net.minecraft.block.entity.BlockEntity; | ||
import net.minecraft.block.entity.BlockEntityTicker; | ||
import net.minecraft.block.entity.BlockEntityType; | ||
import net.minecraft.server.world.ServerWorld; | ||
import net.minecraft.state.StateManager; | ||
import net.minecraft.state.property.DirectionProperty; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.util.math.Direction; | ||
import net.minecraft.world.World; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public class ConsoleScreenBlock extends BlockWithEntity implements PolymerBlock, TardisAware, BlockWithElementHolder { | ||
public static final DirectionProperty FACING = HorizontalFacingBlock.FACING; | ||
|
||
public ConsoleScreenBlock(Settings settings) { | ||
super(settings); | ||
setDefaultState(getStateManager().getDefaultState().with(FACING, Direction.NORTH)); | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public BlockEntity createBlockEntity(BlockPos pos, BlockState state) { | ||
return new ConsoleScreenBlockEntity(pos, state); | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(World world, BlockState state, BlockEntityType<T> type) { | ||
return validateTicker(type, ModBlocks.CONSOLE_SCREEN_ENTITY, (world1, pos, state1, blockEntity) -> blockEntity.tick(world1, pos, state1)); | ||
} | ||
|
||
@Override | ||
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) { | ||
builder.add(FACING); | ||
} | ||
|
||
@Override | ||
public Block getPolymerBlock(BlockState state) { | ||
return Blocks.OAK_WALL_SIGN; | ||
} | ||
|
||
@Override | ||
public BlockState getPolymerBlockState(BlockState state) { | ||
return getPolymerBlock(state).getStateWithProperties(state); | ||
} | ||
|
||
@Override | ||
public boolean tickElementHolder(ServerWorld world, BlockPos pos, BlockState initialBlockState) { | ||
return true; | ||
} | ||
|
||
@Override | ||
public @Nullable ElementHolder createElementHolder(ServerWorld world, BlockPos pos, BlockState initialBlockState) { | ||
var tardisOptional = getTardis(world); | ||
if (tardisOptional.isPresent()) { | ||
var tardis = tardisOptional.get(); | ||
var textDisplay = new TextDisplayElement(); | ||
|
||
return new ElementHolder() { | ||
{ | ||
addElement(textDisplay); | ||
} | ||
|
||
@Override | ||
protected void onTick() { | ||
|
||
} | ||
|
||
private void update() { | ||
textDisplay.setText(tardis.getState().getName()); | ||
} | ||
}; | ||
} | ||
return null; | ||
} | ||
|
||
// @Override | ||
// public void onPolymerBlockSend(BlockState blockState, BlockPos.Mutable pos, ServerPlayerEntity player) { | ||
// var main = new NbtCompound(); | ||
// main.putString("id", "minecraft:sign"); | ||
// main.putInt("x", pos.getX()); | ||
// main.putInt("y", pos.getY()); | ||
// main.putInt("z", pos.getZ()); | ||
// main.putBoolean("is_waxed", true); | ||
// var frontText = new NbtCompound(); | ||
// var messages = new NbtList(); | ||
// messages.add() | ||
// player.networkHandler.sendPacket(PolymerBlockUtils.createBlockEntityPacket(pos.toImmutable(), BlockEntityType.SIGN, main)); | ||
// } | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/dev/enjarai/minitardis/block/console/ConsoleScreenBlockEntity.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,18 @@ | ||
package dev.enjarai.minitardis.block.console; | ||
|
||
import dev.enjarai.minitardis.block.ModBlocks; | ||
import dev.enjarai.minitardis.block.TardisAware; | ||
import net.minecraft.block.BlockState; | ||
import net.minecraft.block.entity.BlockEntity; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.world.World; | ||
|
||
public class ConsoleScreenBlockEntity extends BlockEntity implements TardisAware { | ||
public ConsoleScreenBlockEntity(BlockPos pos, BlockState state) { | ||
super(ModBlocks.CONSOLE_SCREEN_ENTITY, pos, state); | ||
} | ||
|
||
public void tick(World world, BlockPos pos, BlockState state) { | ||
|
||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package dev.enjarai.minitardis.item; | ||
|
||
import dev.enjarai.minitardis.block.ModBlocks; | ||
import eu.pb4.polymer.core.api.block.PolymerBlock; | ||
import eu.pb4.polymer.core.api.item.PolymerBlockItem; | ||
import net.fabricmc.fabric.api.item.v1.FabricItemSettings; | ||
import net.minecraft.registry.Registries; | ||
import net.minecraft.registry.Registry; | ||
|
||
public class ModItems { | ||
public static void load() { | ||
ModBlocks.ITEM_BLOCKS.forEach(block -> { | ||
if (block instanceof PolymerBlock polymerBlock) { | ||
var id = Registries.BLOCK.getId(block); | ||
var polymerItem = polymerBlock.getPolymerBlock(block.getDefaultState()).asItem(); | ||
Registry.register(Registries.ITEM, id, new PolymerBlockItem(block, new FabricItemSettings(), polymerItem)); | ||
} | ||
}); | ||
} | ||
} |