Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
MinecraftForge
GitHub Repository: MinecraftForge/MinecraftForge
Path: blob/1.21.x/src/main/java/net/minecraftforge/common/extensions/IForgeBaseRailBlock.java
7393 views
1
/*
2
* Copyright (c) Forge Development LLC and contributors
3
* SPDX-License-Identifier: LGPL-2.1-only
4
*/
5
6
package net.minecraftforge.common.extensions;
7
8
import net.minecraft.world.entity.vehicle.MinecartFurnace;
9
import net.minecraft.world.level.block.state.BlockState;
10
import net.minecraft.world.entity.vehicle.AbstractMinecart;
11
import net.minecraft.world.level.block.state.properties.RailShape;
12
import net.minecraft.core.BlockPos;
13
import net.minecraft.world.level.BlockGetter;
14
import net.minecraft.world.level.Level;
15
import org.jetbrains.annotations.Nullable;
16
17
public interface IForgeBaseRailBlock
18
{
19
20
/**
21
* Return true if the rail can make corners.
22
* Used by placement logic.
23
* @param level The level.
24
* @param pos Block's position in level
25
* @return True if the rail can make corners.
26
*/
27
boolean isFlexibleRail(BlockState state, BlockGetter level, BlockPos pos);
28
29
/**
30
* Returns true if the rail can make up and down slopes.
31
* Used by placement logic.
32
* @param level The level.
33
* @param pos Block's position in level
34
* @return True if the rail can make slopes.
35
*/
36
default boolean canMakeSlopes(BlockState state, BlockGetter level, BlockPos pos)
37
{
38
return true;
39
}
40
41
/**
42
* Return the rail's direction.
43
* Can be used to make the cart think the rail is a different shape,
44
* for example when making diamond junctions or switches.
45
* The cart parameter will often be null unless it it called from EntityMinecart.
46
*
47
* @param level The level.
48
* @param pos Block's position in level
49
* @param state The BlockState
50
* @param cart The cart asking for the metadata, null if it is not called by EntityMinecart.
51
* @return The direction.
52
*/
53
RailShape getRailDirection(BlockState state, BlockGetter level, BlockPos pos, @Nullable AbstractMinecart cart);
54
55
/**
56
* Returns the max speed of the rail at the specified position.
57
* @param level The level.
58
* @param cart The cart on the rail, may be null.
59
* @param pos Block's position in level
60
* @return The max speed of the current rail.
61
*/
62
default float getRailMaxSpeed(BlockState state, Level level, BlockPos pos, AbstractMinecart cart)
63
{
64
if (cart instanceof MinecartFurnace) return cart.isInWater() ? 0.15f : 0.2f;
65
else return cart.isInWater() ? 0.2f : 0.4f;
66
}
67
68
/**
69
* This function is called by any minecart that passes over this rail.
70
* It is called once per update tick that the minecart is on the rail.
71
* @param level The level.
72
* @param cart The cart on the rail.
73
* @param pos Block's position in level
74
*/
75
default void onMinecartPass(BlockState state, Level level, BlockPos pos, AbstractMinecart cart){}
76
77
/**
78
* Returns true if the given {@link RailShape} is valid for this rail block.
79
* This is called when the RailShape for the initial placement of this block is calculated or
80
* when another rail block tries to connect to this block and this block's RailState calculates
81
* the new RailShape for its current neigbors.
82
* @param shape The new RailShape
83
* @return True when the given RailShape is valid
84
*/
85
default boolean isValidRailShape(RailShape shape)
86
{
87
return true;
88
}
89
}
90
91