-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
allow chosing between diffrent item check behaviours
- Loading branch information
Showing
9 changed files
with
133 additions
and
65 deletions.
There are no files selected for viewing
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 was deleted.
Oops, something went wrong.
74 changes: 74 additions & 0 deletions
74
src/main/java/tf/ssf/sfort/invisframes/mixin/FrameConf.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,74 @@ | ||
package tf.ssf.sfort.invisframes.mixin; | ||
|
||
import net.fabricmc.loader.api.FabricLoader; | ||
import org.apache.logging.log4j.Level; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.objectweb.asm.tree.ClassNode; | ||
import org.spongepowered.asm.mixin.extensibility.IMixinConfigPlugin; | ||
import org.spongepowered.asm.mixin.extensibility.IMixinInfo; | ||
|
||
import java.io.File; | ||
import java.nio.file.Files; | ||
import java.util.*; | ||
|
||
public class FrameConf implements IMixinConfigPlugin { | ||
public static final String mixin = "tf.ssf.sfort.invisframes.mixin"; | ||
public static Logger LOGGER = LogManager.getLogger(); | ||
|
||
public static boolean clientForceInvis = false; | ||
public static boolean allowProjectile = false; | ||
//byte0-client, byte1-server | ||
public static int itemCheck = 1; | ||
|
||
@Override | ||
public void onLoad(String mixinPackage) { | ||
// Configs | ||
File confFile = new File( | ||
FabricLoader.getInstance().getConfigDir().toString(), | ||
"InvisFrames.conf" | ||
); | ||
try { | ||
confFile.createNewFile(); | ||
List<String> la = Files.readAllLines(confFile.toPath()); | ||
List<String> defaultDesc = Arrays.asList( | ||
"^-Should client always make frames with items invisible [false] true | false // You would want to use this if the mod is installed client side only", | ||
"^-Allow the use of projectiles for changing visibility [false] true | false //snowballs arrows etc", | ||
"^-Frame has item check [client] client | server | both | none" | ||
); | ||
String[] ls = la.toArray(new String[Math.max(la.size(), defaultDesc.size() * 2)|1]); | ||
for (int i = 0; i<defaultDesc.size();++i) | ||
ls[i*2+1]= defaultDesc.get(i); | ||
|
||
try{clientForceInvis = ls[0].contains("true");}catch (Exception ignore){} | ||
ls[0] = String.valueOf(clientForceInvis); | ||
try{allowProjectile = ls[2].contains("true");}catch (Exception ignore){} | ||
ls[2] = String.valueOf(allowProjectile); | ||
try{ | ||
itemCheck = (ls[4].contains("both")? 3 : ls[4].contains("server")? 2 : ls[4].contains("none")? 0 : 1);}catch (Exception ignore){} | ||
ls[4] = itemCheck == 3 ? "both" : itemCheck == 2 ? "server": itemCheck == 0 ? "none" : "client"; | ||
|
||
Files.write(confFile.toPath(), Arrays.asList(ls)); | ||
LOGGER.log(Level.INFO,"tf.ssf.sfort.invisframes successfully loaded config file"); | ||
} catch(Exception e) { | ||
LOGGER.log(Level.ERROR,"tf.ssf.sfort.invisframes failed to load config file, using defaults\n"+e); | ||
} | ||
} | ||
|
||
|
||
@Override | ||
public boolean shouldApplyMixin(String targetClassName, String mixinClassName) { | ||
return switch (mixinClassName) { | ||
case mixin + ".FrameEntity" -> (itemCheck & 2) == 0; | ||
case mixin + ".FrameEntityServer" -> (itemCheck & 2) != 0; | ||
case mixin + ".FrameRender" -> (itemCheck & 1) != 0 && !clientForceInvis; | ||
case mixin + ".FrameRenderForce" -> (itemCheck & 1) != 0 && clientForceInvis; | ||
default -> true; | ||
}; | ||
} | ||
@Override public String getRefMapperConfig() { return null; } | ||
@Override public void acceptTargets(Set<String> myTargets, Set<String> otherTargets) { } | ||
@Override public List<String> getMixins() { return null; } | ||
@Override public void preApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) { } | ||
@Override public void postApply(String targetClassName, ClassNode targetClass, String mixinClassName, IMixinInfo mixinInfo) { } | ||
} |
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
33 changes: 33 additions & 0 deletions
33
src/main/java/tf/ssf/sfort/invisframes/mixin/FrameEntityServer.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,33 @@ | ||
package tf.ssf.sfort.invisframes.mixin; | ||
|
||
import net.minecraft.entity.Entity; | ||
import net.minecraft.entity.EntityType; | ||
import net.minecraft.entity.damage.DamageSource; | ||
import net.minecraft.entity.decoration.AbstractDecorationEntity; | ||
import net.minecraft.entity.decoration.ItemFrameEntity; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.world.World; | ||
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.CallbackInfoReturnable; | ||
|
||
@Mixin(value = ItemFrameEntity.class, priority = 2111) | ||
public abstract class FrameEntityServer extends AbstractDecorationEntity { | ||
protected FrameEntityServer(EntityType<? extends AbstractDecorationEntity> entityType, World world) { | ||
super(entityType, world); | ||
} | ||
|
||
@Shadow public abstract ItemStack getHeldItemStack(); | ||
|
||
@Inject(method = "damage",at =@At("HEAD"),cancellable = true) | ||
public void damage(DamageSource source, float amount, CallbackInfoReturnable<Boolean> info) { | ||
Entity attacker = source.getAttacker(); | ||
if (attacker !=null && attacker.isSneaky() && (FrameConf.allowProjectile || source.getName().equals("player"))) { | ||
this.setInvisible(!(this.isInvisible() || this.getHeldItemStack().isEmpty())); | ||
info.setReturnValue(true); | ||
}else | ||
this.setInvisible(false); | ||
} | ||
} |
7 changes: 3 additions & 4 deletions
7
.../java/sf/ssf/sfort/mixin/FrameRender.java → .../sfort/invisframes/mixin/FrameRender.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 |
---|---|---|
@@ -1,16 +1,15 @@ | ||
package sf.ssf.sfort.mixin; | ||
package tf.ssf.sfort.invisframes.mixin; | ||
|
||
import net.minecraft.client.render.entity.ItemFrameEntityRenderer; | ||
import net.minecraft.entity.decoration.ItemFrameEntity; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Redirect; | ||
import sf.ssf.sfort.FrameConf; | ||
|
||
@Mixin(ItemFrameEntityRenderer.class) | ||
@Mixin(value = ItemFrameEntityRenderer.class, priority = 2111) | ||
public abstract class FrameRender { | ||
@Redirect(method = "render",at =@At(value = "INVOKE",target = "Lnet/minecraft/entity/decoration/ItemFrameEntity;isInvisible()Z",ordinal = 0)) | ||
public boolean itemBeInvis(ItemFrameEntity itemFrameEntity) { | ||
return itemFrameEntity.isInvisible()&&!itemFrameEntity.getHeldItemStack().isEmpty() || FrameConf.clientForceInvis; | ||
return itemFrameEntity.isInvisible()&&!itemFrameEntity.getHeldItemStack().isEmpty(); | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
src/main/java/tf/ssf/sfort/invisframes/mixin/FrameRenderForce.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,15 @@ | ||
package tf.ssf.sfort.invisframes.mixin; | ||
|
||
import net.minecraft.client.render.entity.ItemFrameEntityRenderer; | ||
import net.minecraft.entity.decoration.ItemFrameEntity; | ||
import org.spongepowered.asm.mixin.Mixin; | ||
import org.spongepowered.asm.mixin.injection.At; | ||
import org.spongepowered.asm.mixin.injection.Redirect; | ||
|
||
@Mixin(value = ItemFrameEntityRenderer.class, priority = 2111) | ||
public abstract class FrameRenderForce { | ||
@Redirect(method = "render",at =@At(value = "INVOKE",target = "Lnet/minecraft/entity/decoration/ItemFrameEntity;isInvisible()Z",ordinal = 0)) | ||
public boolean itemBeInvis(ItemFrameEntity itemFrameEntity) { | ||
return !itemFrameEntity.getHeldItemStack().isEmpty(); | ||
} | ||
} |
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