Skip to content

Commit

Permalink
[Forge] 1.20
Browse files Browse the repository at this point in the history
  • Loading branch information
octylFractal authored and me4502 committed Jun 9, 2023
1 parent a7ae8a9 commit 4f75106
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 29 deletions.
2 changes: 1 addition & 1 deletion buildSrc/build.gradle.kts
Expand Up @@ -52,7 +52,7 @@ dependencies {
implementation("org.jfrog.buildinfo:build-info-extractor-gradle:4.32.0")
implementation("org.spongepowered:spongegradle-plugin-development:2.0.2")
implementation("org.spongepowered:vanillagradle:0.2.1-20220619.210040-41")
implementation("net.minecraftforge.gradle:ForgeGradle:6.0.4")
implementation("net.minecraftforge.gradle:ForgeGradle:6.0.6")
implementation("net.fabricmc:fabric-loom:$loomVersion")
implementation("net.fabricmc:sponge-mixin:$mixinVersion")
implementation("org.enginehub.gradle:gradle-codecov-plugin:0.2.0")
Expand Down
4 changes: 2 additions & 2 deletions worldedit-forge/build.gradle.kts
Expand Up @@ -12,11 +12,11 @@ plugins {
applyPlatformAndCoreConfiguration(javaRelease = 17)
applyShadowConfiguration()

val minecraftVersion = "1.19.4"
val minecraftVersion = "1.20"
val nextMajorMinecraftVersion: String = minecraftVersion.split('.').let { (useless, major) ->
"$useless.${major.toInt() + 1}"
}
val forgeVersion = "45.0.1"
val forgeVersion = "46.0.1"

val apiClasspath = configurations.create("apiClasspath") {
isCanBeResolved = true
Expand Down
Expand Up @@ -22,7 +22,6 @@
import com.sk89q.worldedit.world.registry.BlockMaterial;
import com.sk89q.worldedit.world.registry.PassthroughBlockMaterial;
import net.minecraft.world.level.block.state.BlockState;
import net.minecraft.world.level.material.Material;
import net.minecraft.world.level.material.PushReaction;

import javax.annotation.Nullable;
Expand All @@ -34,53 +33,54 @@
*/
public class ForgeBlockMaterial extends PassthroughBlockMaterial {

private final Material delegate;
private final BlockState block;

public ForgeBlockMaterial(Material delegate, BlockState block, @Nullable BlockMaterial secondary) {
public ForgeBlockMaterial(BlockState block, @Nullable BlockMaterial secondary) {
super(secondary);
this.delegate = delegate;
this.block = block;
}

@Override
public boolean isAir() {
return delegate == Material.AIR || super.isAir();
return block.isAir() || super.isAir();
}

@Override
public boolean isOpaque() {
return delegate.isSolidBlocking();
return block.canOcclude();
}

@SuppressWarnings("deprecation")
@Override
public boolean isLiquid() {
return delegate.isLiquid();
return block.liquid();
}

@SuppressWarnings("deprecation")
@Override
public boolean isSolid() {
return delegate.isSolid();
return block.isSolid();
}

@Override
public boolean isFragileWhenPushed() {
return delegate.getPushReaction() == PushReaction.DESTROY;
return block.getPistonPushReaction() == PushReaction.DESTROY;
}

@Override
public boolean isUnpushable() {
return delegate.getPushReaction() == PushReaction.BLOCK;
return block.getPistonPushReaction() == PushReaction.BLOCK;
}

@SuppressWarnings("deprecation")
@Override
public boolean isMovementBlocker() {
return delegate.blocksMotion();
return block.blocksMotion();
}

@Override
public boolean isBurnable() {
return delegate.isFlammable();
return block.ignitedByLava();
}

@Override
Expand All @@ -90,7 +90,7 @@ public boolean isToolRequired() {

@Override
public boolean isReplacedDuringPlacement() {
return delegate.isReplaceable();
return block.canBeReplaced();
}

}
Expand Up @@ -52,7 +52,7 @@ public BlockMaterial getMaterial(BlockType blockType) {
}
return materialMap.computeIfAbsent(
block.defaultBlockState(),
s -> new ForgeBlockMaterial(s.getMaterial(), s, super.getMaterial(blockType))
s -> new ForgeBlockMaterial(s, super.getMaterial(blockType))
);
}

Expand Down
Expand Up @@ -70,7 +70,7 @@ public Location getLocation() {
float yaw = entity.getYRot();
float pitch = entity.getXRot();

return new Location(ForgeAdapter.adapt((ServerLevel) entity.level), position, yaw, pitch);
return new Location(ForgeAdapter.adapt((ServerLevel) entity.level()), position, yaw, pitch);
} else {
return new Location(NullWorld.getInstance());
}
Expand All @@ -86,7 +86,7 @@ public boolean setLocation(Location location) {
public Extent getExtent() {
net.minecraft.world.entity.Entity entity = entityRef.get();
if (entity != null) {
return ForgeAdapter.adapt((ServerLevel) entity.level);
return ForgeAdapter.adapt((ServerLevel) entity.level());
} else {
return NullWorld.getInstance();
}
Expand Down
Expand Up @@ -98,7 +98,7 @@ public BaseEntity getState() {
public Location getLocation() {
Vector3 position = Vector3.at(this.player.getX(), this.player.getY(), this.player.getZ());
return new Location(
ForgeWorldEdit.inst.getWorld((ServerLevel) this.player.level),
ForgeWorldEdit.inst.getWorld(this.player.serverLevel()),
position,
this.player.getYRot(),
this.player.getXRot());
Expand All @@ -113,12 +113,12 @@ public boolean setLocation(Location location) {
location.getYaw(), location.getPitch()
);
// This may be false if the teleport was cancelled by a mod
return this.player.getLevel() == level;
return this.player.serverLevel() == level;
}

@Override
public World getWorld() {
return ForgeWorldEdit.inst.getWorld((ServerLevel) this.player.level);
return ForgeWorldEdit.inst.getWorld(this.player.serverLevel());
}

@Override
Expand Down
Expand Up @@ -340,7 +340,8 @@ private void doRegen(Region region, Extent extent, RegenOptions options) throws
// No spawners are needed for this world.
ImmutableList.of(),
// This controls ticking, we don't need it so set it to false.
false
false,
originalWorld.getRandomSequences()
)) {
regenForWorld(region, extent, serverWorld, options);

Expand Down Expand Up @@ -465,7 +466,11 @@ public void fixAfterFastMode(Iterable<BlockVector2> chunks) {
public void fixLighting(Iterable<BlockVector2> chunks) {
ServerLevel world = getWorld();
for (BlockVector2 chunk : chunks) {
world.getChunkSource().getLightEngine().retainData(new ChunkPos(chunk.getBlockX(), chunk.getBlockZ()), true);
// Fetch the chunk after light initialization at least
// We'll be doing a full relight anyways, so we don't need to be LIGHT yet
world.getChunkSource().getLightEngine().lightChunk(world.getChunk(
chunk.getBlockX(), chunk.getBlockZ(), ChunkStatus.INITIALIZE_LIGHT
), false);
}
}

Expand Down
Expand Up @@ -279,13 +279,13 @@ public void onPlayerInteract(PlayerInteractEvent event) {
&& lcb.getUseItem() == Event.Result.DENY;
boolean isRightDeny = event instanceof PlayerInteractEvent.RightClickBlock rcb
&& rcb.getUseItem() == Event.Result.DENY;
if (isLeftDeny || isRightDeny || event.getEntity().level.isClientSide || event.getHand() == InteractionHand.OFF_HAND) {
if (isLeftDeny || isRightDeny || event.getEntity().level().isClientSide || event.getHand() == InteractionHand.OFF_HAND) {
return;
}

WorldEdit we = WorldEdit.getInstance();
ForgePlayer player = adaptPlayer((ServerPlayer) event.getEntity());
ForgeWorld world = getWorld((ServerLevel) event.getEntity().level);
ForgeWorld world = getWorld((ServerLevel) event.getEntity().level());
Direction direction = ForgeAdapter.adaptEnumFacing(event.getFace());

if (event instanceof PlayerInteractEvent.LeftClickEmpty) {
Expand Down Expand Up @@ -323,7 +323,7 @@ public void onCommandEvent(CommandEvent event) throws CommandSyntaxException {
if (!(parseResults.getContext().getSource().getEntity() instanceof ServerPlayer player)) {
return;
}
if (player.level.isClientSide) {
if (player.level().isClientSide) {
return;
}
if (parseResults.getContext().getCommand() != CommandWrapper.FAKE_COMMAND) {
Expand Down
Expand Up @@ -26,7 +26,7 @@
import com.sk89q.worldedit.util.SideEffect;
import com.sk89q.worldedit.util.SideEffectSet;
import net.minecraft.core.BlockPos;
import net.minecraft.server.level.ChunkHolder;
import net.minecraft.server.level.FullChunkStatus;
import net.minecraft.server.level.ServerLevel;
import net.minecraft.world.level.block.Block;
import net.minecraft.world.level.block.state.BlockState;
Expand Down Expand Up @@ -115,7 +115,7 @@ public void notifyBlockUpdate(LevelChunk chunk, BlockPos position, BlockState ol

@Override
public boolean isChunkTicking(LevelChunk chunk) {
return chunk.getFullStatus().isOrAfter(ChunkHolder.FullChunkStatus.TICKING);
return chunk.getFullStatus().isOrAfter(FullChunkStatus.BLOCK_TICKING);
}

@Override
Expand Down Expand Up @@ -162,5 +162,6 @@ public void updateNeighbors(BlockPos pos, BlockState oldState, BlockState newSta
@Override
public void onBlockStateChange(BlockPos pos, BlockState oldState, BlockState newState) {
getWorld().onBlockStateChange(pos, oldState, newState);
newState.onBlockStateChange(getWorld(), pos, oldState);
}
}

0 comments on commit 4f75106

Please sign in to comment.