Skip to content

Commit

Permalink
0.1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Flamarine committed Oct 4, 2022
1 parent a8309e8 commit c86bc30
Show file tree
Hide file tree
Showing 43 changed files with 1,040 additions and 109 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ plugins {
sourceCompatibility = targetCompatibility = JavaVersion.VERSION_17

archivesBaseName = project.archives_base_name
version = project.mod_version
version = project.mod_version + "+mc" + project.minecraft_version
group = project.maven_group

loom {
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ loom.platform=forge
yarn_mappings=1.18.2+build.4

# Mod Properties
mod_version=1.0.0
mod_version=0.1.0
maven_group=io.github.dovecotmc
archives_base_name=LeadBeyond
mod_id=lead_beyond
Expand Down
15 changes: 7 additions & 8 deletions src/main/java/io/github/dovecotmc/leadbeyond/LeadBeyond.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
package io.github.dovecotmc.leadbeyond;

import io.github.dovecotmc.leadbeyond.common.reg.ItemReg;
import io.github.dovecotmc.leadbeyond.common.reg.*;
import net.minecraft.util.Identifier;
import net.minecraftforge.common.MinecraftForge;
import net.minecraftforge.eventbus.api.IEventBus;
import net.minecraftforge.eventbus.api.SubscribeEvent;
import net.minecraftforge.fml.common.Mod;
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
import net.minecraftforge.fml.loading.FMLEnvironment;
Expand All @@ -24,17 +22,18 @@ public class LeadBeyond {
public LeadBeyond() {
IEventBus eventBus = FMLJavaModLoadingContext.get().getModEventBus();
ItemReg.ITEM.register(eventBus);
BlockReg.BLOCKS.register(eventBus);
SoundReg.SOUNDS.register(eventBus);
BlockEntityReg.BLOCK_ENTITIES.register(eventBus);
eventBus.addListener(this::commonSetup);
eventBus.addListener(LeadBeyondClient::clientSetup);
MinecraftForge.EVENT_BUS.register(this);
LOGGER.info("Initialized.");
}

@SubscribeEvent
public void commonSetup(final FMLCommonSetupEvent event) {
}

@SubscribeEvent
public void clientSetup(final FMLClientSetupEvent event) {
}

public static @NotNull Identifier id(String name) {
return new Identifier(MODID, name);
}
Expand Down
15 changes: 15 additions & 0 deletions src/main/java/io/github/dovecotmc/leadbeyond/LeadBeyondClient.java
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());
}
}

This file was deleted.

This file was deleted.

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();
};
}
}
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);
}
}
Loading

0 comments on commit c86bc30

Please sign in to comment.