-
Notifications
You must be signed in to change notification settings - Fork 3
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
43 changed files
with
1,040 additions
and
109 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
15 changes: 15 additions & 0 deletions
15
src/main/java/io/github/dovecotmc/leadbeyond/LeadBeyondClient.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,15 @@ | ||
package io.github.dovecotmc.leadbeyond; | ||
|
||
import io.github.dovecotmc.leadbeyond.common.reg.BlockReg; | ||
import net.minecraft.client.render.RenderLayer; | ||
import net.minecraft.client.render.RenderLayers; | ||
import net.minecraftforge.api.distmarker.Dist; | ||
import net.minecraftforge.eventbus.api.SubscribeEvent; | ||
import net.minecraftforge.fml.common.Mod; | ||
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent; | ||
|
||
public class LeadBeyondClient { | ||
public static void clientSetup(final FMLClientSetupEvent event) { | ||
RenderLayers.setRenderLayer(BlockReg.TICKET_VENDOR.get(), RenderLayer.getTranslucent()); | ||
} | ||
} |
5 changes: 0 additions & 5 deletions
5
src/main/java/io/github/dovecotmc/leadbeyond/common/block/TicketBarrierBlock.java
This file was deleted.
Oops, something went wrong.
11 changes: 0 additions & 11 deletions
11
src/main/java/io/github/dovecotmc/leadbeyond/common/block/TicketMachineBlock.java
This file was deleted.
Oops, something went wrong.
84 changes: 84 additions & 0 deletions
84
src/main/java/io/github/dovecotmc/leadbeyond/common/block/TicketVendorBlock.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,84 @@ | ||
package io.github.dovecotmc.leadbeyond.common.block; | ||
|
||
import com.simibubi.create.content.contraptions.wrench.IWrenchable; | ||
import io.github.dovecotmc.leadbeyond.common.item.CardItem; | ||
import io.github.dovecotmc.leadbeyond.common.reg.ItemReg; | ||
import io.github.dovecotmc.leadbeyond.common.reg.SoundReg; | ||
import net.minecraft.block.*; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.item.ItemPlacementContext; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.item.Items; | ||
import net.minecraft.nbt.NbtCompound; | ||
import net.minecraft.sound.SoundCategory; | ||
import net.minecraft.state.StateManager; | ||
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.util.shape.VoxelShape; | ||
import net.minecraft.util.shape.VoxelShapes; | ||
import net.minecraft.world.BlockView; | ||
import net.minecraft.world.World; | ||
import org.jetbrains.annotations.NotNull; | ||
|
||
public class TicketVendorBlock extends HorizontalFacingBlock | ||
implements IWrenchable { | ||
public TicketVendorBlock(Settings settings) { | ||
super(settings); | ||
setDefaultState(this.stateManager.getDefaultState().with(FACING, Direction.NORTH)); | ||
} | ||
|
||
@Override | ||
protected void appendProperties(StateManager.Builder<Block, BlockState> stateManager) { | ||
stateManager.add(FACING); | ||
} | ||
|
||
@Override | ||
public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, ShapeContext ctx) { | ||
Direction dir = state.get(FACING); | ||
VoxelShape base = VoxelShapes.cuboid(0.0f, 0.0f, 0.0f, 1.0f, 0.25f, 1.0f); | ||
return switch (dir) { | ||
case NORTH -> VoxelShapes.union(base, | ||
Block.createCuboidShape(0, 4, 12, 16, 16, 16)); | ||
case SOUTH -> VoxelShapes.union(base, | ||
Block.createCuboidShape(0, 4, 0, 16, 16, 4)); | ||
case WEST -> VoxelShapes.union(base, | ||
Block.createCuboidShape(12, 4, 0, 16, 16, 16)); | ||
case EAST -> VoxelShapes.union(base, | ||
Block.createCuboidShape(0, 4, 0, 4, 16, 16)); | ||
default -> VoxelShapes.fullCube(); | ||
}; | ||
} | ||
|
||
@Override | ||
public BlockState getPlacementState(ItemPlacementContext ctx) { | ||
return this.getDefaultState().with(FACING, ctx.getPlayerFacing().getOpposite()); | ||
} | ||
|
||
@Override | ||
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) { | ||
if (world.isClient()) return ActionResult.SUCCESS; | ||
if (player.getStackInHand(hand).isOf(Items.EMERALD)) { | ||
player.getStackInHand(hand).decrement(1); | ||
if (getStackInOtherHand(player, hand).getItem() instanceof CardItem) { | ||
world.playSound(null, pos, SoundReg.BEEP_TICKET_VENDOR.get(), SoundCategory.BLOCKS, 1f, 1f); | ||
NbtCompound nbt = getStackInOtherHand(player, hand).getOrCreateSubNbt("cardInfo"); | ||
nbt.putLong("money", nbt.getLong("money") + 100); | ||
} else { | ||
world.playSound(null, pos, SoundReg.TICKET_OUT.get(), SoundCategory.BLOCKS, 1f, 1f); | ||
player.giveItemStack(ItemReg.TICKET.get().getDefaultStack().copy()); | ||
} | ||
return ActionResult.SUCCESS; | ||
} | ||
return super.onUse(state, world, pos, player, hand, hit); | ||
} | ||
|
||
private static ItemStack getStackInOtherHand(PlayerEntity player, @NotNull Hand hand) { | ||
return switch (hand) { | ||
case MAIN_HAND -> player.getOffHandStack(); | ||
case OFF_HAND -> player.getMainHandStack(); | ||
}; | ||
} | ||
} |
181 changes: 181 additions & 0 deletions
181
src/main/java/io/github/dovecotmc/leadbeyond/common/block/TurnstileBlock.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,181 @@ | ||
package io.github.dovecotmc.leadbeyond.common.block; | ||
|
||
import com.simibubi.create.content.contraptions.wrench.IWrenchable; | ||
import com.simibubi.create.content.contraptions.wrench.WrenchItem; | ||
import io.github.dovecotmc.leadbeyond.common.item.CardItem; | ||
import io.github.dovecotmc.leadbeyond.common.item.TicketItem; | ||
import io.github.dovecotmc.leadbeyond.common.reg.BlockEntityReg; | ||
import io.github.dovecotmc.leadbeyond.common.reg.SoundReg; | ||
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.entity.player.PlayerEntity; | ||
import net.minecraft.item.ItemPlacementContext; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.item.ItemUsageContext; | ||
import net.minecraft.nbt.NbtCompound; | ||
import net.minecraft.sound.SoundCategory; | ||
import net.minecraft.state.StateManager; | ||
import net.minecraft.state.property.BooleanProperty; | ||
import net.minecraft.state.property.DirectionProperty; | ||
import net.minecraft.state.property.Properties; | ||
import net.minecraft.text.TranslatableText; | ||
import net.minecraft.util.ActionResult; | ||
import net.minecraft.util.BlockMirror; | ||
import net.minecraft.util.BlockRotation; | ||
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.util.shape.VoxelShape; | ||
import net.minecraft.util.shape.VoxelShapes; | ||
import net.minecraft.world.BlockView; | ||
import net.minecraft.world.World; | ||
import org.jetbrains.annotations.NotNull; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public class TurnstileBlock extends BlockWithEntity | ||
implements IWrenchable { | ||
public static final DirectionProperty FACING = Properties.HORIZONTAL_FACING; | ||
public static final BooleanProperty OPEN = BooleanProperty.of("open"); | ||
|
||
public TurnstileBlock(Settings arg) { | ||
super(arg); | ||
setDefaultState(this.stateManager.getDefaultState() | ||
.with(FACING, Direction.NORTH) | ||
.with(OPEN, false)); | ||
} | ||
|
||
@Override | ||
public BlockRenderType getRenderType(BlockState state) { | ||
return BlockRenderType.MODEL; | ||
} | ||
|
||
public BlockState rotate(BlockState state, BlockRotation rotation) { | ||
return state.with(FACING, rotation.rotate(state.get(FACING))); | ||
} | ||
|
||
public BlockState mirror(BlockState state, BlockMirror mirror) { | ||
return state.rotate(mirror.getRotation(state.get(FACING))); | ||
} | ||
|
||
@Override | ||
protected void appendProperties(StateManager.Builder<Block, BlockState> stateManager) { | ||
stateManager.add(FACING).add(OPEN); | ||
} | ||
|
||
@Override | ||
public BlockState getPlacementState(ItemPlacementContext ctx) { | ||
return this.getDefaultState() | ||
.with(FACING, ctx.getPlayerFacing().getOpposite()) | ||
.with(OPEN, false); | ||
} | ||
|
||
@Override | ||
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) { | ||
if (world.isClient()) return ActionResult.SUCCESS; | ||
ItemStack stack = player.getStackInHand(hand); | ||
BlockEntity be = world.getBlockEntity(pos); | ||
if (be instanceof TurnstileBlockEntity turnstile) { | ||
if (!turnstile.exit) { | ||
if (stack.getItem() instanceof TicketItem) { | ||
NbtCompound nbt = stack.getOrCreateSubNbt("ticketInfo"); | ||
if (!nbt.getBoolean("used")) { | ||
nbt.putBoolean("used", true); | ||
turnstile.setTimer(60); | ||
world.playSound(null, pos, SoundReg.BEEP_TURNSTILE.get(), SoundCategory.BLOCKS, 1f, 1f); | ||
return ActionResult.SUCCESS; | ||
} | ||
} else if (stack.getItem() instanceof CardItem) { | ||
NbtCompound nbt = stack.getOrCreateSubNbt("cardInfo"); | ||
if (nbt.getLong("money") >= 100) { | ||
nbt.putLong("money", nbt.getLong("money") - 100); | ||
turnstile.setTimer(60); | ||
world.playSound(null, pos, SoundReg.BEEP_TURNSTILE.get(), SoundCategory.BLOCKS, 1f, 1f); | ||
return ActionResult.SUCCESS; | ||
} | ||
} | ||
} else if (!(stack.getItem() instanceof WrenchItem)) { | ||
turnstile.setTimer(60); | ||
world.playSound(null, pos, SoundReg.BEEP_TURNSTILE.get(), SoundCategory.BLOCKS, 1f, 1f); | ||
return ActionResult.SUCCESS; | ||
} | ||
} | ||
return super.onUse(state, world, pos, player, hand, hit); | ||
} | ||
|
||
@Override | ||
public ActionResult onWrenched(BlockState state, @NotNull ItemUsageContext context) { | ||
World world = context.getWorld(); | ||
PlayerEntity player = context.getPlayer(); | ||
if (player != null) { | ||
BlockEntity be = world.getBlockEntity(context.getBlockPos()); | ||
if (be instanceof TurnstileBlockEntity turnstile) { | ||
turnstile.exit = !turnstile.exit; | ||
player.sendMessage(new TranslatableText("message.lead_beyond.set_exit." + turnstile.exit), true); | ||
return ActionResult.SUCCESS; | ||
} | ||
} | ||
return ActionResult.PASS; | ||
} | ||
|
||
@Override | ||
public VoxelShape getCollisionShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) { | ||
Direction dir = state.get(FACING); | ||
boolean open = state.get(OPEN); | ||
VoxelShape nsBarrier = Block.createCuboidShape(0, 0, 6, 16, 24, 10); | ||
VoxelShape ewBarrier = Block.createCuboidShape(6, 0, 0, 10, 24, 16); | ||
return switch (dir) { | ||
case SOUTH -> open ? VoxelShapes.union(Block.createCuboidShape(0, 0, 0, 3.5, 14, 16), | ||
Block.createCuboidShape(15, 0, 0, 16, 14, 16)) | ||
: VoxelShapes.union(Block.createCuboidShape(0, 0, 0, 3.5, 24, 16), | ||
Block.createCuboidShape(15, 0, 0, 16, 24, 16), | ||
nsBarrier); | ||
case NORTH -> open ? VoxelShapes.union(Block.createCuboidShape(0, 0, 0, 1, 14, 16), | ||
Block.createCuboidShape(12.5, 0, 0, 16, 14, 16)) | ||
: VoxelShapes.union(Block.createCuboidShape(0, 0, 0, 1, 24, 16), | ||
Block.createCuboidShape(12.5, 0, 0, 16, 24, 16), | ||
nsBarrier); | ||
case EAST -> open ? VoxelShapes.union(Block.createCuboidShape(0, 0, 0, 16, 14, 1), | ||
Block.createCuboidShape(0, 0, 12.5, 16, 14, 16)) | ||
: VoxelShapes.union(Block.createCuboidShape(0, 0, 0, 16, 24, 1), | ||
Block.createCuboidShape(0, 0, 12.5, 16, 24, 16), | ||
ewBarrier); | ||
case WEST -> open ? VoxelShapes.union(Block.createCuboidShape(0, 0, 0, 16, 14, 3.5), | ||
Block.createCuboidShape(0, 0, 15, 16, 14, 16)) | ||
: VoxelShapes.union(Block.createCuboidShape(0, 0, 0, 16, 24, 3.5), | ||
Block.createCuboidShape(0, 0, 15, 16, 24, 16), | ||
ewBarrier); | ||
default -> VoxelShapes.fullCube(); | ||
}; | ||
} | ||
|
||
@Override | ||
public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, ShapeContext ctx) { | ||
Direction dir = state.get(FACING); | ||
return switch (dir) { | ||
case SOUTH -> VoxelShapes.union(Block.createCuboidShape(0, 0, 0, 3.5, 14, 16), | ||
Block.createCuboidShape(15, 0, 0, 16, 14, 16)); | ||
case NORTH -> VoxelShapes.union(Block.createCuboidShape(0, 0, 0, 1, 14, 16), | ||
Block.createCuboidShape(12.5, 0, 0, 16, 14, 16)); | ||
case EAST -> VoxelShapes.union(Block.createCuboidShape(0, 0, 0, 16, 14, 1), | ||
Block.createCuboidShape(0, 0, 12.5, 16, 14, 16)); | ||
case WEST -> VoxelShapes.union(Block.createCuboidShape(0, 0, 0, 16, 14, 3.5), | ||
Block.createCuboidShape(0, 0, 15, 16, 14, 16)); | ||
default -> VoxelShapes.fullCube(); | ||
}; | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public BlockEntity createBlockEntity(BlockPos pos, BlockState state) { | ||
return new TurnstileBlockEntity(pos, state); | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(World world, BlockState state, BlockEntityType<T> type) { | ||
return checkType(type, BlockEntityReg.TURNSTILE.get(), TurnstileBlockEntity::tick); | ||
} | ||
} |
Oops, something went wrong.