-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added an item for victorian lilies and updated the Enum and block a bit.
- Loading branch information
Showing
3 changed files
with
123 additions
and
10 deletions.
There are no files selected for viewing
85 changes: 85 additions & 0 deletions
85
src/main/java/net/qzimyion/cellulose/blocks/customBlocks/VictorianLilyBlock.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,85 @@ | ||
package net.qzimyion.cellulose.blocks.customBlocks; | ||
|
||
import net.minecraft.block.Block; | ||
import net.minecraft.block.BlockState; | ||
import net.minecraft.block.HorizontalFacingBlock; | ||
import net.minecraft.block.LilyPadBlock; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.fluid.Fluids; | ||
import net.minecraft.item.ItemPlacementContext; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.state.StateManager; | ||
import net.minecraft.state.property.DirectionProperty; | ||
import net.minecraft.state.property.EnumProperty; | ||
import net.minecraft.util.ActionResult; | ||
import net.minecraft.util.BlockMirror; | ||
import net.minecraft.util.BlockRotation; | ||
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.math.MathHelper; | ||
import net.minecraft.world.World; | ||
import net.minecraft.world.WorldAccess; | ||
import net.qzimyion.cellulose.blocks.CelluloseBlocks; | ||
import net.qzimyion.cellulose.util.VLBlock; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.Objects; | ||
|
||
@SuppressWarnings("deprecation") | ||
public class VictorianLilyBlock extends LilyPadBlock { | ||
public static final DirectionProperty FACING = HorizontalFacingBlock.FACING; | ||
public static final EnumProperty<VLBlock> VL_BLOCK_ENUM_PROPERTY = EnumProperty.of("side", VLBlock.class); | ||
|
||
public VictorianLilyBlock(Settings settings) { | ||
super(settings); | ||
} | ||
|
||
@Override | ||
protected void appendProperties(StateManager.Builder<Block, BlockState> builder) { | ||
builder.add(VL_BLOCK_ENUM_PROPERTY, FACING); | ||
} | ||
|
||
|
||
@Override | ||
public BlockState getStateForNeighborUpdate(BlockState state, Direction direction, BlockState neighborState, WorldAccess world, BlockPos pos, BlockPos neighborPos) { | ||
return validConnections(state, world, pos); | ||
} | ||
|
||
private BlockState validConnections(BlockState state, WorldAccess world, BlockPos pos){ | ||
Direction facing = state.get(FACING); | ||
BlockState N = world.getBlockState(pos.north()); | ||
BlockState S = world.getBlockState(pos.south()); | ||
BlockState E = world.getBlockState(pos.east()); | ||
BlockState W = world.getBlockState(pos.west()); | ||
|
||
boolean c1 = N.getBlock() instanceof VictorianLilyBlock && N.get(FACING)==facing; | ||
boolean c2 = S.getBlock() instanceof VictorianLilyBlock && S.get(FACING)==facing; | ||
boolean c3 = E.getBlock() instanceof VictorianLilyBlock && E.get(FACING)==facing; | ||
boolean c4 = W.getBlock() instanceof VictorianLilyBlock && W.get(FACING)==facing; | ||
VLBlock lilyShape; | ||
if (c1 && c3){ | ||
lilyShape = VLBlock.N_EAST; | ||
} else if (c1 && c4) { | ||
lilyShape = VLBlock.N_WEST; | ||
} else if (c2 && c3) { | ||
lilyShape = VLBlock.S_EAST; | ||
} else { | ||
lilyShape = VLBlock.S_WEST; | ||
} | ||
return state.with(VL_BLOCK_ENUM_PROPERTY, lilyShape); | ||
} | ||
|
||
|
||
@Override | ||
public @Nullable BlockState getPlacementState(ItemPlacementContext ctx) { | ||
return Objects.requireNonNull(super.getPlacementState(ctx)).with(VL_BLOCK_ENUM_PROPERTY, ctx.getHorizontalPlayerFacing().getAxis() == Direction.Axis.X ? VLBlock.X : VLBlock.Z) | ||
.with(FACING, ); | ||
} | ||
|
||
@Override | ||
public BlockState mirror(BlockState state, BlockMirror mirror) { | ||
return state.rotate(mirror.getRotation(state.get(FACING))); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
src/main/java/net/qzimyion/cellulose/items/VictorianLilyItem.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,32 @@ | ||
package net.qzimyion.cellulose.items; | ||
|
||
import net.minecraft.block.Block; | ||
import net.minecraft.block.BlockState; | ||
import net.minecraft.item.ItemPlacementContext; | ||
import net.minecraft.item.PlaceableOnWaterItem; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.world.World; | ||
|
||
public class VictorianLilyItem extends PlaceableOnWaterItem { | ||
|
||
Block block; | ||
public VictorianLilyItem(Block block, Settings settings) { | ||
super(block, settings); | ||
this.block = block; | ||
} | ||
|
||
@Override | ||
protected boolean place(ItemPlacementContext context, BlockState state) { | ||
World world = context.getWorld(); | ||
BlockPos pos = context.getBlockPos(); | ||
for (int dx = 0; dx < 2; dx++) { | ||
for (int dz = 0; dz < 2; dz++) { | ||
BlockPos posToPlace = pos.add(dx, 0, dz); | ||
BlockState lilyPadState = block.getDefaultState(); | ||
world.setBlockState(pos, state, Block.NOTIFY_ALL | Block.REDRAW_ON_MAIN_THREAD | Block.FORCE_STATE); | ||
world.setBlockState(posToPlace, lilyPadState, 27); | ||
} | ||
} | ||
return true; | ||
} | ||
} |
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