-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Basic BlockState Support and Misc Delegate Methods to LevelJS (#464)
* Added simple Delegate methods for getting WorldBorder, Game Difficulty, and MoonBrightness to LevelJS * Added BlockState Support to Custom Blocks (Needs Testing) --Modifications-- BuiltinKubeJSPlugin: - Added "Properties" and "Property" binding to startup scripts for use with BlockStates BlockBuilder: - Added defaultState callback - Added placementState callback - Added BlockBuilder.property - Added BlockBuilder.boolProperty - Added BlockBuilder.enumProperty - Added BlockBuilder.dirProperty - Deprecated waterlogged BasicBlockJS - Implemented BlockBuilder.defaultState - Implemented BlockBuilder.placementState - Removed usages of BlockBuilder.waterlogged in a handful of places without removing functionality. - Added private method safeCallback for catching and logging exceptions in callback functions to startup script console. Additions: - BlockStateModifyCallbackJS (Used for registering default state) - BlockStateModifyPlacementCallbackJS (Used for modifying blockstate on placement) * Fixed Logical Issue with waterlogging in BasicBlockJS * Replaced "Properties" and "Property" with "BlockProperties" * Modified BlockStateModifyCallbackJS to act closer to a builder * Removed boolProperty, intProperty, dirProperty, and enumProperty from BlockBuilder to encourage reflective use instead. * BasicBlockJS: - Fixed safeCallbackLogic - Made BlockBuilder.blockStateProperties immutable after creation. - Removed the last remaining uses of waterlogged - Fixed WaterLogged logic by implementing SimpleWaterloggedBlock BlockBuilder: - BlockBuilder.blockStateProperties is now a set for quick lookup times. - Added get and set methods to BlockStateModifyCallbackJS for simpler syntax and to clear rhino un-boxing issues. * Fixed BlockStateModifyPlacementCallbackJS.getItemInHand() to be BlockStateModifyPlacementCallbackJS.getItem() for use in beans * Additions to BlockStateModifyPlacementCallbackJS: - Added BlockStateModifyPlacementCallbackJS.waterlogged() - Added BlockStateModifyPlacementCallbackJS.isWaterLogged() * Fixed reference to old BlockStateProperties binding * Removed unused import from BlockStateModifyPlacementCallbackJS * Modified syntax for Waterlogging in BlockStateModifyPlacementCallbackJS: - BlockStateModifyPlacementCallbackJS.isWaterLogged() is now BlockStateModifyPlacementCallbackJS.isInWater - Added BlockStateModifyPlacementCallbackJS.waterlogged(boolean) Co-authored-by: Hunter19823 <hspragg+github@asu.edu>
- Loading branch information
1 parent
269567d
commit 2f5a6dd
Showing
6 changed files
with
364 additions
and
16 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
111 changes: 111 additions & 0 deletions
111
common/src/main/java/dev/latvian/mods/kubejs/block/BlockStateModifyCallbackJS.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,111 @@ | ||
package dev.latvian.mods.kubejs.block; | ||
|
||
import com.google.common.collect.ImmutableMap; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.core.Direction; | ||
import net.minecraft.util.StringRepresentable; | ||
import net.minecraft.world.level.LevelAccessor; | ||
import net.minecraft.world.level.block.Mirror; | ||
import net.minecraft.world.level.block.Rotation; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import net.minecraft.world.level.block.state.properties.BooleanProperty; | ||
import net.minecraft.world.level.block.state.properties.EnumProperty; | ||
import net.minecraft.world.level.block.state.properties.IntegerProperty; | ||
import net.minecraft.world.level.block.state.properties.Property; | ||
|
||
import java.util.Collection; | ||
import java.util.Map; | ||
import java.util.Optional; | ||
|
||
public class BlockStateModifyCallbackJS { | ||
private BlockState state; | ||
public BlockStateModifyCallbackJS(BlockState state) { | ||
this.state = state; | ||
} | ||
|
||
public <T extends Comparable<T>> BlockStateModifyCallbackJS cycle(Property<T> property) { | ||
this.state = state.cycle(property); | ||
return this; | ||
} | ||
|
||
public BlockState getState() { | ||
return state; | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return state.toString(); | ||
} | ||
|
||
public Collection<Property<?>> getProperties() { | ||
return state.getProperties(); | ||
} | ||
|
||
public <T extends Comparable<T>> boolean hasProperty(Property<T> property) { | ||
return state.hasProperty(property); | ||
} | ||
|
||
public <T extends Comparable<T>> T getValue(Property<T> property) { | ||
return state.getValue(property); | ||
} | ||
|
||
public <T extends Comparable<T>> T get(Property<T> property) { | ||
return state.getValue(property); | ||
} | ||
|
||
public <T extends Comparable<T>> Optional<T> getOptionalValue(Property<T> property) { | ||
return state.getOptionalValue(property); | ||
} | ||
|
||
public <T extends Comparable<T>, V extends T> BlockStateModifyCallbackJS setValue(Property<T> property, V comparable) { | ||
this.state = state.setValue(property, comparable); | ||
return this; | ||
} | ||
|
||
public BlockStateModifyCallbackJS set(BooleanProperty property, boolean value) { | ||
this.state = state.setValue(property, value); | ||
return this; | ||
} | ||
|
||
public BlockStateModifyCallbackJS set(IntegerProperty property, Integer value) { | ||
this.state = state.setValue(property, value); | ||
return this; | ||
} | ||
|
||
public <T extends Enum<T> & StringRepresentable> BlockStateModifyCallbackJS set(EnumProperty<T> property, T value) { | ||
this.state = state.setValue(property, value); | ||
return this; | ||
} | ||
|
||
public <T extends Enum<T> & StringRepresentable> BlockStateModifyCallbackJS set(EnumProperty<T> property, String value) { | ||
this.state = state.setValue(property, property.getValue(value).get()); | ||
return this; | ||
} | ||
|
||
|
||
public BlockStateModifyCallbackJS populateNeighbours(Map<Map<Property<?>, Comparable<?>>, BlockState> map) { | ||
state.populateNeighbours(map); | ||
return this; | ||
} | ||
|
||
public ImmutableMap<Property<?>, Comparable<?>> getValues() { | ||
return state.getValues(); | ||
} | ||
|
||
public BlockStateModifyCallbackJS rotate(Rotation rotation) { | ||
this.state = state.rotate(rotation); | ||
return this; | ||
} | ||
|
||
public BlockStateModifyCallbackJS mirror(Mirror mirror) { | ||
this.state = state.mirror(mirror); | ||
return this; | ||
} | ||
|
||
public BlockStateModifyCallbackJS updateShape(Direction direction, BlockState blockState, LevelAccessor levelAccessor, BlockPos blockPos, BlockPos blockPos2) { | ||
this.state = state.updateShape(direction, blockState, levelAccessor, blockPos, blockPos2); | ||
return this; | ||
} | ||
|
||
|
||
} |
122 changes: 122 additions & 0 deletions
122
common/src/main/java/dev/latvian/mods/kubejs/block/BlockStateModifyPlacementCallbackJS.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,122 @@ | ||
package dev.latvian.mods.kubejs.block; | ||
|
||
import dev.latvian.mods.kubejs.item.ItemStackJS; | ||
import dev.latvian.mods.kubejs.level.BlockContainerJS; | ||
import dev.latvian.mods.kubejs.level.LevelJS; | ||
import dev.latvian.mods.kubejs.player.PlayerJS; | ||
import dev.latvian.mods.kubejs.util.UtilsJS; | ||
import net.minecraft.core.BlockPos; | ||
import net.minecraft.core.Direction; | ||
import net.minecraft.world.InteractionHand; | ||
import net.minecraft.world.item.context.BlockPlaceContext; | ||
import net.minecraft.world.level.block.Block; | ||
import net.minecraft.world.level.block.state.properties.BlockStateProperties; | ||
import net.minecraft.world.level.material.Fluid; | ||
import net.minecraft.world.level.material.FluidState; | ||
import net.minecraft.world.level.material.Fluids; | ||
import net.minecraft.world.phys.Vec3; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public class BlockStateModifyPlacementCallbackJS extends BlockStateModifyCallbackJS { | ||
public final BlockPlaceContext context; | ||
public final Block minecraftBlock; | ||
public BlockContainerJS block; | ||
|
||
public BlockStateModifyPlacementCallbackJS(BlockPlaceContext context, Block block) { | ||
super(block.defaultBlockState()); | ||
this.context = context; | ||
this.minecraftBlock = block; | ||
this.block = new BlockContainerJS(context.getLevel(), context.getClickedPos()); | ||
} | ||
|
||
public BlockPos getClickedPos() { | ||
return context.getClickedPos(); | ||
} | ||
|
||
public BlockContainerJS getClickedBlock() { | ||
return getLevel().getBlock(context.getClickedPos()); | ||
} | ||
|
||
public boolean canPlace() { | ||
return context.canPlace(); | ||
} | ||
|
||
public boolean replacingClickedOnBlock() { | ||
return context.replacingClickedOnBlock(); | ||
} | ||
|
||
public Direction getNearestLookingDirection() { | ||
return context.getNearestLookingDirection(); | ||
} | ||
|
||
public Direction getNearestLookingVerticalDirection() { | ||
return context.getNearestLookingVerticalDirection(); | ||
} | ||
|
||
public Direction[] getNearestLookingDirections() { | ||
return context.getNearestLookingDirections(); | ||
} | ||
|
||
public Direction getClickedFace() { | ||
return context.getClickedFace(); | ||
} | ||
|
||
public Vec3 getClickLocation() { | ||
return context.getClickLocation(); | ||
} | ||
|
||
public boolean isInside() { | ||
return context.isInside(); | ||
} | ||
|
||
public ItemStackJS getItem() { | ||
return ItemStackJS.of(context.getItemInHand()); | ||
} | ||
|
||
@Nullable | ||
public PlayerJS<?> getPlayer() { | ||
return getLevel().getPlayer(context.getPlayer()); | ||
} | ||
|
||
public InteractionHand getHand() { | ||
return context.getHand(); | ||
} | ||
|
||
public LevelJS getLevel() { | ||
return UtilsJS.getLevel(context.getLevel()); | ||
} | ||
|
||
public Direction getHorizontalDirection() { | ||
return context.getHorizontalDirection(); | ||
} | ||
|
||
public boolean isSecondaryUseActive() { | ||
return context.isSecondaryUseActive(); | ||
} | ||
|
||
public float getRotation() { | ||
return context.getRotation(); | ||
} | ||
|
||
public FluidState getFluidStateAtClickedPos() { | ||
return context.getLevel().getFluidState(context.getClickedPos()); | ||
} | ||
|
||
public boolean isClickedPosIn(Fluid fluid) { | ||
return getFluidStateAtClickedPos().is(fluid); | ||
} | ||
|
||
public BlockStateModifyPlacementCallbackJS waterlogged(boolean waterlogged) { | ||
setValue(BlockStateProperties.WATERLOGGED, waterlogged); | ||
return this; | ||
} | ||
|
||
public BlockStateModifyPlacementCallbackJS waterlogged() { | ||
waterlogged(isInWater()); | ||
return this; | ||
} | ||
|
||
public boolean isInWater() { | ||
return getFluidStateAtClickedPos().getType() == Fluids.WATER; | ||
} | ||
} |
Oops, something went wrong.