Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package dev.dubhe.anvilcraft.api.itemhandler;

import dev.dubhe.anvilcraft.util.Util;
import net.minecraft.world.item.ItemStack;

import java.util.List;
Expand All @@ -12,12 +11,7 @@ public PollableFilteredItemStackHandler(int size) {

@Override
public boolean isItemValid(int slot, ItemStack stack) {
// 临时解决方案
if (Util.findCaller("doClick")) {
return super.isItemValid(slot, stack);
} else {
return getEmptyOrSmallerSlot(stack) == slot && super.isItemValid(slot, stack);
}
return getEmptyOrSmallerSlot(stack) == slot && super.isItemValid(slot, stack);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,9 @@ public boolean isSlotDisabled(int slot) {
}
return false;
}

@Override
public int getMaxStackSize(ItemStack stack) {
return Math.min(this.getMaxStackSize(), stack.getMaxStackSize());
}
}
83 changes: 52 additions & 31 deletions src/main/java/dev/dubhe/anvilcraft/entity/CauldronOutletEntity.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package dev.dubhe.anvilcraft.entity;

import dev.dubhe.anvilcraft.init.entity.ModEntities;
import lombok.Getter;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.core.registries.Registries;
Expand Down Expand Up @@ -40,10 +39,6 @@ public class CauldronOutletEntity extends Entity {
EntityDataSerializers.BLOCK_STATE
);

@Getter
private BlockPos cauldronPos = BlockPos.ZERO;
private Direction attachedDirection = Direction.UP;
private BlockState cauldronState;

// 标记是否处于活塞推动状态
private boolean wasMoving = false;
Expand All @@ -64,18 +59,17 @@ public CauldronOutletEntity(Level level, Vec3 pos, BlockPos cauldronPos, Directi
this.zo = pos.z;
this.noPhysics = true;
this.setInvulnerable(true);
this.cauldronPos = cauldronPos;
this.attachedDirection = attachedDirection;
this.cauldronState = level.getBlockState(cauldronPos);
this.entityData.set(DATA_ATTACHED_DIRECTION, attachedDirection);
this.setCauldronPos(cauldronPos);
this.setAttachedDirection(attachedDirection);
this.setCauldronState(level.getBlockState(cauldronPos));
}

@Override
public void tick() {
super.tick();

if (!this.level().isClientSide) {
BlockState currentState = this.level().getBlockState(this.cauldronPos);
BlockState currentState = this.level().getBlockState(this.getCauldronPos());

// 0. 防止滑步
// 如果有目标位置,在到达之前不要进行新的检测,防止连环推时输出口滑过好几格
Expand All @@ -97,18 +91,18 @@ public void tick() {
// 1. 主动移动检测
// 检查脚下的方块是不是变成了b36
if (currentState.is(Blocks.MOVING_PISTON)) {
BlockEntity be = this.level().getBlockEntity(this.cauldronPos);
BlockEntity be = this.level().getBlockEntity(this.getCauldronPos());
if (be instanceof PistonMovingBlockEntity pistonBe) {
Direction moveDir = getMovementDirection(pistonBe);

if (pistonBe.isSourcePiston()) {
// A:我是源头。炼药锅正在离我而去 -> 立即追过去
BlockPos destPos = this.cauldronPos.relative(moveDir);
BlockPos destPos = this.getCauldronPos().relative(moveDir);
manualMove(destPos);
return;
} else {
// B:我是目的地。说明有方块正在推入这里 -> 检查是不是连环推
BlockPos nextPos = this.cauldronPos.relative(moveDir);
BlockPos nextPos = this.getCauldronPos().relative(moveDir);
BlockState nextState = this.level().getBlockState(nextPos);

boolean isChainPush = false;
Expand Down Expand Up @@ -141,7 +135,7 @@ public void tick() {
if (this.targetPos == null) {
boolean foundPullingPiston = false;
for (Direction dir : Direction.values()) {
BlockPos neighborPos = this.cauldronPos.relative(dir);
BlockPos neighborPos = this.getCauldronPos().relative(dir);
BlockState neighborState = this.level().getBlockState(neighborPos);

if (neighborState.is(Blocks.MOVING_PISTON)) {
Expand All @@ -150,7 +144,7 @@ public void tick() {
Direction moveDir = getMovementDirection(pistonBe);
BlockPos originPos = neighborPos.relative(moveDir.getOpposite());

if (originPos.equals(this.cauldronPos)) {
if (originPos.equals(this.getCauldronPos())) {
// 发现拉取 -> 锁定目标到邻居
manualMove(neighborPos);
foundPullingPiston = true;
Expand All @@ -168,8 +162,8 @@ public void tick() {
this.wasMoving = false;
this.targetPos = null;

if (currentState != this.cauldronState) {
this.cauldronState = currentState;
if (currentState != this.getCauldronState()) {
this.setCauldronState(currentState);
}
// 继续执行物品逻辑
} else {
Expand All @@ -182,6 +176,7 @@ public void tick() {
}

// 物品输出逻辑
BlockPos cauldronPos = this.getCauldronPos();
AABB aabb = new AABB(
cauldronPos.getX() - 0.01,
cauldronPos.getY() - 0.01,
Expand All @@ -190,6 +185,7 @@ public void tick() {
cauldronPos.getY() + 1.01,
cauldronPos.getZ() + 1.01
);
Direction attachedDirection = this.getAttachedDirection();
level().getEntities(EntityType.ITEM, aabb, entity -> !entity.anvilcraft$isAdsorbable()).forEach(entity -> {
Vec3 ejectPos = this.position()
.add(attachedDirection.getStepX() * 0.25, attachedDirection.getStepY() * 0.25, attachedDirection.getStepZ() * 0.25);
Expand Down Expand Up @@ -229,11 +225,10 @@ private Direction getMovementDirection(PistonMovingBlockEntity be) {

private void moveToBlock(BlockPos pos, BlockState state) {
// 计算偏移量,保持实体相对于方块的位置不变
Vec3 offset = this.position().subtract(Vec3.atLowerCornerOf(this.cauldronPos));
this.cauldronPos = pos;
this.cauldronState = state;
Vec3 offset = this.position().subtract(Vec3.atLowerCornerOf(this.getCauldronPos()));
this.setCauldronPos(pos);
this.setCauldronState(state);
this.setPos(Vec3.atLowerCornerOf(pos).add(offset));
this.entityData.set(DATA_CAULDRON_POS, pos);
// 重置状态
this.wasMoving = false;
this.targetPos = null;
Expand All @@ -244,26 +239,55 @@ public boolean isAttackable() {
return false;
}

@Override
public boolean fireImmune() {
return true;
}

@Override
protected void defineSynchedData(SynchedEntityData.Builder builder) {
builder.define(DATA_CAULDRON_POS, BlockPos.ZERO)
.define(DATA_ATTACHED_DIRECTION, Direction.UP)
.define(DATA_CAULDRON_STATE, Blocks.AIR.defaultBlockState());
}

public BlockPos getCauldronPos() {
return this.entityData.get(DATA_CAULDRON_POS);
}

public void setCauldronPos(BlockPos pos) {
this.entityData.set(DATA_CAULDRON_POS, pos);
}

public Direction getAttachedDirection() {
return this.entityData.get(DATA_ATTACHED_DIRECTION);
}

public void setAttachedDirection(Direction direction) {
this.entityData.set(DATA_ATTACHED_DIRECTION, direction);
}

public BlockState getCauldronState() {
return this.entityData.get(DATA_CAULDRON_STATE);
}

public void setCauldronState(BlockState state) {
this.entityData.set(DATA_CAULDRON_STATE, state);
}

@Override
protected void readAdditionalSaveData(CompoundTag compoundTag) {
this.cauldronPos = NbtUtils.readBlockPos(compoundTag, "CauldronPos").orElse(BlockPos.ZERO);
this.attachedDirection = Direction.from3DDataValue(compoundTag.getInt("AttachedDirection"));
this.cauldronState = NbtUtils.readBlockState(this.level().holderLookup(Registries.BLOCK), compoundTag.getCompound("CauldronState"));
this.entityData.set(DATA_ATTACHED_DIRECTION, this.attachedDirection);
this.setCauldronPos(NbtUtils.readBlockPos(compoundTag, "CauldronPos").orElse(BlockPos.ZERO));
this.setAttachedDirection(Direction.from3DDataValue(compoundTag.getInt("AttachedDirection")));
this.setCauldronState(NbtUtils.readBlockState(this.level().holderLookup(Registries.BLOCK),
compoundTag.getCompound("CauldronState")));
}

@Override
protected void addAdditionalSaveData(CompoundTag compoundTag) {
compoundTag.put("CauldronState", NbtUtils.writeBlockState(this.cauldronState));
compoundTag.put("CauldronPos", NbtUtils.writeBlockPos(this.cauldronPos));
compoundTag.putInt("AttachedDirection", this.attachedDirection.get3DDataValue());
compoundTag.put("CauldronState", NbtUtils.writeBlockState(this.getCauldronState()));
compoundTag.put("CauldronPos", NbtUtils.writeBlockPos(this.getCauldronPos()));
compoundTag.putInt("AttachedDirection", this.getAttachedDirection().get3DDataValue());
}

@Override
Expand All @@ -276,7 +300,4 @@ public PushReaction getPistonPushReaction() {
return PushReaction.IGNORE;
}

public Direction getAttachedDirection() {
return this.entityData.get(DATA_ATTACHED_DIRECTION);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ public boolean isAttackable() {
return false;
}

@Override
public boolean fireImmune() {
return true;
}

@Override
protected void defineSynchedData(SynchedEntityData.Builder builder) {
builder.define(DATA_BLOCK_POS, BlockPos.ZERO).define(DATA_BLOCK_STATE, Blocks.AIR.defaultBlockState());
Expand Down
9 changes: 3 additions & 6 deletions src/main/java/dev/dubhe/anvilcraft/init/block/ModBlocks.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@
import dev.dubhe.anvilcraft.block.BerryCakeBlock;
import dev.dubhe.anvilcraft.block.BerryCreamBlock;
import dev.dubhe.anvilcraft.block.BlackHoleBlock;
import dev.dubhe.anvilcraft.block.FrostMetalBlock;
import dev.dubhe.anvilcraft.block.WhiteHoleBlock;
import dev.dubhe.anvilcraft.block.BlockComparatorBlock;
import dev.dubhe.anvilcraft.block.BlockDevourerBlock;
import dev.dubhe.anvilcraft.block.BlockPlacerBlock;
Expand Down Expand Up @@ -47,6 +45,7 @@
import dev.dubhe.anvilcraft.block.FerriteCoreMagnetBlock;
import dev.dubhe.anvilcraft.block.FireCauldronBlock;
import dev.dubhe.anvilcraft.block.FlintBlock;
import dev.dubhe.anvilcraft.block.FrostMetalBlock;
import dev.dubhe.anvilcraft.block.GiantAnvilBlock;
import dev.dubhe.anvilcraft.block.GunpowderBlock;
import dev.dubhe.anvilcraft.block.HeatCollectorBlock;
Expand Down Expand Up @@ -117,6 +116,7 @@
import dev.dubhe.anvilcraft.block.TransparentCraftingTableBlock;
import dev.dubhe.anvilcraft.block.VoidEnergyCollectorBlock;
import dev.dubhe.anvilcraft.block.VoidMatterBlock;
import dev.dubhe.anvilcraft.block.WhiteHoleBlock;
import dev.dubhe.anvilcraft.block.heatable.GlowingBlock;
import dev.dubhe.anvilcraft.block.heatable.HeatedBlock;
import dev.dubhe.anvilcraft.block.heatable.IncandescentBlock;
Expand Down Expand Up @@ -232,10 +232,7 @@
import static dev.dubhe.anvilcraft.api.power.IPowerComponent.OVERLOAD;
import static dev.dubhe.anvilcraft.api.power.IPowerComponent.SWITCH;

@SuppressWarnings({
"unused",
"CodeBlock2Expr"
})
@SuppressWarnings({"unused", "CodeBlock2Expr"})
public class ModBlocks {
static {
REGISTRATE.defaultCreativeTab(ModItemGroups.ANVILCRAFT_FUNCTION_BLOCK.getKey());
Expand Down
3 changes: 2 additions & 1 deletion src/main/java/dev/dubhe/anvilcraft/init/item/ModItems.java
Original file line number Diff line number Diff line change
Expand Up @@ -721,7 +721,8 @@ public class ModItems {
ItemTags.MINING_ENCHANTABLE,
ItemTags.FISHING_ENCHANTABLE,
ItemTags.STRIDER_TEMPT_ITEMS
).properties((properties) -> properties.durability(2031)).model(DataGenUtil::noExtraModelOrState).register();
).properties((properties) -> properties.durability(2031).fireResistant())
.model(DataGenUtil::noExtraModelOrState).register();

public static final ItemEntry<? extends SpectralSlingshotItem> SPECTRAL_SLINGSHOT = REGISTRATE
.item("spectral_slingshot", SpectralSlingshotItem::new)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -218,7 +218,6 @@ public static void registerRecipes(IRecipeRegistration registration) {
}

public static void registerRecipeCatalysts(IRecipeCatalystRegistration registration) {
registration.addRecipeCatalyst(ModBlocks.CURSED_GOLD_BLOCK.asStack(), AnvilCraftJeiPlugin.TRANSCENDIUM_RECIPE);
registration.addRecipeCatalyst(new ItemStack(Items.ANVIL), AnvilCraftJeiPlugin.TRANSCENDIUM_RECIPE);
registration.addRecipeCatalyst(new ItemStack(ModBlocks.ROYAL_ANVIL), AnvilCraftJeiPlugin.TRANSCENDIUM_RECIPE);
registration.addRecipeCatalyst(new ItemStack(ModBlocks.EMBER_ANVIL), AnvilCraftJeiPlugin.TRANSCENDIUM_RECIPE);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ public class EmberMetalResonatorItem extends ResonatorItem {
public EmberMetalResonatorItem(Properties properties) {
super(
ModTiers.EMBER_METAL,
properties
properties.fireResistant()
.attributes(ResonatorItem.createAttributes(ModTiers.EMBER_METAL, 10, -3f))
.component(ModComponents.FIRE_REFORGING, Unit.INSTANCE)
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ public class FrostMetalAxeItem extends AxeItem {
public FrostMetalAxeItem(Properties properties) {
super(
ModTiers.FROST_METAL,
properties.fireResistant()
.attributes(AxeItem.createAttributes(ModTiers.FROST_METAL, 9, -3f))
properties.attributes(AxeItem.createAttributes(ModTiers.FROST_METAL, 9, -3f))
.component(ModComponents.MERCILESS, Merciless.DEFAULT)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ public class FrostMetalHoeItem extends HoeItem {
public FrostMetalHoeItem(Properties properties) {
super(
ModTiers.FROST_METAL,
properties.fireResistant()
.attributes(HoeItem.createAttributes(ModTiers.FROST_METAL, 1, 0))
properties.attributes(HoeItem.createAttributes(ModTiers.FROST_METAL, 1, 0))
.component(ModComponents.MERCILESS, Merciless.DEFAULT)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ public class FrostMetalPickaxeItem extends PickaxeItem {
public FrostMetalPickaxeItem(Properties properties) {
super(
ModTiers.FROST_METAL,
properties.fireResistant()
.attributes(PickaxeItem.createAttributes(ModTiers.FROST_METAL, 4, -2.8f))
properties.attributes(PickaxeItem.createAttributes(ModTiers.FROST_METAL, 4, -2.8f))
.component(ModComponents.MERCILESS, Merciless.DEFAULT)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ public class FrostMetalShovelItem extends ShovelItem {
public FrostMetalShovelItem(Properties properties) {
super(
ModTiers.FROST_METAL,
properties.fireResistant()
.attributes(ShovelItem.createAttributes(ModTiers.FROST_METAL, 5, -3f))
properties.attributes(ShovelItem.createAttributes(ModTiers.FROST_METAL, 5, -3f))
.component(ModComponents.MERCILESS, Merciless.DEFAULT)
);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,7 @@ public class FrostMetalSwordItem extends SwordItem {
public FrostMetalSwordItem(Properties properties) {
super(
ModTiers.FROST_METAL,
properties.fireResistant()
.attributes(SwordItem.createAttributes(ModTiers.FROST_METAL, 7, -2.4f))
properties.attributes(SwordItem.createAttributes(ModTiers.FROST_METAL, 7, -2.4f))
.component(ModComponents.MERCILESS, Merciless.DEFAULT)
);
}
Expand Down
4 changes: 1 addition & 3 deletions src/main/java/dev/dubhe/anvilcraft/item/ResonatorItem.java
Original file line number Diff line number Diff line change
Expand Up @@ -70,9 +70,7 @@ public abstract class ResonatorItem extends TieredItem {
public ResonatorItem(Tier tier, Properties properties) {
super(
tier,
properties
.component(DataComponents.TOOL, createToolProperties(tier))
.fireResistant()
properties.component(DataComponents.TOOL, createToolProperties(tier))
);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public class TranscendenceResonatorItem extends ResonatorItem {
public TranscendenceResonatorItem(Properties properties) {
super(
ModTiers.TRANSCENDIUM,
properties
properties.fireResistant()
.attributes(ResonatorItem.createAttributes(ModTiers.TRANSCENDIUM, 17, -3f))
.component(ModComponents.MULTIPHASE, new MultiphaseRef())
.component(DataComponents.ITEM_NAME, Multiphase.firstPhaseName(NAME))
Expand Down