Skip to content

Commit

Permalink
Port to 1.12.2
Browse files Browse the repository at this point in the history
  • Loading branch information
tr7zw committed Oct 3, 2023
1 parent d423d28 commit 7846e24
Show file tree
Hide file tree
Showing 10 changed files with 61 additions and 76 deletions.
64 changes: 27 additions & 37 deletions EntityCulling-Forge/build.gradle
Original file line number Diff line number Diff line change
@@ -1,23 +1,24 @@
buildscript {
repositories {
//new forge repository
maven { url "https://maven.minecraftforge.net" }
maven { url 'https://repo.spongepowered.org/maven'}
maven { url = 'https://maven.minecraftforge.net/' }
mavenCentral()
maven {
name = "Sponge"
url = "https://repo.spongepowered.org/repository/maven-public/"
}
}
dependencies {
classpath "net.minecraftforge.gradle:ForgeGradle:2.1-SNAPSHOT"
classpath 'org.spongepowered:mixingradle:0.6-SNAPSHOT'
classpath 'net.minecraftforge.gradle:ForgeGradle:4.+'
classpath 'org.spongepowered:mixingradle:0.7-SNAPSHOT'
}
}

plugins {
id "java"
id "com.github.johnrengelman.shadow" version "2.0.4"
//id "forge" version "ddb1eb0" //ddb1eb0
//id 'org.spongepowered.mixin' version "d5f9873"
}

apply plugin: "net.minecraftforge.gradle.forge"
apply plugin: 'net.minecraftforge.gradle'
apply plugin: 'org.spongepowered.mixin'

repositories {
Expand All @@ -36,17 +37,11 @@ sourceCompatibility = targetCompatibility = 1.8
compileJava.options.encoding = 'UTF-8'

minecraft {
version = "1.8.9-11.15.1.2318-1.8.9"
mappings = "stable_22"
runDir = "run"
replace('@NAME@', "EntityCulling")
replace('@VER@': project.mod_version)
replace('@ID@', "entityculling")
makeObfSourceJar = false
/*clientRunArgs += "--tweakClass"
clientRunArgs += "org.spongepowered.asm.launch.MixinTweaker"
clientRunArgs += "--mixin"
clientRunArgs += "entityculling.mixins.json"*/
mappings channel: 'snapshot', version: '20171003-1.12'
// clientRunArgs += "--tweakClass"
// clientRunArgs += "org.spongepowered.asm.launch.MixinTweaker"
// clientRunArgs += "--mixin"
// clientRunArgs += "waveycapes.mixins.json"
}

configurations {
Expand Down Expand Up @@ -76,20 +71,23 @@ repositories {

dependencies {
// annotationProcessor 'org.spongepowered:mixin:0.7.11-SNAPSHOT'
minecraft 'net.minecraftforge:forge:1.12.2-14.23.5.2860'
annotationProcessor 'org.spongepowered:mixin:0.8.5'
annotationProcessor 'com.google.code.gson:gson:2.9.0'
annotationProcessor 'com.google.guava:guava:31.1-jre'
annotationProcessor 'org.ow2.asm:asm:9.3'
annotationProcessor 'org.ow2.asm:asm-tree:9.3'

include "com.logisticscraft:occlusionculling:${project.occlusionculling_version}"

include 'org.spongepowered:mixin:0.7.11-SNAPSHOT'
include 'org.spongepowered:mixin:0.8.5'

sourceSets.main.java.srcDirs += new File(project.rootDir, "EntityCulling-Shared/src/main/java");//(project(':EntityCulling-Shared').sourceSets.main.java.srcDirs)
sourceSets.main.resources.srcDirs += new File(project.rootDir, "EntityCulling-Shared/src/main/resources");//sourceSets.main.resources.srcDirs += (project(':EntityCulling-Shared').sourceSets.main.resources.srcDirs)
}


mixin {
defaultObfuscationEnv = "notch"
}

shadowJar {
finalizedBy('reobfJar')
// archiveClassifier.set('')
configurations = [project.configurations.include]
duplicatesStrategy DuplicatesStrategy.EXCLUDE
Expand All @@ -116,14 +114,14 @@ shadowJar {

processResources {
inputs.property 'version', project.version
inputs.property 'mcversion', project.minecraft.version
inputs.property 'mcversion', '1.12.2'
inputs.property 'name', 'entityculling'
inputs.property 'modid', 'entityculling'
from(sourceSets.main.resources.srcDirs) {
include 'mcmod.info'
expand (
'version':project.version,
'mcversion':project.minecraft.version,
'mcversion':'1.12.2',
'name':'EntityCulling',
'modid': 'entityculling'
)
Expand All @@ -145,6 +143,7 @@ moveResources.dependsOn processResources
classes.dependsOn moveResources

jar {
finalizedBy('shadowJar')
manifest.attributes(
"ForceLoadAsMod": true,
"ModSide": "CLIENT",
Expand All @@ -154,19 +153,11 @@ jar {
"Manifest-Version": 1.0
)

enabled = false
}

mixin {
disableRefMapWarning = true
defaultObfuscationEnv searge
add sourceSets.main, "entityculling.refmap.json"
}

reobf {
shadowJar {
mappingType = "SEARGE"
}
defaultObfuscationEnv = 'searge'
}

sourceSets {
Expand All @@ -175,4 +166,3 @@ sourceSets {
}
}

tasks.reobfJar.dependsOn(shadowJar)
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import java.util.ConcurrentModificationException;
import java.util.Iterator;
import java.util.Map.Entry;
import java.util.Set;

import com.logisticscraft.occlusionculling.OcclusionCullingInstance;
Expand All @@ -13,10 +12,8 @@
import net.minecraft.entity.Entity;
import net.minecraft.entity.item.EntityArmorStand;
import net.minecraft.tileentity.TileEntity;
import net.minecraft.util.AxisAlignedBB;
import net.minecraft.util.BlockPos;
import net.minecraft.util.Vec3;
import net.minecraft.world.chunk.Chunk;
import net.minecraft.util.math.AxisAlignedBB;
import net.minecraft.util.math.BlockPos;

public class CullTask implements Runnable {

Expand Down Expand Up @@ -45,21 +42,21 @@ public void run() {
try {
Thread.sleep(sleepDelay);

if (EntityCullingModBase.enabled && client.theWorld != null && client.thePlayer != null && client.thePlayer.ticksExisted > 10 && client.getRenderViewEntity() != null) {
Vec3 cameraMC = null;
if (EntityCullingModBase.enabled && client.world != null && client.player != null && client.player.ticksExisted > 10 && client.getRenderViewEntity() != null) {
net.minecraft.util.math.Vec3d cameraMC = null;
if(EntityCullingModBase.instance.config.debugMode) {
cameraMC = client.thePlayer.getPositionEyes(0);
cameraMC = client.player.getPositionEyes(0);
} else {
cameraMC = getCameraPos();
}
if (requestCull || !(cameraMC.xCoord == lastPos.x && cameraMC.yCoord == lastPos.y && cameraMC.zCoord == lastPos.z)) {
if (requestCull || !(cameraMC.x == lastPos.x && cameraMC.y == lastPos.y && cameraMC.z == lastPos.z)) {
long start = System.currentTimeMillis();
requestCull = false;
lastPos.set(cameraMC.xCoord, cameraMC.yCoord, cameraMC.zCoord);
lastPos.set(cameraMC.x, cameraMC.y, cameraMC.z);
Vec3d camera = lastPos;
culling.resetCache();
boolean noCulling = client.thePlayer.isSpectator() || client.gameSettings.thirdPersonView != 0;
Iterator<TileEntity> iterator = client.theWorld.loadedTileEntityList.iterator();
boolean noCulling = client.player.isSpectator() || client.gameSettings.thirdPersonView != 0;
Iterator<TileEntity> iterator = client.world.loadedTileEntityList.iterator();
TileEntity entry;
while(iterator.hasNext()) {
try {
Expand All @@ -78,7 +75,7 @@ public void run() {
continue;
}
BlockPos pos = entry.getPos();
if(pos.distanceSq(cameraMC.xCoord, cameraMC.yCoord, cameraMC.zCoord) < 64*64) { // 64 is the fixed max tile view distance
if(pos.distanceSq(cameraMC.x, cameraMC.y, cameraMC.z) < 64*64) { // 64 is the fixed max tile view distance
aabbMin.set(pos.getX(), pos.getY(), pos.getZ());
aabbMax.set(pos.getX()+1d, pos.getY()+1d, pos.getZ()+1d);
boolean visible = culling.isAABBVisible(aabbMin, aabbMax, camera);
Expand All @@ -88,7 +85,7 @@ public void run() {
}
}
Entity entity = null;
Iterator<Entity> iterable = client.theWorld.getLoadedEntityList().iterator();
Iterator<Entity> iterable = client.world.getLoadedEntityList().iterator();
while (iterable.hasNext()) {
try {
entity = iterable.next();
Expand Down Expand Up @@ -131,7 +128,7 @@ public void run() {
}

// 1.8 doesnt know where the heck the camera is... what?!?
private Vec3 getCameraPos() {
private net.minecraft.util.math.Vec3d getCameraPos() {
if (client.gameSettings.thirdPersonView == 0) {
return client.getRenderViewEntity().getPositionEyes(0);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@
import java.io.IOException;
import java.nio.charset.StandardCharsets;
import java.nio.file.Files;
import java.util.HashSet;
import java.util.Set;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;
Expand All @@ -14,8 +12,8 @@
import net.minecraft.client.Minecraft;
import net.minecraft.client.entity.EntityPlayerSP;
import net.minecraft.client.settings.KeyBinding;
import net.minecraft.util.ChatComponentText;
import net.minecraft.util.IChatComponent;
import net.minecraft.util.text.ChatType;
import net.minecraft.util.text.TextComponentString;

public abstract class EntityCullingModBase {

Expand Down Expand Up @@ -91,14 +89,14 @@ public void clientTick() {
return;
pressed = true;
enabled = !enabled;
EntityPlayerSP player = Minecraft.getMinecraft().thePlayer;
EntityPlayerSP player = Minecraft.getMinecraft().player;
if(enabled) {
if (player != null) {
player.addChatMessage(new ChatComponentText("Culling on"));
Minecraft.getMinecraft().ingameGUI.addChatMessage(ChatType.SYSTEM, new TextComponentString("Culling on"));
}
} else {
if (player != null) {
player.addChatMessage(new ChatComponentText("Culling off"));
Minecraft.getMinecraft().ingameGUI.addChatMessage(ChatType.SYSTEM, new TextComponentString("Culling off"));
}
}
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@

import com.logisticscraft.occlusionculling.DataProvider;

import net.minecraft.block.state.IBlockState;
import net.minecraft.client.Minecraft;
import net.minecraft.client.multiplayer.WorldClient;
import net.minecraft.util.BlockPos;
import net.minecraft.util.math.BlockPos;

public class Provider implements DataProvider {

Expand All @@ -13,14 +14,15 @@ public class Provider implements DataProvider {

@Override
public boolean prepareChunk(int chunkX, int chunkZ) {
world = client.theWorld;
world = client.world;
return world != null;
}

@Override
public boolean isOpaqueFullCube(int x, int y, int z) {
BlockPos pos = new BlockPos(x, y, z);
return world.getBlockState(pos).getBlock().isOpaqueCube();
IBlockState state = world.getBlockState(pos);
return state.getBlock().isOpaqueCube(state);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,6 @@ public interface EntityRendererInter<T extends Entity> {

boolean shadowShouldShowName(T entity);

void shadowRenderNameTag(T entity, double p_renderName_2_, double offsetX, double offsetY);
void shadowRenderNameTag(T entity, double x, double y, double z);

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,8 @@
@Mixin(TileEntityRendererDispatcher.class)
public class BlockEntityRenderDispatcherMixin {

@Inject(method = "Lnet/minecraft/client/renderer/tileentity/TileEntityRendererDispatcher;renderTileEntityAt(Lnet/minecraft/tileentity/TileEntity;DDDFI)V", at = @At("HEAD"), cancellable = true)
public void renderTileEntityAt(TileEntity blockEntity, double p_renderTileEntityAt_2_, double d1,
double d2, float f1, int p_renderTileEntityAt_9_, CallbackInfo info) {
@Inject(method = "Lnet/minecraft/client/renderer/tileentity/TileEntityRendererDispatcher;render(Lnet/minecraft/tileentity/TileEntity;DDDFIF)V", at = @At("HEAD"), cancellable = true)
public void renderTileEntityAt(TileEntity blockEntity, double x, double y, double z, float partialTicks, int destroyStage, float p_192854_10_, CallbackInfo info) {
if (!((Cullable) blockEntity).isForcedVisible() && ((Cullable) blockEntity).isCulled()) {
EntityCullingModBase.instance.skippedBlockEntities++;
info.cancel();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,12 +16,12 @@ public boolean shadowShouldShowName(T entity) {
}

@Override
public void shadowRenderNameTag(T p_renderName_1_, double p_renderName_2_, double d1, double d2) {
renderName(p_renderName_1_, p_renderName_2_, d1, d2);
public void shadowRenderNameTag(T p_renderName_1_, double x, double y, double z) {
renderName(p_renderName_1_, x, y, z);
}

@Shadow
protected abstract void renderName(T p_renderName_1_, double p_renderName_2_, double d1, double d2);
protected abstract void renderName(T p_renderName_1_, double x, double y, double z);

@Shadow
protected abstract boolean canRenderName(T p_canRenderName_1_);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
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;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;

import dev.tr7zw.entityculling.EntityCullingModBase;
import dev.tr7zw.entityculling.access.Cullable;
import dev.tr7zw.entityculling.access.EntityRendererInter;
import net.minecraft.client.renderer.EntityRenderer;
import net.minecraft.client.renderer.entity.Render;
import net.minecraft.client.renderer.entity.RenderManager;
import net.minecraft.entity.Entity;
Expand All @@ -23,14 +23,13 @@ public abstract class WorldRendererMixin {
@Shadow
public abstract <T extends Entity> Render<T> getEntityRenderObject(Entity p_getEntityRenderObject_1_);

@Inject(at = @At("HEAD"), method = "doRenderEntity", cancellable = true)
public void doRenderEntity(Entity entity, double p_doRenderEntity_2_, double d1, double d2,
float tickDelta, float p_doRenderEntity_9_, boolean p_doRenderEntity_10_, CallbackInfoReturnable<Boolean> info) {
@Inject(at = @At("HEAD"), method = "renderEntity", cancellable = true)
public void doRenderEntity(Entity entity, double x, double y, double z, float yaw, float partialTicks, boolean p_188391_10_, CallbackInfo info) {
Cullable cullable = (Cullable) entity;
if (!cullable.isForcedVisible() && cullable.isCulled()) {
EntityRendererInter<Entity> entityRenderer = (EntityRendererInter) getEntityRenderObject(entity);
if (EntityCullingModBase.instance.config.renderNametagsThroughWalls && entityRenderer.shadowShouldShowName(entity)) {
entityRenderer.shadowRenderNameTag(entity, p_doRenderEntity_2_, d1, d2);
entityRenderer.shadowRenderNameTag(entity, x, y, z);
//entityRenderer.doRender(entity, entity.posX, entity.posY, entity.posZ, tickDelta, tickDelta);
}
EntityCullingModBase.instance.skippedEntities++;
Expand Down
2 changes: 1 addition & 1 deletion gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ mod_version=1.6.2
maven_group=de.tr7zw

# Fabric/Forge settings
minecraft_version=1.8.9
minecraft_version=1.12.2
loader_version=0.11.3
fabric_version=0.34.9+1.17

Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-4.2.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.9.1-all.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists

0 comments on commit 7846e24

Please sign in to comment.