Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft: A launchpad #67

Draft
wants to merge 2 commits into
base: lt24
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
769 changes: 769 additions & 0 deletions src/generated/resources/assets/ltextras/blockstates/jumppad.json

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions src/generated/resources/assets/ltextras/lang/en_ud.json
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@
"block.ltextras.imposter_white_concrete_powder": "ɹǝpʍoԀ ǝʇǝɹɔuoƆ ǝʇıɥM ɹǝʇsodɯI",
"block.ltextras.imposter_yellow_concrete_powder": "ɹǝpʍoԀ ǝʇǝɹɔuoƆ ʍoןןǝʎ ɹǝʇsodɯI",
"block.ltextras.infertile_vine": "ǝuıΛ ǝןıʇɹǝɟuI",
"block.ltextras.jumppad": "pɐԀ dɯnſ",
"block.ltextras.light_blue_concrete_powder_slab": "qɐןS ɹǝpʍoԀ ǝʇǝɹɔuoƆ ǝnןᗺ ʇɥbıꞀ",
"block.ltextras.light_blue_concrete_powder_stairs": "sɹıɐʇS ɹǝpʍoԀ ǝʇǝɹɔuoƆ ǝnןᗺ ʇɥbıꞀ",
"block.ltextras.light_blue_concrete_slab": "qɐןS ǝʇǝɹɔuoƆ ǝnןᗺ ʇɥbıꞀ",
Expand Down
1 change: 1 addition & 0 deletions src/generated/resources/assets/ltextras/lang/en_us.json
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,7 @@
"block.ltextras.imposter_white_concrete_powder": "Imposter White Concrete Powder",
"block.ltextras.imposter_yellow_concrete_powder": "Imposter Yellow Concrete Powder",
"block.ltextras.infertile_vine": "Infertile Vine",
"block.ltextras.jumppad": "Jump Pad",
"block.ltextras.light_blue_concrete_powder_slab": "Light Blue Concrete Powder Slab",
"block.ltextras.light_blue_concrete_powder_stairs": "Light Blue Concrete Powder Stairs",
"block.ltextras.light_blue_concrete_slab": "Light Blue Concrete Slab",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"parent": "minecraft:block/slab",
"textures": {
"bottom": "ltextras:block/jumppad_bottom",
"particle": "ltextras:block/jumppad_side",
"side": "ltextras:block/jumppad_side",
"top": "ltextras:block/jumppad_top"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"parent": "minecraft:block/slab",
"textures": {
"bottom": "ltextras:block/jumppad_bottom",
"particle": "ltextras:block/jumppad_side",
"side": "ltextras:block/jumppad_side",
"top": "ltextras:block/jumppad_top_nohoriz"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"parent": "ltextras:block/jumppad"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
{
"type": "minecraft:block",
"pools": [
{
"bonus_rolls": 0.0,
"conditions": [
{
"condition": "minecraft:survives_explosion"
}
],
"entries": [
{
"type": "minecraft:item",
"name": "ltextras:jumppad"
}
],
"rolls": 1.0
}
],
"random_sequence": "ltextras:blocks/jumppad"
}
33 changes: 32 additions & 1 deletion src/main/java/com/lovetropics/extras/ExtraBlocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.DoorBlock;
import net.minecraft.world.level.block.FenceBlock;
import net.minecraft.world.level.block.HalfTransparentBlock;
import net.minecraft.world.level.block.IronBarsBlock;
import net.minecraft.world.level.block.LadderBlock;
import net.minecraft.world.level.block.PipeBlock;
Expand Down Expand Up @@ -952,6 +951,38 @@ public InteractionResultHolder<ItemStack> use(Level leve, Player player, Interac
.build()
.register();

private static BlockEntry<JumppadBlock> JUMPPAD = REGISTRATE.block("jumppad", JumppadBlock::new)
.lang("Jump Pad")
.initialProperties(() -> Blocks.GRASS_BLOCK)
.blockstate((ctx, prov) -> {
BlockModelBuilder model = prov.models().withExistingParent(ctx.getName(), prov.mcLoc("block/slab"))
.texture("bottom", prov.modLoc("block/jumppad_bottom"))
.texture("side", prov.modLoc("block/jumppad_side"))
.texture("top", prov.modLoc("block/jumppad_top"))
.texture("particle", prov.modLoc("block/jumppad_side"));

BlockModelBuilder noHorizontalPowerModel = prov.models().withExistingParent(ctx.getName() + "_nohoriz", prov.mcLoc("block/slab"))
.texture("bottom", prov.modLoc("block/jumppad_bottom"))
.texture("side", prov.modLoc("block/jumppad_side"))
.texture("top", prov.modLoc("block/jumppad_top_nohoriz"))
.texture("particle", prov.modLoc("block/jumppad_side"));

prov.getVariantBuilder(ctx.get()).forAllStatesExcept(state -> {
Direction direction = state.getValue(JumppadBlock.FACING);
boolean noHorizontalPower = state.getValue(JumppadBlock.HORIZONTAL_POWER) < 1;
BlockModelBuilder selectedModel = noHorizontalPower ? noHorizontalPowerModel : model;
int rotationY = ((int) direction.toYRot() + 180) % 360;
return ConfiguredModel.builder()
.modelFile(selectedModel)
.rotationY(rotationY)
.build();
}, JumppadBlock.VERTICAL_POWER);

})
.addLayer(() -> RenderType::solid)
.simpleItem()
.register();


private static final TemplateBuilder<CeilingCarpetBlock, BlockFactory<CeilingCarpetBlock>> CEILING_CARPET_TEMPLATES = new TemplateBuilder<CeilingCarpetBlock, BlockFactory<CeilingCarpetBlock>>()
.add(Blocks.SAND, CeilingCarpetBlock::new)
Expand Down
64 changes: 64 additions & 0 deletions src/main/java/com/lovetropics/extras/block/JumppadBlock.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
package com.lovetropics.extras.block;

import com.mojang.serialization.MapCodec;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.world.entity.Entity;
import net.minecraft.world.item.context.BlockPlaceContext;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.HorizontalDirectionalBlock;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.IntegerProperty;
import net.minecraft.world.phys.Vec3;
import net.minecraft.world.phys.shapes.CollisionContext;
import net.minecraft.world.phys.shapes.VoxelShape;

public class JumppadBlock extends HorizontalDirectionalBlock {

public static final MapCodec<JumppadBlock> CODEC = simpleCodec(JumppadBlock::new);
private static final VoxelShape AABB = Block.box(0.0, 0.0, 0.0, 16.0, 8.0, 16.0);
//Power is divided by 10 since there is no FloatProperty
public static final IntegerProperty VERTICAL_POWER = IntegerProperty.create("vertical_power", 0, 50);
public static final IntegerProperty HORIZONTAL_POWER = IntegerProperty.create("horizontal_power", 0, 50);

public JumppadBlock(final Properties properties) {
super(properties);
registerDefaultState(defaultBlockState().setValue(VERTICAL_POWER, 10).setValue(HORIZONTAL_POWER, 10));
}

@Override
public void stepOn(Level level, BlockPos pos, BlockState state, Entity entity) {
final double verticalPower = (double) state.getValue(VERTICAL_POWER) / 10;
final double horizontalPower = (double) state.getValue(HORIZONTAL_POWER) / 10;
final Direction facing = state.getValue(FACING);

final Vec3 upwards = new Vec3(0, verticalPower, 0);
final Vec3 forward = new Vec3(facing.getStepX(), 0, facing.getStepZ()).scale(horizontalPower);

entity.addDeltaMovement(forward.add(upwards));
super.stepOn(level, pos, state, entity);
}

@Override
public BlockState getStateForPlacement(BlockPlaceContext context) {
return this.defaultBlockState().setValue(FACING, context.getHorizontalDirection().getOpposite());
}

@Override
protected VoxelShape getShape(final BlockState state, final BlockGetter level, final BlockPos pos, final CollisionContext context) {
return AABB;
}

@Override
protected MapCodec<? extends HorizontalDirectionalBlock> codec() {
return CODEC;
}

@Override
protected void createBlockStateDefinition(StateDefinition.Builder<Block, BlockState> builder) {
builder.add(FACING, VERTICAL_POWER, HORIZONTAL_POWER);
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading