Skip to content

Commit

Permalink
Fix #2 i am sorry to everyone that had to wait this long for me to do…
Browse files Browse the repository at this point in the history
… this
  • Loading branch information
SFort committed Nov 11, 2021
1 parent a6b156b commit 4d30bec
Show file tree
Hide file tree
Showing 4 changed files with 39 additions and 9 deletions.
12 changes: 7 additions & 5 deletions src/main/java/tf/ssf/sfort/lengthyladders/mixin/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class Config implements IMixinConfigPlugin {
private static final String mod = "tf.ssf.sfort.lengthyladders";
public static Logger LOGGER = LogManager.getLogger();

public static boolean LadderScaff = true;
public static Boolean LadderScaff = true;
//public static final boolean fapiLoaded = FabricLoader.getInstance().getAllMods().stream().anyMatch(a->return a.getMetadata().getId().equals("fabric-api-base"));

@Override
Expand All @@ -32,15 +32,15 @@ public void onLoad(String mixinPackage) {
confFile.createNewFile();
List<String> la = Files.readAllLines(confFile.toPath());
List<String> defaultDesc = Arrays.asList(
"^-Should ladders behave like scaffolding [true] true | false"
"^-Should ladders behave like scaffolding [true] true | false | iWantToBreakCompatibility"
);
String[] ls = la.toArray(new String[Math.max(la.size(), defaultDesc.size() * 2)|1]);
final int hash = Arrays.hashCode(ls);
for (int i = 0; i<defaultDesc.size();++i)
ls[i*2+1]= defaultDesc.get(i);

try{LadderScaff = ls[0].contains("true");}catch (Exception ignore){}
ls[0] = String.valueOf(LadderScaff);
try{LadderScaff = ls[0].startsWith("false") ? null : ls[0].contains("true");}catch (Exception ignore){}
ls[0] = LadderScaff == null ? "false" : LadderScaff ? "true" : "iWantToBreakCompatibility";

if (hash != Arrays.hashCode(ls))
Files.write(confFile.toPath(), Arrays.asList(ls));
Expand All @@ -53,7 +53,9 @@ public void onLoad(String mixinPackage) {
public boolean shouldApplyMixin(String targetClassName, String mixinClassName) {
switch (mixinClassName){
case mod+".mixin.MixinItems":
return LadderScaff;
return LadderScaff != null && !LadderScaff;
case mod+".mixin.MixinItemsCompat":
return LadderScaff != null && LadderScaff;
default:
return true;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,10 @@
import net.minecraft.item.Item;
import net.minecraft.item.ItemGroup;
import net.minecraft.item.Items;
import net.minecraft.util.registry.Registry;
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.ModifyArg;
import org.spongepowered.asm.mixin.injection.Redirect;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfoReturnable;
import tf.ssf.sfort.lengthyladders.LadderBlockItem;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package tf.ssf.sfort.lengthyladders.mixin;

import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.LadderBlock;
import net.minecraft.item.BlockItem;
import net.minecraft.item.ItemPlacementContext;
import net.minecraft.util.math.BlockPos;
import net.minecraft.util.math.Direction;
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(BlockItem.class)
public abstract class MixinItemsCompat {
@Shadow public abstract Block getBlock();

@Inject(method = "getPlacementContext(Lnet/minecraft/item/ItemPlacementContext;)Lnet/minecraft/item/ItemPlacementContext;", at=@At("HEAD"), cancellable = true)
private void register(ItemPlacementContext context, CallbackInfoReturnable<ItemPlacementContext> cir){
if(this.getBlock() instanceof LadderBlock){
BlockPos hit = context.getBlockPos().offset(context.getSide().getOpposite());
BlockState state = context.getWorld().getBlockState(hit);
if (state.isOf(this.getBlock()) && state.get(LadderBlock.FACING).equals(context.getSide())) {
cir.setReturnValue(ItemPlacementContext.offset(context, hit.up(), Direction.DOWN));
}
}
}
}
3 changes: 2 additions & 1 deletion src/main/resources/lengthyladders.mixins.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"LongLadder"
],
"client": [
"MixinItems"
"MixinItems",
"MixinItemsCompat"
],
"injectors": {
"defaultRequire": 1
Expand Down

0 comments on commit 4d30bec

Please sign in to comment.