Skip to content

Commit

Permalink
wip: launchpad
Browse files Browse the repository at this point in the history
  • Loading branch information
bazke committed Oct 13, 2024
1 parent 50ef8b7 commit 523c1d5
Show file tree
Hide file tree
Showing 13 changed files with 912 additions and 0 deletions.
769 changes: 769 additions & 0 deletions src/generated/resources/assets/ltextras/blockstates/launchpad.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 @@ -52,6 +52,7 @@
"block.ltextras.imposter_tube_coral": "ןɐɹoƆ ǝqn⟘ ɹǝʇsodɯI",
"block.ltextras.imposter_tube_coral_block": "ʞɔoןᗺ ןɐɹoƆ ǝqn⟘ ɹǝʇsodɯI",
"block.ltextras.infertile_vine": "ǝuıΛ ǝןıʇɹǝɟuI",
"block.ltextras.launchpad": "pɐdɥɔunɐꞀ",
"block.ltextras.light_blue_glow_sticks": "sʞɔıʇS ʍoן⅁ ǝnןᗺ ʇɥbıꞀ",
"block.ltextras.light_blue_seat": "ʇɐǝS ǝnןᗺ ʇɥbıꞀ",
"block.ltextras.light_gray_seat": "ʇɐǝS ʎɐɹ⅁ ʇɥ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 @@ -52,6 +52,7 @@
"block.ltextras.imposter_tube_coral": "Imposter Tube Coral",
"block.ltextras.imposter_tube_coral_block": "Imposter Tube Coral Block",
"block.ltextras.infertile_vine": "Infertile Vine",
"block.ltextras.launchpad": "Launchpad",
"block.ltextras.light_blue_glow_sticks": "Light Blue Glow Sticks",
"block.ltextras.light_blue_seat": "Light Blue Seat",
"block.ltextras.light_gray_seat": "Light Gray Seat",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"parent": "minecraft:block/slab",
"textures": {
"bottom": "ltextras:block/launchpad_top",
"particle": "ltextras:block/launchpad_side",
"side": "ltextras:block/launchpad_side",
"top": "ltextras:block/launchpad_top"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
{
"parent": "minecraft:block/slab",
"textures": {
"bottom": "ltextras:block/launchpad_bottom",
"particle": "ltextras:block/launchpad_side",
"side": "ltextras:block/launchpad_side",
"top": "ltextras:block/launchpad_top_nohoriz"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"parent": "ltextras:block/launchpad"
}
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:launchpad"
}
],
"rolls": 1.0
}
],
"random_sequence": "ltextras:blocks/launchpad"
}
34 changes: 34 additions & 0 deletions src/main/java/com/lovetropics/extras/ExtraBlocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import com.tterrag.registrate.util.entry.BlockEntry;
import com.tterrag.registrate.util.nullness.NonNullSupplier;
import it.unimi.dsi.fastutil.objects.Object2ObjectOpenHashMap;
import net.minecraft.advancements.critereon.SimpleCriterionTrigger;
import net.minecraft.client.renderer.BiomeColors;
import net.minecraft.client.renderer.RenderType;
import net.minecraft.core.BlockPos;
Expand Down Expand Up @@ -842,6 +843,39 @@ public InteractionResultHolder<ItemStack> use(Level leve, Player player, Interac
.build()
.register();

private static BlockEntry<LaunchpadBlock> LAUNCHPAD = REGISTRATE.block("launchpad", LaunchpadBlock::new)
.initialProperties(() -> Blocks.GRASS_BLOCK)
.blockstate((ctx, prov) -> {
BlockModelBuilder model = prov.models().withExistingParent(ctx.getName(), prov.mcLoc("block/slab"))
.texture("bottom", prov.modLoc("block/launchpad_top"))
.texture("side", prov.modLoc("block/launchpad_side"))
.texture("top", prov.modLoc("block/launchpad_top"))
.texture("particle", prov.modLoc("block/launchpad_side"));

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


//This creates many models. Is there a better way to do this? In BlockModelGenerators I think you can use some sort of selector on the properties...
prov.getVariantBuilder(ctx.get()).forAllStatesExcept(state -> {
Direction direction = state.getValue(LaunchpadBlock.FACING);
boolean noHorizontalPower = state.getValue(LaunchpadBlock.HORIZONTAL_POWER) < 1;
BlockModelBuilder selectedModel = noHorizontalPower ? noHorizontalPowerModel : model;
int rotationY = ((int) direction.toYRot() + 180) % 360;
return ConfiguredModel.builder()
.modelFile(selectedModel)
.rotationY(rotationY)
.build();
}, LaunchpadBlock.VERTICAL_POWER);

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

public static final Set<BlockEntry<SeatBlock>> SEAT_BLOCKS = Stream.of(DyeColor.values())
.map(ExtraBlocks::seat)
.collect(Collectors.toSet());
Expand Down
65 changes: 65 additions & 0 deletions src/main/java/com/lovetropics/extras/block/LaunchpadBlock.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
package com.lovetropics.extras.block;

import com.mojang.serialization.MapCodec;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.sounds.SoundEvents;
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 LaunchpadBlock extends HorizontalDirectionalBlock {

public static final MapCodec<LaunchpadBlock> CODEC = simpleCodec(LaunchpadBlock::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 LaunchpadBlock(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.

0 comments on commit 523c1d5

Please sign in to comment.