Skip to content

Commit

Permalink
Merge pull request #861 from SkyDynamic/releases/1.20.1
Browse files Browse the repository at this point in the history
添加巨型铁砧
  • Loading branch information
Gu-ZT authored Jun 11, 2024
2 parents ec6bc79 + 8295626 commit f04def1
Show file tree
Hide file tree
Showing 42 changed files with 880 additions and 345 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package dev.dubhe.anvilcraft.api.power;

import dev.dubhe.anvilcraft.AnvilCraft;
import dev.dubhe.anvilcraft.api.chargecollector.ThermoManager;
import dev.dubhe.anvilcraft.network.PowerGridRemovePack;
import dev.dubhe.anvilcraft.network.PowerGridSyncPack;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import net.minecraft.core.Direction;
import net.minecraft.core.Vec3i;
import net.minecraft.data.loot.BlockLootSubProvider;
import net.minecraft.util.StringRepresentable;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.level.Level;
import net.minecraft.world.level.LevelAccessor;
Expand All @@ -16,42 +15,38 @@
import net.minecraft.world.level.material.Fluids;
import org.jetbrains.annotations.NotNull;

public abstract class AbstractMultiplePartBlock
<P extends Enum<P> & Comparable<P> & StringRepresentable & MultiplePartBlockState>
extends Block {
public abstract class AbstractMultiplePartBlock<P extends Enum<P> & MultiplePartBlockState<P>> extends Block {
public AbstractMultiplePartBlock(Properties properties) {
super(properties);
}

protected abstract @NotNull Property<P> getPart();

protected abstract Enum<P>[] getParts();
protected abstract P[] getParts();

protected Vec3i getMainPartOffset() {
return new Vec3i(0, 0, 0);
}

@Override
@SuppressWarnings("deprecation")
public @NotNull BlockState updateShape(
@NotNull BlockState state, @NotNull Direction direction, @NotNull BlockState neighborState,
@NotNull LevelAccessor level, @NotNull BlockPos pos, @NotNull BlockPos neighborPos
) {
MultiplePartBlockState state1;
if (!state.hasProperty(this.getPart())) {
return super.updateShape(state, direction, neighborState, level, pos, neighborPos);
}
state1 = state.getValue(this.getPart());
for (Enum<?> part : getParts()) {
if (part instanceof MultiplePartBlockState state2) {
Vec3i offset = state2.getOffset().subtract(state1.getOffset());
int distance = offset.getX() + offset.getY() + offset.getZ();
if (Math.abs(distance) != 1) continue;
BlockPos pos1 = pos.offset(offset);
BlockState blockState = level.getBlockState(pos1);
if (
!blockState.is(this)
|| !blockState.hasProperty(this.getPart())
|| blockState.getValue(this.getPart()) != state2
) {
return Blocks.AIR.defaultBlockState();
}
MultiplePartBlockState<P> state1 = state.getValue(this.getPart());
for (P part : getParts()) {
Vec3i offset = neighborPos.subtract(pos).offset(state1.getOffset()); // 更新来源偏移值
if (offset.distSqr(part.getOffset()) != 0) continue;
if (
!neighborState.is(this)
|| !neighborState.hasProperty(this.getPart())
|| neighborState.getValue(this.getPart()) != part
) {
return Blocks.AIR.defaultBlockState();
}
}
return super.updateShape(state, direction, neighborState, level, pos, neighborPos);
Expand All @@ -73,8 +68,8 @@ private void preventCreativeDropFromMainPart(
if (!state.is(this)) return;
if (!state.hasProperty(this.getPart())) return;
P value = state.getValue(this.getPart());
if (value.getOffset().distSqr(new Vec3i(0, 0, 0)) == 0) return;
BlockPos mainPartPos = pos.subtract(value.getOffset());
if (value.getOffset().distSqr(this.getMainPartOffset()) == 0) return;
BlockPos mainPartPos = pos.subtract(value.getOffset()).offset(this.getMainPartOffset());
BlockState mainPartState = level.getBlockState(mainPartPos);
if (!mainPartState.is(this)) return;
if (!mainPartState.hasProperty(this.getPart())) return;
Expand All @@ -91,14 +86,12 @@ private void preventCreativeDropFromMainPart(
* @param provider 提供器
* @param block 方块
*/
@SuppressWarnings("unchecked")
public static <T extends Enum<T> & Comparable<T> & StringRepresentable & MultiplePartBlockState> void loot(
public static <T extends Enum<T> & MultiplePartBlockState<T>> void loot(
BlockLootSubProvider provider, @NotNull AbstractMultiplePartBlock<T> block
) {
for (Enum<?> part : block.getParts()) {
if (!(part instanceof MultiplePartBlockState state)) continue;
if (state.getOffset().distSqr(new Vec3i(0, 0, 0)) == 0) {
provider.add(block, provider.createSinglePropConditionTable(block, block.getPart(), (T) part));
for (T part : block.getParts()) {
if (part.getOffset().distSqr(block.getMainPartOffset()) == 0) {
provider.add(block, provider.createSinglePropConditionTable(block, block.getPart(), part));
break;
}
}
Expand Down
Loading

0 comments on commit f04def1

Please sign in to comment.