Skip to content

Commit

Permalink
Optional config value to force PolyMc to take over the int id of blocks
Browse files Browse the repository at this point in the history
  • Loading branch information
TheEpicBlock committed Jul 2, 2022
1 parent a78fb14 commit c882014
Show file tree
Hide file tree
Showing 7 changed files with 80 additions and 9 deletions.
9 changes: 8 additions & 1 deletion src/main/java/io/github/theepicblock/polymc/impl/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,13 @@
*/
@SuppressWarnings({"unused", "MismatchedQueryAndUpdateOfCollection", "JavadocReference"})
public class Config {
public static final int LATEST_VERSION = 9;
public static final int LATEST_VERSION = 10;
public MiscConfig misc;
private int configVersion;
private List<String> disabledMixins;
public boolean remapVanillaBlockIds;
public boolean enableWizardThreading;
public boolean forceBlockIdIntControl;
public int maxPacketsPerSecond;

public int getConfigVersion() {
Expand Down Expand Up @@ -80,6 +81,12 @@ public boolean isMixinAutoDisabled(String mixin) {
return FabricLoader.getInstance().isModLoaded("imm_ptl_core");
}

if (mixin.contains("dontforceintcontrol")) {
return !forceBlockIdIntControl;
} else if (mixin.contains("forceintcontrol")) {
return forceBlockIdIntControl;
}

return false;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* PolyMc
* Copyright (C) 2020-2021 TheEpicBlock_TEB
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 3 of the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program; If not, see <https://www.gnu.org/licenses>.
*/
package io.github.theepicblock.polymc.mixins.block.implementations.dontforceintcontrol;

import io.github.theepicblock.polymc.impl.Util;
import net.minecraft.block.BlockState;
import net.minecraft.network.packet.s2c.play.ChunkDeltaUpdateS2CPacket;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.ModifyArg;
import xyz.nucleoid.packettweaker.PacketContext;

@Mixin(ChunkDeltaUpdateS2CPacket.class)
public class ChunkDeltaUpdateImplementation {
@ModifyArg(method = "write", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/Block;getRawIdFromState(Lnet/minecraft/block/BlockState;)I"))
public BlockState getRawIdFromStateRedirect(BlockState state) {
var player = PacketContext.get().getTarget();
var polymap = Util.tryGetPolyMap(player);
return polymap.getClientState(state, player);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.theepicblock.polymc.mixins.block.implementations;
package io.github.theepicblock.polymc.mixins.block.implementations.dontforceintcontrol;

import io.github.theepicblock.polymc.impl.Util;
import net.minecraft.block.Block;
Expand All @@ -18,10 +18,7 @@ private <T> T redirectBlock(T original, IndexedIterable<T> registry) {
if (registry == Block.STATE_IDS) {
var player = PacketContext.get().getTarget();
var polymap = Util.tryGetPolyMap(player);
int clientStateId = polymap.getClientStateRawId((BlockState)original, player);

//noinspection unchecked
return (T)Block.STATE_IDS.get(clientStateId);
return (T)polymap.getClientState((BlockState)original, player);
}
return original;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
* You should have received a copy of the GNU Lesser General Public License
* along with this program; If not, see <https://www.gnu.org/licenses>.
*/
package io.github.theepicblock.polymc.mixins.block.implementations;
package io.github.theepicblock.polymc.mixins.block.implementations.forceintcontrol;

import io.github.theepicblock.polymc.impl.Util;
import net.minecraft.block.BlockState;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package io.github.theepicblock.polymc.mixins.block.implementations.forceintcontrol;

import io.github.theepicblock.polymc.impl.Util;
import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.network.PacketByteBuf;
import net.minecraft.util.collection.IndexedIterable;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Redirect;
import xyz.nucleoid.packettweaker.PacketContext;

@Mixin(PacketByteBuf.class)
public class WriteRegistryValueImplementation {
@Redirect(method = "writeRegistryValue", at = @At(value = "INVOKE", target = "Lnet/minecraft/util/collection/IndexedIterable;getRawId(Ljava/lang/Object;)I"))
private <T> int redirectBlock(IndexedIterable<T> instance, T t) {
if (instance == Block.STATE_IDS) {
var player = PacketContext.get().getTarget();
var polymap = Util.tryGetPolyMap(player);
return polymap.getClientStateRawId((BlockState)t, player);
}
return instance.getRawId(t);
}
}
5 changes: 5 additions & 0 deletions src/main/resources/config_update.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,5 +46,10 @@
"add": {
"maxPacketsPerSecond": 600
}
},
"10": {
"add": {
"forceBlockIdIntControl": false
}
}
}
6 changes: 4 additions & 2 deletions src/main/resources/polymc.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,16 @@
"block.implementations.BedBlockImplementation",
"block.implementations.BreakParticleImplementation",
"block.implementations.ChunkDataPlayerProvider",
"block.implementations.ChunkDeltaUpdateImplementation",
"block.implementations.FallingBlockEntityImplementation",
"block.implementations.IdListImplementation",
"block.implementations.PaletteBlockPolyImplementation",
"block.implementations.TallPlantBreakImplementation",
"block.implementations.TrackedDataImplementation",
"block.implementations.WriteRegistryValueImplementation",
"block.implementations.ZombieBreakDoorImplementation",
"block.implementations.dontforceintcontrol.ChunkDeltaUpdateImplementation",
"block.implementations.dontforceintcontrol.WriteRegistryValueImplementation",
"block.implementations.forceintcontrol.ChunkDeltaUpdateImplementation",
"block.implementations.forceintcontrol.WriteRegistryValueImplementation",
"compat.FabricRegistrySyncDisabler",
"compat.immersive_portals.ChunkDataSyncManagerMixin",
"entity.DisableCustomEntities",
Expand Down

0 comments on commit c882014

Please sign in to comment.