Skip to content

Commit

Permalink
Backport mod to 1.8.9 with Legacy Fabric
Browse files Browse the repository at this point in the history
Some code changes needed! These new mixins are a bit more invasive than I hoped to make them, but there’s unlikely to be many problems with them...
  • Loading branch information
NeRdTheNed committed Nov 25, 2020
1 parent 2a20136 commit a67018f
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 19 deletions.
4 changes: 2 additions & 2 deletions .github/workflows/draftrelease.yml
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
# This workflow will build a Java project with Gradle
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle

name: fabric-1.16 - Draft release
name: fabric-1.8.9 - Draft release

on:
push:
# Sequence of patterns matched against refs/tags
tags: 'v*-1.16' # Push events to matching v*-1.16
tags: 'v*-1.8.9' # Push events to matching v*-1.8.9

jobs:
build:
Expand Down
6 changes: 3 additions & 3 deletions .github/workflows/gradle.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
# This workflow will build a Java project with Gradle
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-gradle

name: fabric-1.16 - Snapshot
name: fabric-1.8.9 - Snapshot

on:
push:
branches: fabric-1.16
branches: fabric-1.8.9
pull_request:
branches: fabric-1.16
branches: fabric-1.8.9

jobs:
build:
Expand Down
32 changes: 31 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,41 @@ archivesBaseName = project.archives_base_name
version = project.mod_version + "-" + project.minecraft_version
group = project.maven_group

repositories {
mavenCentral()
jcenter()
maven {
name = 'Fabric'
url = 'http://maven.fabricmc.net/'
}
maven {
name = 'SpongePowered'
url = 'http://repo.spongepowered.org/maven'
}
maven {
name = 'mojang'
url = 'https://libraries.minecraft.net/'
}
maven {
name = 'legacy-fabric'
url = 'https://dl.bintray.com/legacy-fabric/Legacy-Fabric-Maven'
}
}

minecraft {
intermediaryUrl = {
return "https://dl.bintray.com/legacy-fabric/Legacy-Fabric-Maven/net/fabricmc/intermediary/" + it + "/intermediary-" + it + "-v2.jar";
}
}

dependencies {
//to change the versions see the gradle.properties file
implementation "com.google.guava:guava:23.5-jre"
minecraft "com.mojang:minecraft:${project.minecraft_version}"
mappings "net.fabricmc:yarn:${project.yarn_mappings}:v2"
modImplementation "net.fabricmc:fabric-loader:${project.loader_version}"
modImplementation ("net.fabricmc:fabric-loader-1.8.9:${project.loader_version}") {
exclude module: "guava"
}
}

import groovy.json.JsonSlurper
Expand Down
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
# Done to increase the memory available to gradle.
org.gradle.jvmargs=-Xmx1G
org.gradle.jvmargs=-Xmx2G

# Fabric Properties
# check these on https://fabricmc.net/use
minecraft_version=1.16
yarn_mappings=1.16+build.4
loader_version=0.7.4+build.177
minecraft_version = 1.8.9
yarn_mappings = 1.8.9+build.202011050955
loader_version = 0.9.3+build.202009100647

# Mod Properties
mod_version = 1.0.1
Expand Down
53 changes: 44 additions & 9 deletions src/main/java/com/github/NeRdTheNed/Punch2Prime/TntBlockMixin.java
Original file line number Diff line number Diff line change
@@ -1,25 +1,60 @@
package com.github.NeRdTheNed.Punch2Prime;

import org.apache.logging.log4j.LogManager;
import org.spongepowered.asm.mixin.Mixin;
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.ModifyArg;

import net.minecraft.block.Block;
import net.minecraft.block.BlockState;
import net.minecraft.block.Blocks;
import net.minecraft.block.TntBlock;
import net.minecraft.block.entity.BlockEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.stat.Stats;
import net.minecraft.util.math.BlockPos;
import net.minecraft.world.World;

@Mixin(TntBlock.class)
public abstract class TntBlockMixin extends Block {

// Dummy constructor, I'm not sure if this is how it's supposed to be done or if I'm bad at Mixins.
public TntBlockMixin(Settings settings) {
super(settings);
public TntBlockMixin() {
super(null);
}

@Inject(method = "<init>", at = @At("TAIL"))
private void init(CallbackInfo a) {
setDefaultState(getDefaultState().with(TntBlock.UNSTABLE, true));
LogManager.getLogger("Punch 2 Prime").info("Newly placed TNT will now be punchable!");
// Fabric hacks :/ Overrides used to fix the vanilla bug of a TNT item dropping when the TNT is activated by punching it.
// I've attempted to retain "compatibility" with other mods by checking if the block is specifically a TNT block, so any other blocks extending the TNT block shouldn't be affected.
@Override
public void harvest(World world, PlayerEntity player, BlockPos pos, BlockState state, BlockEntity be) {
if (!state.getBlock().isEqualTo(Blocks.TNT)) {
super.harvest(world, player, pos, state, be);
return;
}

player.incrementStat(Stats.BLOCK_STATS[getIdByBlock(this)]);
player.addExhaustion(0.025F);
}

/**
* Doesn't work, no clue why :(
*
* <pre>
* {@literal @}Inject(method = "<init>", at {@literal @}At("TAIL"))
* private void init(CallbackInfo a) {
* setDefaultState(stateManager.getDefaultState().with(TntBlock.EXPLODE, true));
* LogManager.getLogger("Punch 2 Prime").info("Newly placed TNT will now be punchable!");
* }
* </pre>
*/

// Hack to make the TNT block always explode when punched, as setting it as the default state doesn't work.
// I've attempted to retain "compatibility" with other mods by checking if the block is specifically a TNT block, so any other blocks extending the TNT block shouldn't be affected.
@ModifyArg(method = "onBreakByPlayer(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;)V", at = @At(value = "INVOKE", target = "Lnet/minecraft/block/TntBlock;method_1034(Lnet/minecraft/world/World;Lnet/minecraft/util/math/BlockPos;Lnet/minecraft/block/BlockState;Lnet/minecraft/entity/LivingEntity;)V"))
private BlockState method_1034(BlockState state) {
if (state.getBlock().isEqualTo(Blocks.TNT)) {
return state.with(TntBlock.EXPLODE, true);
}

return state;
}
}

0 comments on commit a67018f

Please sign in to comment.