Skip to content

Commit

Permalink
Finalish changes before release
Browse files Browse the repository at this point in the history
  • Loading branch information
Fusion-Flux committed Apr 19, 2021
1 parent 358cfcd commit d7339ee
Show file tree
Hide file tree
Showing 11 changed files with 630 additions and 6 deletions.
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ fabric_version=0.31.0+1.16
cloth_config_version=4.11.14
modmenu_version=1.14.15
ip_version=1.16-SNAPSHOT
rayon_version=1.2.2
rayon_version=1.2.3
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.fusionflux.thinkingwithportatos.blocks;

import net.minecraft.block.AbstractBlock;
import net.minecraft.sound.SoundEvent;
import net.minecraft.sound.SoundEvents;

public class TallButton extends TallButtonVarient{
public TallButton(AbstractBlock.Settings settings) {
super(false, settings);
}

protected SoundEvent getClickSound(boolean powered) {
return powered ? SoundEvents.BLOCK_STONE_BUTTON_CLICK_ON : SoundEvents.BLOCK_STONE_BUTTON_CLICK_OFF;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,198 @@
package com.fusionflux.thinkingwithportatos.blocks;

import net.minecraft.block.*;
import net.minecraft.block.enums.WallMountLocation;
import net.minecraft.entity.Entity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.entity.projectile.PersistentProjectileEntity;
import net.minecraft.server.world.ServerWorld;
import net.minecraft.sound.SoundCategory;
import net.minecraft.sound.SoundEvent;
import net.minecraft.state.StateManager;
import net.minecraft.state.property.BooleanProperty;
import net.minecraft.state.property.Properties;
import net.minecraft.state.property.Property;
import net.minecraft.util.ActionResult;
import net.minecraft.util.Hand;
import net.minecraft.util.hit.BlockHitResult;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
import net.minecraft.util.shape.VoxelShape;
import net.minecraft.world.BlockView;
import net.minecraft.world.World;
import net.minecraft.world.WorldAccess;
import org.jetbrains.annotations.Nullable;

import java.util.List;
import java.util.Random;

public abstract class TallButtonVarient extends WallMountedBlock {
public static final BooleanProperty POWERED;
protected static final VoxelShape CEILING_X_SHAPE;
protected static final VoxelShape CEILING_Z_SHAPE;
protected static final VoxelShape FLOOR_X_SHAPE;
protected static final VoxelShape FLOOR_Z_SHAPE;
protected static final VoxelShape NORTH_SHAPE;
protected static final VoxelShape SOUTH_SHAPE;
protected static final VoxelShape WEST_SHAPE;
protected static final VoxelShape EAST_SHAPE;
protected static final VoxelShape CEILING_X_PRESSED_SHAPE;
protected static final VoxelShape CEILING_Z_PRESSED_SHAPE;
protected static final VoxelShape FLOOR_X_PRESSED_SHAPE;
protected static final VoxelShape FLOOR_Z_PRESSED_SHAPE;
protected static final VoxelShape NORTH_PRESSED_SHAPE;
protected static final VoxelShape SOUTH_PRESSED_SHAPE;
protected static final VoxelShape WEST_PRESSED_SHAPE;
protected static final VoxelShape EAST_PRESSED_SHAPE;
private final boolean wooden;

protected TallButtonVarient(boolean wooden, AbstractBlock.Settings settings) {
super(settings);
this.setDefaultState((BlockState)((BlockState)((BlockState)((BlockState)this.stateManager.getDefaultState()).with(FACING, Direction.NORTH)).with(POWERED, false)).with(FACE, WallMountLocation.WALL));
this.wooden = wooden;
}

private int getPressTicks() {
return this.wooden ? 30 : 20;
}

public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) {
Direction direction = (Direction)state.get(FACING);
boolean bl = (Boolean)state.get(POWERED);
switch((WallMountLocation)state.get(FACE)) {
case FLOOR:
if (direction.getAxis() == Direction.Axis.X) {
return bl ? FLOOR_X_PRESSED_SHAPE : FLOOR_X_SHAPE;
}

return bl ? FLOOR_Z_PRESSED_SHAPE : FLOOR_Z_SHAPE;
case WALL:
switch(direction) {
case EAST:
return bl ? EAST_PRESSED_SHAPE : EAST_SHAPE;
case WEST:
return bl ? WEST_PRESSED_SHAPE : WEST_SHAPE;
case SOUTH:
return bl ? SOUTH_PRESSED_SHAPE : SOUTH_SHAPE;
case NORTH:
default:
return bl ? NORTH_PRESSED_SHAPE : NORTH_SHAPE;
}
case CEILING:
default:
if (direction.getAxis() == Direction.Axis.X) {
return bl ? CEILING_X_PRESSED_SHAPE : CEILING_X_SHAPE;
} else {
return bl ? CEILING_Z_PRESSED_SHAPE : CEILING_Z_SHAPE;
}
}
}

public ActionResult onUse(BlockState state, World world, BlockPos pos, PlayerEntity player, Hand hand, BlockHitResult hit) {
if ((Boolean)state.get(POWERED)) {
return ActionResult.CONSUME;
} else {
this.powerOn(state, world, pos);
this.playClickSound(player, world, pos, true);
return ActionResult.success(world.isClient);
}
}

public void powerOn(BlockState state, World world, BlockPos pos) {
world.setBlockState(pos, (BlockState)state.with(POWERED, true), 3);
this.updateNeighbors(state, world, pos);
world.getBlockTickScheduler().schedule(pos, this, this.getPressTicks());
}

protected void playClickSound(@Nullable PlayerEntity player, WorldAccess world, BlockPos pos, boolean powered) {
world.playSound(powered ? player : null, pos, this.getClickSound(powered), SoundCategory.BLOCKS, 0.3F, powered ? 0.6F : 0.5F);
}

protected abstract SoundEvent getClickSound(boolean powered);

public void onStateReplaced(BlockState state, World world, BlockPos pos, BlockState newState, boolean moved) {
if (!moved && !state.isOf(newState.getBlock())) {
if ((Boolean)state.get(POWERED)) {
this.updateNeighbors(state, world, pos);
}

super.onStateReplaced(state, world, pos, newState, moved);
}
}

public int getWeakRedstonePower(BlockState state, BlockView world, BlockPos pos, Direction direction) {
return (Boolean)state.get(POWERED) ? 15 : 0;
}

public int getStrongRedstonePower(BlockState state, BlockView world, BlockPos pos, Direction direction) {
return (Boolean)state.get(POWERED) && getDirection(state) == direction ? 15 : 0;
}

public boolean emitsRedstonePower(BlockState state) {
return true;
}

public void scheduledTick(BlockState state, ServerWorld world, BlockPos pos, Random random) {
if ((Boolean)state.get(POWERED)) {
if (this.wooden) {
this.tryPowerWithProjectiles(state, world, pos);
} else {
world.setBlockState(pos, (BlockState)state.with(POWERED, false), 3);
this.updateNeighbors(state, world, pos);
this.playClickSound((PlayerEntity)null, world, pos, false);
}

}
}

public void onEntityCollision(BlockState state, World world, BlockPos pos, Entity entity) {
if (!world.isClient && this.wooden && !(Boolean)state.get(POWERED)) {
this.tryPowerWithProjectiles(state, world, pos);
}
}

private void tryPowerWithProjectiles(BlockState state, World world, BlockPos pos) {
List<? extends Entity> list = world.getNonSpectatingEntities(PersistentProjectileEntity.class, state.getOutlineShape(world, pos).getBoundingBox().offset(pos));
boolean bl = !list.isEmpty();
boolean bl2 = (Boolean)state.get(POWERED);
if (bl != bl2) {
world.setBlockState(pos, (BlockState)state.with(POWERED, bl), 3);
this.updateNeighbors(state, world, pos);
this.playClickSound((PlayerEntity)null, world, pos, bl);
}

if (bl) {
world.getBlockTickScheduler().schedule(new BlockPos(pos), this, this.getPressTicks());
}

}

private void updateNeighbors(BlockState state, World world, BlockPos pos) {
world.updateNeighborsAlways(pos, this);
world.updateNeighborsAlways(pos.offset(getDirection(state).getOpposite()), this);
}

protected void appendProperties(StateManager.Builder<Block, BlockState> builder) {
builder.add(new Property[]{FACING, POWERED, FACE});
}

static {
POWERED = Properties.POWERED;
CEILING_X_SHAPE = Block.createCuboidShape(5.5D, 1.0D, 5.5D, 10.5D, 16.0D, 10.5D);
CEILING_Z_SHAPE = Block.createCuboidShape(5.5D, 1.0D, 5.5D, 10.5D, 16.0D, 10.5D);
FLOOR_X_SHAPE = Block.createCuboidShape(5.5D, 0.0D, 5.5D, 10.5D, 15.0D, 10.5D);
FLOOR_Z_SHAPE = Block.createCuboidShape(5.5D, 0.0D, 5.5D, 10.5D, 15.0D, 10.5D);
NORTH_SHAPE = Block.createCuboidShape(5.5D, 5.5D, 1.0D, 10.5D, 10.5D, 16.0D);
SOUTH_SHAPE = Block.createCuboidShape(5.5D, 5.5D, 0.0D, 10.5D, 10.5D, 15.0D);
WEST_SHAPE = Block.createCuboidShape(1.0D, 5.5D, 5.5D, 16.0D, 10.5D, 10.5D);
EAST_SHAPE = Block.createCuboidShape(0.0D, 5.5D, 5.5D, 15.0D, 10.5D, 10.5D);
CEILING_X_PRESSED_SHAPE = Block.createCuboidShape(5.5D, 1.0D, 5.5D, 10.5D, 16.0D, 10.5D);
CEILING_Z_PRESSED_SHAPE = Block.createCuboidShape(5.5D, 1.0D, 5.5D, 10.5D, 16.0D, 10.5D);
FLOOR_X_PRESSED_SHAPE = Block.createCuboidShape(5.5D, 0.0D, 5.5D, 10.5D, 15.0D, 10.5D);
FLOOR_Z_PRESSED_SHAPE = Block.createCuboidShape(5.5D, 0.0D, 5.5D, 10.5D, 15.0D, 10.5D);
NORTH_PRESSED_SHAPE = Block.createCuboidShape(5.5D, 5.5D, 1.0D, 10.5D, 10.5D, 16.0D);
SOUTH_PRESSED_SHAPE = Block.createCuboidShape(5.5D, 5.5D, 0.0D, 10.5D, 10.5D, 15.0D);
WEST_PRESSED_SHAPE = Block.createCuboidShape(1.0D, 5.5D, 5.5D, 16.0D, 10.5D, 10.5D);
EAST_PRESSED_SHAPE = Block.createCuboidShape(0.0D, 5.5D, 5.5D, 15.0D, 10.5D, 10.5D);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,9 @@ public class ThinkingWithPortatosBlocks {
public static final ExcursionFunnel EXCURSION_FUNNEL = new ExcursionFunnel(FabricBlockSettings.of(Material.AIR).nonOpaque().noCollision());
public static final LightBlock LIGHT_CUBE = new LightBlock(FabricBlockSettings.of(Material.AIR).luminance(15).noCollision().air().hardness(3.5f));

public static final TallButton TALL_BUTTON = new TallButton(FabricBlockSettings.of(Material.METAL).hardness(3.5f));


public static BlockEntityType<HardLightBridgeEmitterBlockEntity> HLB_EMITTER_ENTITY;
public static BlockEntityType<HardLightBridgeBlockEntity> HLB_BLOCK_ENTITY;
public static BlockEntityType<NeurotoxinBlockEntity> NEUROTOXIN_BLOCK_ENTITY;
Expand Down Expand Up @@ -169,6 +172,11 @@ public static void registerBlocks() {
FLOWING_ACID = Registry.register(Registry.FLUID, id("flowing_acid"), new AcidFluid.Flowing());
ACID_BUCKET = Registry.register(Registry.ITEM, id("acid_bucket"), new BucketItem(STILL_ACID, new Item.Settings().recipeRemainder(Items.BUCKET).maxCount(1).group(ThinkingWithPortatos.ThinkingWithPortatosGroup)));
ACID = Registry.register(Registry.BLOCK, id("acid"), new CustomFluidBlock(STILL_ACID, FabricBlockSettings.copy(Blocks.WATER)){});

Registry.register(Registry.BLOCK, id("tall_button"), TALL_BUTTON);
Registry.register(Registry.ITEM, id("tall_button"), new BlockItem(TALL_BUTTON, new Item.Settings().group(ThinkingWithPortatos.ThinkingWithPortatosGroup)));


}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,11 +199,11 @@ public void tick(CallbackInfo ci) {
Vec3d direction = new Vec3d(0, 0, 0);
if (this.verticalCollision) {
if (state.get(RepulsionGel.UP)) {
direction = direction.add(0, -1, 0);
direction = direction.add(0, -2, 0);
}

if (state.get(RepulsionGel.DOWN)) {
direction = direction.add(0, 1, 0);
direction = direction.add(0, 2, 0);
}

}
Expand All @@ -223,14 +223,15 @@ public void tick(CallbackInfo ci) {
if (state.get(RepulsionGel.WEST)) {
direction = direction.add(1, 0, 0);
}
direction = direction.add(0, 0.45, 0);
direction = direction.add(0, 0.5, 0);
}
if (!this.isSneaking() && !direction.equals(new Vec3d(0, 0, 0))) {
if (world.isClient && (Object) this instanceof PlayerEntity) {
world.playSound((PlayerEntity) (Object) this, this.getPos().getX(), this.getPos().getY(), this.getPos().getZ(), ThinkingWithPortatosSounds.GEL_BOUNCE_EVENT, SoundCategory.BLOCKS, .3F, 1F);
} else {
world.playSound(null, this.getPos().getX(), this.getPos().getY(), this.getPos().getZ(), ThinkingWithPortatosSounds.GEL_BOUNCE_EVENT, SoundCategory.BLOCKS, .3F, 1F);
}
this.setVelocity(this.getVelocity().multiply(1.4));
this.setVelocity(this.getVelocity().add(direction.x, direction.y, direction.z));
}
} else if (world.getBlockState(new BlockPos(this.getBlockPos().getX(), this.getBlockPos().getY() + 1, this.getBlockPos().getZ())).getBlock() == ThinkingWithPortatosBlocks.REPULSION_GEL) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,110 @@
{
"variants": {
"face=ceiling,facing=east,powered=false": {
"model": "thinkingwithportatos:block/tall_button",
"y": 270,
"x": 180
},
"face=ceiling,facing=east,powered=true": {
"model": "thinkingwithportatos:block/tall_button_pressed",
"y": 270,
"x": 180
},
"face=ceiling,facing=north,powered=false": {
"model": "thinkingwithportatos:block/tall_button",
"y": 180,
"x": 180
},
"face=ceiling,facing=north,powered=true": {
"model": "thinkingwithportatos:block/tall_button_pressed",
"y": 180,
"x": 180
},
"face=ceiling,facing=south,powered=false": {
"model": "thinkingwithportatos:block/tall_button",
"x": 180
},
"face=ceiling,facing=south,powered=true": {
"model": "thinkingwithportatos:block/tall_button_pressed",
"x": 180
},
"face=ceiling,facing=west,powered=false": {
"model": "thinkingwithportatos:block/tall_button",
"y": 90,
"x": 180
},
"face=ceiling,facing=west,powered=true": {
"model": "thinkingwithportatos:block/tall_button_pressed",
"y": 90,
"x": 180
},
"face=floor,facing=east,powered=false": {
"model": "thinkingwithportatos:block/tall_button",
"y": 90
},
"face=floor,facing=east,powered=true": {
"model": "thinkingwithportatos:block/tall_button_pressed",
"y": 90
},
"face=floor,facing=north,powered=false": {
"model": "thinkingwithportatos:block/tall_button"
},
"face=floor,facing=north,powered=true": {
"model": "thinkingwithportatos:block/tall_button_pressed"
},
"face=floor,facing=south,powered=false": {
"model": "thinkingwithportatos:block/tall_button",
"y": 180
},
"face=floor,facing=south,powered=true": {
"model": "thinkingwithportatos:block/tall_button_pressed",
"y": 180
},
"face=floor,facing=west,powered=false": {
"model": "thinkingwithportatos:block/tall_button",
"y": 270
},
"face=floor,facing=west,powered=true": {
"model": "thinkingwithportatos:block/tall_button_pressed",
"y": 270
},
"face=wall,facing=east,powered=false": {
"model": "thinkingwithportatos:block/tall_button",
"y": -90,
"x": -90
},
"face=wall,facing=east,powered=true": {
"model": "thinkingwithportatos:block/tall_button_pressed",
"y": -90,
"x": -90
},
"face=wall,facing=north,powered=false": {
"model": "thinkingwithportatos:block/tall_button",
"y": -180,
"x": -90
},
"face=wall,facing=north,powered=true": {
"model": "thinkingwithportatos:block/tall_button_pressed",
"y": -180,
"x": -90
},
"face=wall,facing=south,powered=false": {
"model": "thinkingwithportatos:block/tall_button",
"x": -90
},
"face=wall,facing=south,powered=true": {
"model": "thinkingwithportatos:block/tall_button_pressed",
"x": -90
},
"face=wall,facing=west,powered=false": {
"model": "thinkingwithportatos:block/tall_button",
"y": -270,
"x": -90
},
"face=wall,facing=west,powered=true": {
"model": "thinkingwithportatos:block/tall_button_pressed",
"y": -270,
"x": -90
}
}
}
Loading

0 comments on commit d7339ee

Please sign in to comment.