-
-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
make ModifyBlockRenderPowerType call on block updates and block secti…
…on updates
- Loading branch information
Showing
8 changed files
with
151 additions
and
2 deletions.
There are no files selected for viewing
9 changes: 9 additions & 0 deletions
9
origins/src/main/java/io/github/dueris/originspaper/access/BlockStateOwner.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package io.github.dueris.originspaper.access; | ||
|
||
import net.minecraft.core.SectionPos; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
|
||
public interface BlockStateOwner { | ||
void apoli$setBlockState(BlockState state); | ||
BlockState apoli$getBlockState(); | ||
} |
12 changes: 12 additions & 0 deletions
12
origins/src/main/java/io/github/dueris/originspaper/access/SectionBlocksOwner.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package io.github.dueris.originspaper.access; | ||
|
||
import net.minecraft.core.SectionPos; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
|
||
public interface SectionBlocksOwner { | ||
void apoli$setBlockStates(BlockState[] states); | ||
BlockState[] apoli$getBlockStates(); | ||
|
||
SectionPos apoli$sectionPos(); | ||
short[] apoli$positions(); | ||
} |
27 changes: 27 additions & 0 deletions
27
.../src/main/java/io/github/dueris/originspaper/mixin/ClientboundBlockUpdatePacketMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
package io.github.dueris.originspaper.mixin; | ||
|
||
import io.github.dueris.originspaper.access.BlockStateOwner; | ||
import net.minecraft.core.SectionPos; | ||
import net.minecraft.network.protocol.game.ClientboundBlockUpdatePacket; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
|
||
/** | ||
* Need to update blocks for {@link io.github.dueris.originspaper.power.type.ModifyBlockRenderPowerType}... | ||
*/ | ||
@Mixin(ClientboundBlockUpdatePacket.class) | ||
public class ClientboundBlockUpdatePacketMixin implements BlockStateOwner { | ||
@Shadow | ||
public BlockState blockState; | ||
|
||
@Override | ||
public void apoli$setBlockState(BlockState state) { | ||
this.blockState = state; | ||
} | ||
|
||
@Override | ||
public BlockState apoli$getBlockState() { | ||
return this.blockState; | ||
} | ||
} |
42 changes: 42 additions & 0 deletions
42
...n/java/io/github/dueris/originspaper/mixin/ClientboundSectionBlocksUpdatePacketMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package io.github.dueris.originspaper.mixin; | ||
|
||
import io.github.dueris.originspaper.access.BlockStateOwner; | ||
import io.github.dueris.originspaper.access.SectionBlocksOwner; | ||
import net.minecraft.core.SectionPos; | ||
import net.minecraft.network.protocol.game.ClientboundSectionBlocksUpdatePacket; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import org.spongepowered.asm.mixin.Final; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
|
||
/** | ||
* Primarily used to maintain compatibility with {@link io.github.dueris.originspaper.power.type.ModifyBlockRenderPowerType} and plugins | ||
*/ | ||
@Mixin(ClientboundSectionBlocksUpdatePacket.class) | ||
public class ClientboundSectionBlocksUpdatePacketMixin implements SectionBlocksOwner { | ||
@Shadow @Final private BlockState[] states; | ||
|
||
@Shadow @Final private SectionPos sectionPos; | ||
|
||
@Shadow @Final private short[] positions; | ||
|
||
@Override | ||
public void apoli$setBlockStates(BlockState[] states) { | ||
System.arraycopy(states, 0, this.states, 0, states.length); | ||
} | ||
|
||
@Override | ||
public BlockState[] apoli$getBlockStates() { | ||
return this.states; | ||
} | ||
|
||
@Override | ||
public SectionPos apoli$sectionPos() { | ||
return this.sectionPos; | ||
} | ||
|
||
@Override | ||
public short[] apoli$positions() { | ||
return this.positions; | ||
} | ||
} |
48 changes: 48 additions & 0 deletions
48
...rc/main/java/io/github/dueris/originspaper/mixin/ServerCommonPacketListenerImplMixin.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package io.github.dueris.originspaper.mixin; | ||
|
||
import io.github.dueris.originspaper.access.BlockStateOwner; | ||
import io.github.dueris.originspaper.access.SectionBlocksOwner; | ||
import io.github.dueris.originspaper.component.PowerHolderComponent; | ||
import io.github.dueris.originspaper.power.type.ModifyBlockRenderPowerType; | ||
import net.minecraft.network.PacketSendListener; | ||
import net.minecraft.network.protocol.Packet; | ||
import net.minecraft.network.protocol.game.ClientboundBlockUpdatePacket; | ||
import net.minecraft.network.protocol.game.ClientboundSectionBlocksUpdatePacket; | ||
import net.minecraft.server.level.ServerPlayer; | ||
import net.minecraft.server.network.ServerCommonPacketListenerImpl; | ||
import net.minecraft.world.level.block.state.BlockState; | ||
import org.spongepowered.asm.mixin.Final; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Inject; | ||
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo; | ||
|
||
@Mixin(ServerCommonPacketListenerImpl.class) | ||
public class ServerCommonPacketListenerImplMixin { | ||
|
||
@Shadow @Final protected ServerPlayer player; | ||
|
||
@Inject(method = "send(Lnet/minecraft/network/protocol/Packet;Lnet/minecraft/network/PacketSendListener;)V", at = @At("HEAD")) | ||
public void apoli$modifyBlockRender(Packet<?> packet, PacketSendListener callbacks, CallbackInfo ci) { | ||
if (packet instanceof ClientboundBlockUpdatePacket blockUpdatePacket) { | ||
for (ModifyBlockRenderPowerType powerType : PowerHolderComponent.getPowerTypes(player, ModifyBlockRenderPowerType.class)) { | ||
if (powerType.doesPrevent(player.level(), blockUpdatePacket.getPos())) { | ||
((BlockStateOwner) blockUpdatePacket).apoli$setBlockState(powerType.getBlockState()); | ||
} | ||
} | ||
} else if (packet instanceof ClientboundSectionBlocksUpdatePacket sectionBlocksUpdatePacket) { | ||
SectionBlocksOwner sectionBlocksOwner = (SectionBlocksOwner) sectionBlocksUpdatePacket; | ||
BlockState[] states = sectionBlocksOwner.apoli$getBlockStates(); | ||
short[] positions = sectionBlocksOwner.apoli$positions(); | ||
for (ModifyBlockRenderPowerType powerType : PowerHolderComponent.getPowerTypes(player, ModifyBlockRenderPowerType.class)) { | ||
if (powerType.isSending()) continue; | ||
for (int i = 0; i < states.length; i++) { | ||
if (powerType.doesPrevent(player.level(), sectionBlocksOwner.apoli$sectionPos().relativeToBlockPos(positions[i]))) { | ||
states[i] = powerType.getBlockState(); | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters