Skip to content

Commit

Permalink
Merge pull request Anvil-Dev#742 from dmzz-yyhyy/reinforced_concrete
Browse files Browse the repository at this point in the history
添加钢筋混凝土
  • Loading branch information
Gu-ZT authored May 18, 2024
2 parents 1569ec5 + 900ddfb commit 2822cb0
Show file tree
Hide file tree
Showing 1,335 changed files with 38,873 additions and 25 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package dev.dubhe.anvilcraft.block;

import dev.dubhe.anvilcraft.api.hammer.IHammerRemovable;
import dev.dubhe.anvilcraft.block.state.Color;
import net.minecraft.core.BlockPos;
import net.minecraft.core.cauldron.CauldronInteraction;
import net.minecraft.world.item.ItemStack;
import net.minecraft.world.item.Items;
import net.minecraft.world.level.BlockGetter;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.AbstractCauldronBlock;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.EnumProperty;
import org.jetbrains.annotations.NotNull;

public class CementCauldronBlock extends AbstractCauldronBlock implements IHammerRemovable {
public static final EnumProperty<Color> COLOR =
EnumProperty.create("color", Color.class);

/**
* @param properties 方块属性
*/
public CementCauldronBlock(Properties properties) {
super(properties, CauldronInteraction.EMPTY);
this.registerDefaultState(
this.stateDefinition.any()
.setValue(COLOR, Color.GRAY));
}

@Override
protected void createBlockStateDefinition(
@NotNull StateDefinition.Builder<Block, BlockState> builder) {
builder.add(COLOR);
}

@Override
protected double getContentHeight(@NotNull BlockState state) {
return 0.9375;
}

@Override
public boolean isFull(@NotNull BlockState state) {
return true;
}

@Override
public int getAnalogOutputSignal(@NotNull BlockState state, @NotNull Level level, @NotNull BlockPos pos) {
return 3;
}

@Override
public @NotNull ItemStack getCloneItemStack(
@NotNull BlockGetter level, @NotNull BlockPos pos, @NotNull BlockState state
) {
return new ItemStack(Items.CAULDRON);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
package dev.dubhe.anvilcraft.block;

import dev.dubhe.anvilcraft.block.state.Half;
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.util.RandomSource;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.StateDefinition;
import net.minecraft.world.level.block.state.properties.EnumProperty;
import org.jetbrains.annotations.NotNull;

public class ReinforcedConcreteBlock extends Block {
public static final EnumProperty<Half> HALF = EnumProperty.create("half", Half.class);

/**
* @param properties 方块属性
*/
public ReinforcedConcreteBlock(Properties properties) {
super(properties);
this.registerDefaultState(
this.stateDefinition.any()
.setValue(HALF, Half.MID));
}

@Override
protected void createBlockStateDefinition(
@NotNull StateDefinition.Builder<Block, BlockState> builder) {
builder.add(HALF);
}

@Override
@SuppressWarnings("deprecation")
public void neighborChanged(
@NotNull BlockState state,
@NotNull Level level,
@NotNull BlockPos pos,
@NotNull Block neighborBlock,
@NotNull BlockPos neighborPos,
boolean movedByPiston
) {
if (level.isClientSide) return;
if (neighborPos.getY() == pos.getY()) return;
Half half = state.getValue(HALF);
if (half != Half.MID) {
if (half == Half.TOP && !level.getBlockState(pos.below()).is(this)) {
level.setBlock(pos, state.setValue(HALF, Half.MID), 2);
return;
}
if (half == Half.BOTTOM && !level.getBlockState(pos.above()).is(this)) {
level.setBlock(pos, state.setValue(HALF, Half.MID), 2);
}
} else {
if (level.getBlockState(pos.above()).is(this)
&& level.getBlockState(pos.above()).getValue(HALF) == Half.MID) {
level.setBlock(pos, state.setValue(HALF, Half.BOTTOM), 2);
level.setBlock(pos.above(), state.setValue(HALF, Half.TOP), 2);
return;
}
if (level.getBlockState(pos.below()).is(this)
&& level.getBlockState(pos.below()).getValue(HALF) == Half.MID) {
level.setBlock(pos, state.setValue(HALF, Half.TOP), 2);
level.setBlock(pos.below(), state.setValue(HALF, Half.BOTTOM), 2);
}
}
}

@Override
public void tick(
@NotNull BlockState state,
@NotNull ServerLevel level,
@NotNull BlockPos pos,
@NotNull RandomSource random) {
super.tick(state, level, pos, random);
}
}
38 changes: 38 additions & 0 deletions common/src/main/java/dev/dubhe/anvilcraft/block/state/Color.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package dev.dubhe.anvilcraft.block.state;

import net.minecraft.util.StringRepresentable;
import org.jetbrains.annotations.NotNull;

public enum Color implements StringRepresentable {
BLACK("black"),
BLUE("blue"),
BROWN("brown"),
CYAN("cyan"),
GRAY("gray"),
GREEN("green"),
LIGHT_BLUE("light_blue"),
LIGHT_GRAY("light_gray"),
LIME("lime"),
MAGENTA("magenta"),
ORANGE("orange"),
PINK("pink"),
PURPLE("purple"),
RED("red"),
WHITE("white"),
YELLOW("yellow");

private final String name;

Color(String name) {
this.name = name;
}

public String toString() {
return this.name;
}

@Override
public @NotNull String getSerializedName() {
return this.name;
}
}
15 changes: 15 additions & 0 deletions common/src/main/java/dev/dubhe/anvilcraft/data/RecipeItem.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package dev.dubhe.anvilcraft.data;

import lombok.Getter;
import net.minecraft.core.registries.BuiltInRegistries;
import net.minecraft.tags.TagKey;
import net.minecraft.world.item.Item;
import net.minecraft.world.level.ItemLike;
Expand Down Expand Up @@ -222,4 +223,18 @@ public RecipeItem(double chance, TagKey<Item> itemTagKey, boolean isSelectOne) {
this.count = 1;
this.isSelectOne = isSelectOne;
}

/**
* 获取key
*
* @return key
*/
public String getKey() {
return this.item == null
? this.itemTagKey == null
? ""
: itemTagKey.location().getPath()
: BuiltInRegistries.ITEM
.getKey(this.item.asItem()).getPath();
}
}
Loading

0 comments on commit 2822cb0

Please sign in to comment.