-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
109 additions
and
0 deletions.
There are no files selected for viewing
14 changes: 14 additions & 0 deletions
14
...ain/java/org/embeddedt/vintagefix/mixin/allocation_rate/AccessorVertexBufferConsumer.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,14 @@ | ||
package org.embeddedt.vintagefix.mixin.allocation_rate; | ||
|
||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraftforge.client.model.pipeline.VertexBufferConsumer; | ||
import org.embeddedt.vintagefix.annotation.ClientOnlyMixin; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.gen.Accessor; | ||
|
||
@Mixin(value = VertexBufferConsumer.class, remap = false) | ||
@ClientOnlyMixin | ||
public interface AccessorVertexBufferConsumer { | ||
@Accessor("offset") | ||
void vintage$setOffset(BlockPos offset); | ||
} |
77 changes: 77 additions & 0 deletions
77
src/main/java/org/embeddedt/vintagefix/mixin/allocation_rate/MixinChunkCache.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,77 @@ | ||
package org.embeddedt.vintagefix.mixin.allocation_rate; | ||
|
||
import net.minecraft.block.state.IBlockState; | ||
import net.minecraft.util.EnumFacing; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.world.ChunkCache; | ||
import net.minecraft.world.EnumSkyBlock; | ||
import net.minecraft.world.World; | ||
import net.minecraft.world.chunk.Chunk; | ||
import org.embeddedt.vintagefix.annotation.ClientOnlyMixin; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.Overwrite; | ||
import org.spongepowered.asm.mixin.Shadow; | ||
|
||
@Mixin(value = ChunkCache.class ,priority = 500) | ||
@ClientOnlyMixin | ||
public abstract class MixinChunkCache { | ||
@Shadow | ||
protected World world; | ||
|
||
@Shadow | ||
public abstract IBlockState getBlockState(BlockPos pos); | ||
|
||
@Shadow | ||
public abstract int getLightFor(EnumSkyBlock type, BlockPos pos); | ||
|
||
@Shadow | ||
protected int chunkX; | ||
|
||
@Shadow | ||
protected int chunkZ; | ||
|
||
@Shadow | ||
protected abstract boolean withinBounds(int x, int z); | ||
|
||
@Shadow | ||
protected Chunk[][] chunkArray; | ||
|
||
/** | ||
* @author embeddedt | ||
* @reason reduce BlockPos allocations when checking neighbor brightness | ||
*/ | ||
@Overwrite | ||
private int getLightForExt(EnumSkyBlock type, BlockPos pos) { | ||
if (type == EnumSkyBlock.SKY && !this.world.provider.hasSkyLight()) { | ||
return 0; | ||
} else if (pos.getY() >= 0 && pos.getY() < 256) { | ||
if (this.getBlockState(pos).useNeighborBrightness()) { | ||
// VintageFix change: use mutable BlockPos so we only allocate once | ||
BlockPos.MutableBlockPos offsetPos = new BlockPos.MutableBlockPos(); | ||
int l = 0; | ||
|
||
for (EnumFacing enumfacing : EnumFacing.VALUES) { | ||
offsetPos.setPos(pos.getX() + enumfacing.getXOffset(), pos.getY() + enumfacing.getYOffset(), pos.getZ() + enumfacing.getZOffset()); | ||
int k = this.getLightFor(type, offsetPos); | ||
|
||
if (k > l) { | ||
l = k; | ||
} | ||
|
||
if (l >= 15) { | ||
return l; | ||
} | ||
} | ||
|
||
return l; | ||
} else { | ||
int i = (pos.getX() >> 4) - this.chunkX; | ||
int j = (pos.getZ() >> 4) - this.chunkZ; | ||
if (!withinBounds(i, j)) return type.defaultLightValue; | ||
return this.chunkArray[i][j].getLightFor(type, pos); | ||
} | ||
} else { | ||
return type.defaultLightValue; | ||
} | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
...ain/java/org/embeddedt/vintagefix/mixin/allocation_rate/MixinForgeBlockModelRenderer.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,18 @@ | ||
package org.embeddedt.vintagefix.mixin.allocation_rate; | ||
|
||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraftforge.client.model.pipeline.ForgeBlockModelRenderer; | ||
import net.minecraftforge.client.model.pipeline.VertexBufferConsumer; | ||
import org.embeddedt.vintagefix.annotation.ClientOnlyMixin; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Redirect; | ||
|
||
@Mixin(ForgeBlockModelRenderer.class) | ||
@ClientOnlyMixin | ||
public class MixinForgeBlockModelRenderer { | ||
@Redirect(method = "*", at = @At(value = "INVOKE", target = "Lnet/minecraftforge/client/model/pipeline/VertexBufferConsumer;setOffset(Lnet/minecraft/util/math/BlockPos;)V"), require = 0) | ||
private void setOffsetWithoutAlloc(VertexBufferConsumer consumer, BlockPos offset) { | ||
((AccessorVertexBufferConsumer)consumer).vintage$setOffset(offset); | ||
} | ||
} |