Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update paperweight 1.20.4 - isOpaque does not exist (anymore) #2629

Merged
merged 3 commits into from Mar 17, 2024
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Expand Up @@ -12,6 +12,6 @@ repositories {

dependencies {
// url=https://repo.papermc.io/service/rest/repository/browse/maven-public/io/papermc/paper/dev-bundle/1.20.4-R0.1-SNAPSHOT
the<PaperweightUserDependenciesExtension>().paperDevBundle("1.20.4-R0.1-20240106.182028-62")
the<PaperweightUserDependenciesExtension>().paperDevBundle("1.20.4-R0.1-20240316.193646-135")
compileOnly(libs.paperlib)
}
Expand Up @@ -2,26 +2,22 @@

import com.google.common.base.Suppliers;
import com.sk89q.jnbt.CompoundTag;
import com.sk89q.util.ReflectionUtil;
import com.sk89q.worldedit.bukkit.adapter.Refraction;
import com.sk89q.worldedit.bukkit.adapter.impl.fawe.v1_20_R3.nbt.PaperweightLazyCompoundTag;
import com.sk89q.worldedit.world.registry.BlockMaterial;
import net.minecraft.core.BlockPos;
import net.minecraft.world.level.EmptyBlockGetter;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.EntityBlock;
import net.minecraft.world.level.block.LiquidBlock;
import net.minecraft.world.level.block.entity.BlockEntity;
import net.minecraft.world.level.block.state.BlockBehaviour;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.Fluids;
import net.minecraft.world.level.material.PushReaction;
import org.bukkit.craftbukkit.v1_20_R3.block.data.CraftBlockData;

public class PaperweightBlockMaterial implements BlockMaterial {

private final Block block;
private final BlockState blockState;
private final boolean isTranslucent;
private final CraftBlockData craftBlockData;
private final org.bukkit.Material craftMaterial;
private final int opacity;
Expand All @@ -36,11 +32,6 @@ public PaperweightBlockMaterial(Block block, BlockState blockState) {
this.blockState = blockState;
this.craftBlockData = CraftBlockData.fromData(blockState);
this.craftMaterial = craftBlockData.getMaterial();
BlockBehaviour.Properties blockInfo = ReflectionUtil.getField(BlockBehaviour.class, block,
Refraction.pickName("properties", "aP"));
this.isTranslucent = !(boolean) ReflectionUtil.getField(BlockBehaviour.Properties.class, blockInfo,
Refraction.pickName("canOcclude", "n")
);
opacity = blockState.getLightBlock(EmptyBlockGetter.INSTANCE, BlockPos.ZERO);
BlockEntity tileEntity = !(block instanceof EntityBlock) ? null : ((EntityBlock) block).newBlockEntity(
BlockPos.ZERO,
Expand Down Expand Up @@ -75,7 +66,7 @@ public boolean isFullCube() {

@Override
public boolean isOpaque() {
return blockState.isOpaque();
return blockState.canOcclude();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

!canOcclude()?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've orientated myself on the 1.20.3 source of the BlockStateBase#isOpaque method there
image

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, the same was present in 1.20.4-R0.1-20240106.182028-62 - which is kinda weird as therefor isSolid == isTranslucent == isOpaque lol

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yeah, I'm dumb - didn't invert in isTranslucent

}

@Override
Expand All @@ -85,14 +76,13 @@ public boolean isPowerSource() {

@Override
public boolean isLiquid() {
// TODO: Better check ?
return block instanceof LiquidBlock;
return !blockState.getFluidState().is(Fluids.EMPTY);
}

@Override
public boolean isSolid() {
// TODO: Replace
return blockState.isSolid();
// No access to world -> EmptyBlockGetter
return blockState.isSolidRender(EmptyBlockGetter.INSTANCE, BlockPos.ZERO);
}

@Override
Expand Down Expand Up @@ -158,7 +148,7 @@ public boolean isReplacedDuringPlacement() {

@Override
public boolean isTranslucent() {
return isTranslucent;
return !blockState.canOcclude();
}

@Override
Expand Down