-
-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
c
- Loading branch information
Showing
11 changed files
with
95 additions
and
31 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,50 +1,89 @@ | ||
package fr.hugman.mubble.block; | ||
|
||
import fr.hugman.mubble.Mubble; | ||
import fr.hugman.mubble.registry.SuperMarioContent; | ||
//Komerish is a cool dude. (sometimes (all the ((some)time)) | ||
|
||
import net.minecraft.SharedConstants; | ||
import net.minecraft.block.Block; | ||
import net.minecraft.block.BlockState; | ||
import net.minecraft.block.ShapeContext; | ||
import net.minecraft.item.ItemPlacementContext; | ||
import net.minecraft.server.world.ServerWorld; | ||
import net.minecraft.state.StateManager; | ||
import net.minecraft.state.property.BooleanProperty; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.util.math.random.Random; | ||
import net.minecraft.util.shape.VoxelShape; | ||
import net.minecraft.util.shape.VoxelShapes; | ||
import net.minecraft.world.BlockView; | ||
import net.minecraft.world.World; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
public class BeepBlock extends Block { | ||
private static final int COOLDOWN = SharedConstants.TICKS_PER_SECOND * 4; | ||
public static final BooleanProperty FRAME = BooleanProperty.of("frame"); | ||
|
||
public BeepBlock(Settings settings) { | ||
public final int offset; | ||
|
||
public BeepBlock(Settings settings, int offset) { | ||
super(settings); | ||
setDefaultState(getDefaultState().with(FRAME, false)); | ||
this.offset = offset; | ||
this.setDefaultState(getDefaultState().with(FRAME, false)); | ||
} | ||
|
||
@Override | ||
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) { | ||
builder.add(FRAME); | ||
} | ||
|
||
@Override | ||
public boolean isTranslucent(BlockState state, BlockView world, BlockPos pos) { | ||
return state.get(FRAME); | ||
} | ||
|
||
@Override | ||
public VoxelShape getCollisionShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) { | ||
return state.get(FRAME) ? VoxelShapes.empty() : VoxelShapes.fullCube(); | ||
} | ||
|
||
@Override | ||
public VoxelShape getOutlineShape(BlockState state, BlockView world, BlockPos pos, ShapeContext context) { | ||
if(context.isHolding(this.asItem())) return VoxelShapes.fullCube(); | ||
return state.get(FRAME) ? VoxelShapes.empty() : VoxelShapes.fullCube(); | ||
} | ||
|
||
@Override | ||
public float getAmbientOcclusionLightLevel(BlockState state, BlockView world, BlockPos pos) { | ||
return state.get(FRAME) ? 1.0F : super.getAmbientOcclusionLightLevel(state, world, pos); | ||
} | ||
|
||
@Nullable | ||
@Override | ||
public BlockState getPlacementState(ItemPlacementContext ctx) { | ||
return getStateAtTime(ctx.getWorld().getTime()); | ||
} | ||
|
||
@Override | ||
public void onBlockAdded(BlockState state, World world, BlockPos pos, BlockState oldState, boolean notify) { | ||
world.scheduleBlockTick(pos, state.getBlock(), (int) (80 - world.getTime() %80)); | ||
world.scheduleBlockTick(pos, state.getBlock(), this.getNextUpdateTickDelta(world.getTime())); | ||
} | ||
|
||
@Override | ||
public void scheduledTick(BlockState state, ServerWorld world, BlockPos pos, Random random) { | ||
if(!world.isClient()) { | ||
this.trigger(world, pos, state); | ||
Mubble.LOGGER.info("SPIN ME!"); | ||
world.scheduleBlockTick(pos, state.getBlock(), (int) (80 - world.getTime()%80)); | ||
long worldTime = world.getTime(); | ||
world.setBlockState(pos, getStateAtTime(worldTime)); | ||
world.scheduleBlockTick(pos, state.getBlock(), this.getNextUpdateTickDelta(worldTime)); | ||
} | ||
} | ||
public void trigger(World world, BlockPos pos, BlockState state) { | ||
////////////////world.setBlockState(pos, SuperMarioContent.BEEP_BLOCK_FRAME.getDefaultState(), Block.NOTIFY_LISTENERS); | ||
if (! state.get(FRAME)) { | ||
world.setBlockState(pos, state.with(FRAME, true)); | ||
} | ||
else { | ||
world.setBlockState(pos, state.with(FRAME, false)); | ||
} | ||
|
||
public int getNextUpdateTickDelta(long worldTime) { | ||
int delta = (int) (COOLDOWN - worldTime); | ||
if(delta == 0) return COOLDOWN; | ||
else return delta % COOLDOWN; | ||
} | ||
} | ||
|
||
public BlockState getStateAtTime(long worldTime) { | ||
boolean frame = (int) ((worldTime + this.offset) % (COOLDOWN * 2)) < COOLDOWN; | ||
return this.getDefaultState().with(FRAME, frame); | ||
} | ||
} |
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
7 changes: 7 additions & 0 deletions
7
src/main/resources/assets/mubble/blockstates/blue_beep_block.json
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,7 @@ | ||
{ | ||
"variants": { | ||
"frame=false": { "model": "mubble:block/blue_beep_block" }, | ||
"frame=true": { "model": "mubble:block/beep_block_frame" } | ||
} | ||
} | ||
|
6 changes: 3 additions & 3 deletions
6
src/main/resources/assets/mubble/blockstates/red_beep_block.json
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 |
---|---|---|
@@ -1,7 +1,7 @@ | ||
{ | ||
"variants": { | ||
"": { | ||
"model": "mubble:block/red_beep_block" | ||
} | ||
"frame=false": { "model": "mubble:block/red_beep_block" }, | ||
"frame=true": { "model": "mubble:block/beep_block_frame" } | ||
} | ||
} | ||
|
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
7 changes: 7 additions & 0 deletions
7
src/main/resources/assets/mubble/models/block/blue_beep_block.json
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,7 @@ | ||
{ | ||
"parent": "minecraft:block/cube_all", | ||
"textures": { | ||
"all": "mubble:block/blue_beep_block" | ||
} | ||
} | ||
|
3 changes: 3 additions & 0 deletions
3
src/main/resources/assets/mubble/models/item/blue_beep_block.json
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,3 @@ | ||
{ | ||
"parent": "mubble:block/blue_beep_block" | ||
} |
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
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