Skip to content

Commit c86bc30

Browse files
committed
0.1.0
1 parent a8309e8 commit c86bc30

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

43 files changed

+1040
-109
lines changed

build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ plugins {
66
sourceCompatibility = targetCompatibility = JavaVersion.VERSION_17
77

88
archivesBaseName = project.archives_base_name
9-
version = project.mod_version
9+
version = project.mod_version + "+mc" + project.minecraft_version
1010
group = project.maven_group
1111

1212
loom {

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ loom.platform=forge
1616
yarn_mappings=1.18.2+build.4
1717

1818
# Mod Properties
19-
mod_version=1.0.0
19+
mod_version=0.1.0
2020
maven_group=io.github.dovecotmc
2121
archives_base_name=LeadBeyond
2222
mod_id=lead_beyond

src/main/java/io/github/dovecotmc/leadbeyond/LeadBeyond.java

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
package io.github.dovecotmc.leadbeyond;
22

3-
import io.github.dovecotmc.leadbeyond.common.reg.ItemReg;
3+
import io.github.dovecotmc.leadbeyond.common.reg.*;
44
import net.minecraft.util.Identifier;
55
import net.minecraftforge.common.MinecraftForge;
66
import net.minecraftforge.eventbus.api.IEventBus;
7-
import net.minecraftforge.eventbus.api.SubscribeEvent;
87
import net.minecraftforge.fml.common.Mod;
9-
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
108
import net.minecraftforge.fml.event.lifecycle.FMLCommonSetupEvent;
119
import net.minecraftforge.fml.javafmlmod.FMLJavaModLoadingContext;
1210
import net.minecraftforge.fml.loading.FMLEnvironment;
@@ -24,17 +22,18 @@ public class LeadBeyond {
2422
public LeadBeyond() {
2523
IEventBus eventBus = FMLJavaModLoadingContext.get().getModEventBus();
2624
ItemReg.ITEM.register(eventBus);
25+
BlockReg.BLOCKS.register(eventBus);
26+
SoundReg.SOUNDS.register(eventBus);
27+
BlockEntityReg.BLOCK_ENTITIES.register(eventBus);
28+
eventBus.addListener(this::commonSetup);
29+
eventBus.addListener(LeadBeyondClient::clientSetup);
2730
MinecraftForge.EVENT_BUS.register(this);
31+
LOGGER.info("Initialized.");
2832
}
2933

30-
@SubscribeEvent
3134
public void commonSetup(final FMLCommonSetupEvent event) {
3235
}
3336

34-
@SubscribeEvent
35-
public void clientSetup(final FMLClientSetupEvent event) {
36-
}
37-
3837
public static @NotNull Identifier id(String name) {
3938
return new Identifier(MODID, name);
4039
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
package io.github.dovecotmc.leadbeyond;
2+
3+
import io.github.dovecotmc.leadbeyond.common.reg.BlockReg;
4+
import net.minecraft.client.render.RenderLayer;
5+
import net.minecraft.client.render.RenderLayers;
6+
import net.minecraftforge.api.distmarker.Dist;
7+
import net.minecraftforge.eventbus.api.SubscribeEvent;
8+
import net.minecraftforge.fml.common.Mod;
9+
import net.minecraftforge.fml.event.lifecycle.FMLClientSetupEvent;
10+
11+
public class LeadBeyondClient {
12+
public static void clientSetup(final FMLClientSetupEvent event) {
13+
RenderLayers.setRenderLayer(BlockReg.TICKET_VENDOR.get(), RenderLayer.getTranslucent());
14+
}
15+
}

src/main/java/io/github/dovecotmc/leadbeyond/common/block/TicketBarrierBlock.java

Lines changed: 0 additions & 5 deletions
This file was deleted.

src/main/java/io/github/dovecotmc/leadbeyond/common/block/TicketMachineBlock.java

Lines changed: 0 additions & 11 deletions
This file was deleted.
Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
package io.github.dovecotmc.leadbeyond.common.block;
2+
3+
import com.simibubi.create.content.contraptions.wrench.IWrenchable;
4+
import io.github.dovecotmc.leadbeyond.common.item.CardItem;
5+
import io.github.dovecotmc.leadbeyond.common.reg.ItemReg;
6+
import io.github.dovecotmc.leadbeyond.common.reg.SoundReg;
7+
import net.minecraft.block.*;
8+
import net.minecraft.entity.player.PlayerEntity;
9+
import net.minecraft.item.ItemPlacementContext;
10+
import net.minecraft.item.ItemStack;
11+
import net.minecraft.item.Items;
12+
import net.minecraft.nbt.NbtCompound;
13+
import net.minecraft.sound.SoundCategory;
14+
import net.minecraft.state.StateManager;
15+
import net.minecraft.util.ActionResult;
16+
import net.minecraft.util.Hand;
17+
import net.minecraft.util.hit.BlockHitResult;
18+
import net.minecraft.util.math.BlockPos;
19+
import net.minecraft.util.math.Direction;
20+
import net.minecraft.util.shape.VoxelShape;
21+
import net.minecraft.util.shape.VoxelShapes;
22+
import net.minecraft.world.BlockView;
23+
import net.minecraft.world.World;
24+
import org.jetbrains.annotations.NotNull;
25+
26+
public class TicketVendorBlock extends HorizontalFacingBlock
27+
implements IWrenchable {
28+
public TicketVendorBlock(Settings settings) {
29+
super(settings);
30+
setDefaultState(this.stateManager.getDefaultState().with(FACING, Direction.NORTH));
31+
}
32+
33+
@Override
34+
protected void appendProperties(StateManager.Builder<Block, BlockState> stateManager) {
35+
stateManager.add(FACING);
36+
}
37+
38+
@Override
39+
public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, ShapeContext ctx) {
40+
Direction dir = state.get(FACING);
41+
VoxelShape base = VoxelShapes.cuboid(0.0f, 0.0f, 0.0f, 1.0f, 0.25f, 1.0f);
42+
return switch (dir) {
43+
case NORTH -> VoxelShapes.union(base,
44+
Block.createCuboidShape(0, 4, 12, 16, 16, 16));
45+
case SOUTH -> VoxelShapes.union(base,
46+
Block.createCuboidShape(0, 4, 0, 16, 16, 4));
47+
case WEST -> VoxelShapes.union(base,
48+
Block.createCuboidShape(12, 4, 0, 16, 16, 16));
49+
case EAST -> VoxelShapes.union(base,
50+
Block.createCuboidShape(0, 4, 0, 4, 16, 16));
51+
default -> VoxelShapes.fullCube();
52+
};
53+
}
54+
55+
@Override
56+
public BlockState getPlacementState(ItemPlacementContext ctx) {
57+
return this.getDefaultState().with(FACING, ctx.getPlayerFacing().getOpposite());
58+
}
59+
60+
@Override
61+
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
62+
if (world.isClient()) return ActionResult.SUCCESS;
63+
if (player.getStackInHand(hand).isOf(Items.EMERALD)) {
64+
player.getStackInHand(hand).decrement(1);
65+
if (getStackInOtherHand(player, hand).getItem() instanceof CardItem) {
66+
world.playSound(null, pos, SoundReg.BEEP_TICKET_VENDOR.get(), SoundCategory.BLOCKS, 1f, 1f);
67+
NbtCompound nbt = getStackInOtherHand(player, hand).getOrCreateSubNbt("cardInfo");
68+
nbt.putLong("money", nbt.getLong("money") + 100);
69+
} else {
70+
world.playSound(null, pos, SoundReg.TICKET_OUT.get(), SoundCategory.BLOCKS, 1f, 1f);
71+
player.giveItemStack(ItemReg.TICKET.get().getDefaultStack().copy());
72+
}
73+
return ActionResult.SUCCESS;
74+
}
75+
return super.onUse(state, world, pos, player, hand, hit);
76+
}
77+
78+
private static ItemStack getStackInOtherHand(PlayerEntity player, @NotNull Hand hand) {
79+
return switch (hand) {
80+
case MAIN_HAND -> player.getOffHandStack();
81+
case OFF_HAND -> player.getMainHandStack();
82+
};
83+
}
84+
}
Lines changed: 181 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,181 @@
1+
package io.github.dovecotmc.leadbeyond.common.block;
2+
3+
import com.simibubi.create.content.contraptions.wrench.IWrenchable;
4+
import com.simibubi.create.content.contraptions.wrench.WrenchItem;
5+
import io.github.dovecotmc.leadbeyond.common.item.CardItem;
6+
import io.github.dovecotmc.leadbeyond.common.item.TicketItem;
7+
import io.github.dovecotmc.leadbeyond.common.reg.BlockEntityReg;
8+
import io.github.dovecotmc.leadbeyond.common.reg.SoundReg;
9+
import net.minecraft.block.*;
10+
import net.minecraft.block.entity.BlockEntity;
11+
import net.minecraft.block.entity.BlockEntityTicker;
12+
import net.minecraft.block.entity.BlockEntityType;
13+
import net.minecraft.entity.player.PlayerEntity;
14+
import net.minecraft.item.ItemPlacementContext;
15+
import net.minecraft.item.ItemStack;
16+
import net.minecraft.item.ItemUsageContext;
17+
import net.minecraft.nbt.NbtCompound;
18+
import net.minecraft.sound.SoundCategory;
19+
import net.minecraft.state.StateManager;
20+
import net.minecraft.state.property.BooleanProperty;
21+
import net.minecraft.state.property.DirectionProperty;
22+
import net.minecraft.state.property.Properties;
23+
import net.minecraft.text.TranslatableText;
24+
import net.minecraft.util.ActionResult;
25+
import net.minecraft.util.BlockMirror;
26+
import net.minecraft.util.BlockRotation;
27+
import net.minecraft.util.Hand;
28+
import net.minecraft.util.hit.BlockHitResult;
29+
import net.minecraft.util.math.BlockPos;
30+
import net.minecraft.util.math.Direction;
31+
import net.minecraft.util.shape.VoxelShape;
32+
import net.minecraft.util.shape.VoxelShapes;
33+
import net.minecraft.world.BlockView;
34+
import net.minecraft.world.World;
35+
import org.jetbrains.annotations.NotNull;
36+
import org.jetbrains.annotations.Nullable;
37+
38+
public class TurnstileBlock extends BlockWithEntity
39+
implements IWrenchable {
40+
public static final DirectionProperty FACING = Properties.HORIZONTAL_FACING;
41+
public static final BooleanProperty OPEN = BooleanProperty.of("open");
42+
43+
public TurnstileBlock(Settings arg) {
44+
super(arg);
45+
setDefaultState(this.stateManager.getDefaultState()
46+
.with(FACING, Direction.NORTH)
47+
.with(OPEN, false));
48+
}
49+
50+
@Override
51+
public BlockRenderType getRenderType(BlockState state) {
52+
return BlockRenderType.MODEL;
53+
}
54+
55+
public BlockState rotate(BlockState state, BlockRotation rotation) {
56+
return state.with(FACING, rotation.rotate(state.get(FACING)));
57+
}
58+
59+
public BlockState mirror(BlockState state, BlockMirror mirror) {
60+
return state.rotate(mirror.getRotation(state.get(FACING)));
61+
}
62+
63+
@Override
64+
protected void appendProperties(StateManager.Builder<Block, BlockState> stateManager) {
65+
stateManager.add(FACING).add(OPEN);
66+
}
67+
68+
@Override
69+
public BlockState getPlacementState(ItemPlacementContext ctx) {
70+
return this.getDefaultState()
71+
.with(FACING, ctx.getPlayerFacing().getOpposite())
72+
.with(OPEN, false);
73+
}
74+
75+
@Override
76+
public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
77+
if (world.isClient()) return ActionResult.SUCCESS;
78+
ItemStack stack = player.getStackInHand(hand);
79+
BlockEntity be = world.getBlockEntity(pos);
80+
if (be instanceof TurnstileBlockEntity turnstile) {
81+
if (!turnstile.exit) {
82+
if (stack.getItem() instanceof TicketItem) {
83+
NbtCompound nbt = stack.getOrCreateSubNbt("ticketInfo");
84+
if (!nbt.getBoolean("used")) {
85+
nbt.putBoolean("used", true);
86+
turnstile.setTimer(60);
87+
world.playSound(null, pos, SoundReg.BEEP_TURNSTILE.get(), SoundCategory.BLOCKS, 1f, 1f);
88+
return ActionResult.SUCCESS;
89+
}
90+
} else if (stack.getItem() instanceof CardItem) {
91+
NbtCompound nbt = stack.getOrCreateSubNbt("cardInfo");
92+
if (nbt.getLong("money") >= 100) {
93+
nbt.putLong("money", nbt.getLong("money") - 100);
94+
turnstile.setTimer(60);
95+
world.playSound(null, pos, SoundReg.BEEP_TURNSTILE.get(), SoundCategory.BLOCKS, 1f, 1f);
96+
return ActionResult.SUCCESS;
97+
}
98+
}
99+
} else if (!(stack.getItem() instanceof WrenchItem)) {
100+
turnstile.setTimer(60);
101+
world.playSound(null, pos, SoundReg.BEEP_TURNSTILE.get(), SoundCategory.BLOCKS, 1f, 1f);
102+
return ActionResult.SUCCESS;
103+
}
104+
}
105+
return super.onUse(state, world, pos, player, hand, hit);
106+
}
107+
108+
@Override
109+
public ActionResult onWrenched(BlockState state, @NotNull ItemUsageContext context) {
110+
World world = context.getWorld();
111+
PlayerEntity player = context.getPlayer();
112+
if (player != null) {
113+
BlockEntity be = world.getBlockEntity(context.getBlockPos());
114+
if (be instanceof TurnstileBlockEntity turnstile) {
115+
turnstile.exit = !turnstile.exit;
116+
player.sendMessage(new TranslatableText("message.lead_beyond.set_exit." + turnstile.exit), true);
117+
return ActionResult.SUCCESS;
118+
}
119+
}
120+
return ActionResult.PASS;
121+
}
122+
123+
@Override
124+
public VoxelShape getCollisionShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
125+
Direction dir = state.get(FACING);
126+
boolean open = state.get(OPEN);
127+
VoxelShape nsBarrier = Block.createCuboidShape(0, 0, 6, 16, 24, 10);
128+
VoxelShape ewBarrier = Block.createCuboidShape(6, 0, 0, 10, 24, 16);
129+
return switch (dir) {
130+
case SOUTH -> open ? VoxelShapes.union(Block.createCuboidShape(0, 0, 0, 3.5, 14, 16),
131+
Block.createCuboidShape(15, 0, 0, 16, 14, 16))
132+
: VoxelShapes.union(Block.createCuboidShape(0, 0, 0, 3.5, 24, 16),
133+
Block.createCuboidShape(15, 0, 0, 16, 24, 16),
134+
nsBarrier);
135+
case NORTH -> open ? VoxelShapes.union(Block.createCuboidShape(0, 0, 0, 1, 14, 16),
136+
Block.createCuboidShape(12.5, 0, 0, 16, 14, 16))
137+
: VoxelShapes.union(Block.createCuboidShape(0, 0, 0, 1, 24, 16),
138+
Block.createCuboidShape(12.5, 0, 0, 16, 24, 16),
139+
nsBarrier);
140+
case EAST -> open ? VoxelShapes.union(Block.createCuboidShape(0, 0, 0, 16, 14, 1),
141+
Block.createCuboidShape(0, 0, 12.5, 16, 14, 16))
142+
: VoxelShapes.union(Block.createCuboidShape(0, 0, 0, 16, 24, 1),
143+
Block.createCuboidShape(0, 0, 12.5, 16, 24, 16),
144+
ewBarrier);
145+
case WEST -> open ? VoxelShapes.union(Block.createCuboidShape(0, 0, 0, 16, 14, 3.5),
146+
Block.createCuboidShape(0, 0, 15, 16, 14, 16))
147+
: VoxelShapes.union(Block.createCuboidShape(0, 0, 0, 16, 24, 3.5),
148+
Block.createCuboidShape(0, 0, 15, 16, 24, 16),
149+
ewBarrier);
150+
default -> VoxelShapes.fullCube();
151+
};
152+
}
153+
154+
@Override
155+
public VoxelShape getOutlineShape(BlockState state, BlockView view, BlockPos pos, ShapeContext ctx) {
156+
Direction dir = state.get(FACING);
157+
return switch (dir) {
158+
case SOUTH -> VoxelShapes.union(Block.createCuboidShape(0, 0, 0, 3.5, 14, 16),
159+
Block.createCuboidShape(15, 0, 0, 16, 14, 16));
160+
case NORTH -> VoxelShapes.union(Block.createCuboidShape(0, 0, 0, 1, 14, 16),
161+
Block.createCuboidShape(12.5, 0, 0, 16, 14, 16));
162+
case EAST -> VoxelShapes.union(Block.createCuboidShape(0, 0, 0, 16, 14, 1),
163+
Block.createCuboidShape(0, 0, 12.5, 16, 14, 16));
164+
case WEST -> VoxelShapes.union(Block.createCuboidShape(0, 0, 0, 16, 14, 3.5),
165+
Block.createCuboidShape(0, 0, 15, 16, 14, 16));
166+
default -> VoxelShapes.fullCube();
167+
};
168+
}
169+
170+
@Nullable
171+
@Override
172+
public BlockEntity createBlockEntity(BlockPos pos, BlockState state) {
173+
return new TurnstileBlockEntity(pos, state);
174+
}
175+
176+
@Nullable
177+
@Override
178+
public <T extends BlockEntity> BlockEntityTicker<T> getTicker(World world, BlockState state, BlockEntityType<T> type) {
179+
return checkType(type, BlockEntityReg.TURNSTILE.get(), TurnstileBlockEntity::tick);
180+
}
181+
}

0 commit comments

Comments
 (0)