Skip to content

Commit

Permalink
Merge pull request #2456 from Gegy/misc-fixes
Browse files Browse the repository at this point in the history
[1.20.1] A few small bug fixes
  • Loading branch information
Lothrazar authored Jan 7, 2025
2 parents 7d41fa2 + e538428 commit 8dc2b37
Show file tree
Hide file tree
Showing 5 changed files with 63 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -80,19 +80,25 @@ private void normalFlow() {
if (outgoingSide == incomingSide) {
continue;
}
EnumConnectType outgoingConnection = this.getBlockState().getValue(CableBase.FACING_TO_PROPERTY_MAP.get(outgoingSide));
if (outgoingConnection.isExtraction() || outgoingConnection.isBlocked()) {
if (!canPushToSide(outgoingSide)) {
continue;
}
if (this.moveItems(outgoingSide, FLOW_QTY, sideHandler)) {
continue incomingSideLoop; //if items have been moved then change side
}
}
//if no items have been moved then move items in from adjacent
this.moveItems(incomingSide, FLOW_QTY, sideHandler);
if (canPushToSide(incomingSide)) {
// allow items to travel backwards if they have nowhere else to go, instead of getting stuck (see #1677)
this.moveItems(incomingSide, FLOW_QTY, sideHandler);
}
}
}

private boolean canPushToSide(Direction outgoingSide) {
EnumConnectType outgoingConnection = getBlockState().getValue(CableBase.FACING_TO_PROPERTY_MAP.get(outgoingSide));
return !outgoingConnection.isExtraction() && !outgoingConnection.isBlocked();
}

@Override
public <T> LazyOptional<T> getCapability(Capability<T> cap, Direction side) {
if (side != null && cap == ForgeCapabilities.ITEM_HANDLER) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag;
import net.minecraft.nbt.Tag;
import net.minecraft.network.chat.Component;
import net.minecraft.world.MenuProvider;
import net.minecraft.world.entity.player.Inventory;
Expand Down Expand Up @@ -201,6 +202,13 @@ public <T> LazyOptional<T> getCapability(Capability<T> cap, Direction side) {

@Override
public void load(CompoundTag tag) {
// For backwards-compatibility: these weren't always stored, so keep the default
if (tag.contains("size", Tag.TAG_INT)) {
radius = tag.getInt("size");
}
if (tag.contains("height", Tag.TAG_INT)) {
height = tag.getInt("height");
}
shapeIndex = tag.getInt("shapeIndex");
tank.readFromNBT(tag.getCompound(NBTFLUID));
energy.deserializeNBT(tag.getCompound(NBTENERGY));
Expand All @@ -210,6 +218,8 @@ public void load(CompoundTag tag) {

@Override
public void saveAdditional(CompoundTag tag) {
tag.putInt("size", radius);
tag.putInt("height", height);
tag.put(NBTENERGY, energy.serializeNBT());
tag.put(NBTINV, inventory.serializeNBT());
CompoundTag fluid = new CompoundTag();
Expand Down
32 changes: 25 additions & 7 deletions src/main/java/com/lothrazar/cyclic/block/miner/TileMiner.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
import com.lothrazar.cyclic.registry.ItemRegistry;
import com.lothrazar.cyclic.registry.TileRegistry;
import com.lothrazar.library.cap.CustomEnergyStorage;
import net.minecraft.commands.arguments.EntityAnchorArgument;
import com.lothrazar.library.util.ShapeUtil;
import net.minecraft.core.BlockPos;
import net.minecraft.core.Direction;
Expand All @@ -29,6 +30,7 @@
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.block.state.properties.BlockStateProperties;
import net.minecraft.world.phys.AABB;
import net.minecraft.world.phys.Vec3;
import net.minecraftforge.common.ForgeConfigSpec.IntValue;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.ForgeCapabilities;
Expand Down Expand Up @@ -135,6 +137,7 @@ public void load(CompoundTag tag) {
radius = tag.getInt("size");
height = tag.getInt("height");
isCurrentlyMining = tag.getBoolean("isCurrentlyMining");
shapeIndex = tag.getInt("shapeIndex");
directionIsUp = tag.getBoolean("directionIsUp");
energy.deserializeNBT(tag.getCompound(NBTENERGY));
inventory.deserializeNBT(tag.getCompound(NBTINV));
Expand All @@ -146,6 +149,7 @@ public void saveAdditional(CompoundTag tag) {
tag.putInt("size", radius);
tag.putInt("height", height);
tag.putBoolean("isCurrentlyMining", isCurrentlyMining);
tag.putInt("shapeIndex", shapeIndex);
tag.putBoolean("directionIsUp", directionIsUp);
tag.put(NBTENERGY, energy.serializeNBT());
tag.put(NBTINV, inventory.serializeNBT());
Expand Down Expand Up @@ -187,28 +191,30 @@ private boolean updateMiningProgress(List<BlockPos> shape) {
isCurrentlyMining = true;
//then keep current target
}
else { // no valid target, back out
else { // no valid target, back out
updateTargetPos(shape);
resetProgress();
}
Integer cost = POWERCONF.get();
if (energy.getEnergyStored() < cost && cost > 0) {
return false;
}
FakePlayer fakePlayer = this.fakePlayer.get();
//currentlyMining may have changed, and we are still turned on:
if (isCurrentlyMining) {
BlockState targetState = level.getBlockState(targetPos);
float relative = targetState.getDestroyProgress(fakePlayer.get(), level, targetPos);
float relative = targetState.getDestroyProgress(fakePlayer, level, targetPos);
//state.getPlayerRelativeBlockHardness(player, worldIn, pos);UtilItemStack.getPlayerRelativeBlockHardness(targetState.getBlock(), targetState, fakePlayer.get(), world, targetPos);
curBlockDamage += relative;
//
//if hardness is relative, jus fekin break it like air eh
if (curBlockDamage >= 1.0f || relative == 0) {
boolean harvested = fakePlayer.get().gameMode.destroyBlock(targetPos);
placePlayerBehindBlock(fakePlayer, targetPos);
boolean harvested = fakePlayer.gameMode.destroyBlock(targetPos);
if (!harvested) {
// world.destroyBlock(targetPos, true, fakePlayer.get());
//removedByPlayer
harvested = level.getBlockState(targetPos).onDestroyedByPlayer(level, worldPosition, fakePlayer.get(), true, level.getFluidState(worldPosition));
harvested = level.getBlockState(targetPos).onDestroyedByPlayer(level, targetPos, fakePlayer, true, level.getFluidState(targetPos));
// ModCyclic.LOGGER.info("Miner:removedByPlayer hacky workaround " + targetPos);
}
if (harvested) {
Expand All @@ -217,16 +223,28 @@ private boolean updateMiningProgress(List<BlockPos> shape) {
resetProgress();
}
else {
level.destroyBlockProgress(fakePlayer.get().getUUID().hashCode(), targetPos, (int) (curBlockDamage * 10.0F) - 1);
level.destroyBlockProgress(fakePlayer.getUUID().hashCode(), targetPos, (int) (curBlockDamage * 10.0F) - 1);
}
}
}
else { //is mining is false
level.destroyBlockProgress(fakePlayer.get().getUUID().hashCode(), targetPos, (int) (curBlockDamage * 10.0F) - 1);
else { //is mining is false
level.destroyBlockProgress(fakePlayer.getUUID().hashCode(), targetPos, (int) (curBlockDamage * 10.0F) - 1);
}
return false;
}

private void placePlayerBehindBlock(FakePlayer player, BlockPos targetPos) {
// Some items (such as Mattock) use the position of the player relative to the block to determine mining behavior
// Place the fake player just behind the block
Direction facing = getBlockState().getValue(BlockStateProperties.FACING);
player.moveTo(
targetPos.getX() - facing.getStepX() + 0.5,
targetPos.getY() - facing.getStepY() + 0.5 - player.getEyeHeight(),
targetPos.getZ() - facing.getStepZ() + 0.5
);
player.lookAt(EntityAnchorArgument.Anchor.EYES, Vec3.atCenterOf(targetPos));
}

/***
* Unbreakable blocks and fluid blocks are not valid. Otherwise checks if player:canHarvestBlock using its equipped item
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import net.minecraft.client.renderer.MultiBufferSource;
import net.minecraft.client.renderer.blockentity.BlockEntityRenderer;
import net.minecraft.client.renderer.blockentity.BlockEntityRendererProvider;
import net.minecraft.core.BlockPos;
import net.minecraft.world.phys.Vec3;

public class RenderShapedata implements BlockEntityRenderer<TileShapedata> {
Expand All @@ -16,18 +17,26 @@ public RenderShapedata(BlockEntityRendererProvider.Context d) {}
@Override
public void render(TileShapedata te, float v, PoseStack matrixStack, MultiBufferSource ibuffer, int partialTicks, int destroyStage) {
int previewType = te.getField(TileShapedata.Fields.RENDER.ordinal());
if (PreviewOutlineType.NONE.ordinal() == previewType) {
return;
}
BlockPos targetA = te.getTarget(0);
BlockPos targetB = te.getTarget(1);
if (PreviewOutlineType.SHADOW.ordinal() == previewType) {
if (te.getTarget(0) != null) {
RenderBlockUtils.renderOutline(te.getBlockPos(), te.getTarget(0), matrixStack, 1.05F, Color.BLUE);
if (targetA != null) {
RenderBlockUtils.renderOutline(te.getBlockPos(), targetA, matrixStack, 1.05F, Color.BLUE);
}
if (te.getTarget(1) != null) {
RenderBlockUtils.renderOutline(te.getBlockPos(), te.getTarget(1), matrixStack, 1.05F, Color.RED);
if (targetB != null) {
RenderBlockUtils.renderOutline(te.getBlockPos(), targetB, matrixStack, 1.05F, Color.RED);
}
}
else if (PreviewOutlineType.WIREFRAME.ordinal() == previewType) {
// for (BlockPos crd : te.getShapeHollow()) {
RenderBlockUtils.createBox(matrixStack, te.getTarget(0), Vec3.atLowerCornerOf(te.getBlockPos()));
RenderBlockUtils.createBox(matrixStack, te.getTarget(1), Vec3.atLowerCornerOf(te.getBlockPos()));
if (targetA != null) {
RenderBlockUtils.createBox(matrixStack, targetA, Vec3.atLowerCornerOf(te.getBlockPos()));
}
if (targetB != null) {
RenderBlockUtils.createBox(matrixStack, targetB, Vec3.atLowerCornerOf(te.getBlockPos()));
}
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.lothrazar.cyclic.block.shapedata;

import java.util.List;
import javax.annotation.Nullable;
import com.lothrazar.cyclic.ModCyclic;
import com.lothrazar.cyclic.block.TileBlockEntityCyclic;
import com.lothrazar.cyclic.data.PreviewOutlineType;
Expand Down Expand Up @@ -214,6 +215,7 @@ public boolean isAvailable(StructCommands shape) {
return true;
}

@Nullable
public BlockPos getTarget(int s) {
ItemStack stackA = inventory.getStackInSlot(s);
BlockPosDim loc = LocationGpsCard.getPosition(stackA);
Expand Down

0 comments on commit 8dc2b37

Please sign in to comment.