Skip to content
This repository was archived by the owner on Jun 3, 2024. It is now read-only.

Commit 9d6542c

Browse files
NuclearfartsNuclearfarts
authored andcommitted
patchwork-extensions-block created. listed calls in IForgeBlock
1 parent 91ced1f commit 9d6542c

11 files changed

Lines changed: 2105 additions & 0 deletions

File tree

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
archivesBaseName = "patchwork-extensions-block"
2+
version = getSubprojectVersion(project, "0.1.0")

patchwork-extensions-block/src/main/java/net/minecraftforge/common/extensions/IForgeBlock.java

Lines changed: 1060 additions & 0 deletions
Large diffs are not rendered by default.

patchwork-extensions-block/src/main/java/net/minecraftforge/common/extensions/IForgeBlockState.java

Lines changed: 848 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package net.patchworkmc.mixin.extensions.block;
2+
3+
import org.spongepowered.asm.mixin.Mixin;
4+
import org.spongepowered.asm.mixin.gen.Accessor;
5+
6+
import net.minecraft.tag.BlockTags;
7+
8+
@Mixin(BlockTags.class)
9+
public interface BlockTagsAccessor {
10+
@Accessor
11+
static int getLatestVersion() {
12+
throw new UnsupportedOperationException();
13+
}
14+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Minecraft Forge, Patchwork Project
3+
* Copyright (c) 2016-2020, 2019-2020
4+
*
5+
* This library is free software; you can redistribute it and/or
6+
* modify it under the terms of the GNU Lesser General Public
7+
* License as published by the Free Software Foundation version 2.1
8+
* of the License.
9+
*
10+
* This library is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
* Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public
16+
* License along with this library; if not, write to the Free Software
17+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18+
*/
19+
20+
package net.patchworkmc.mixin.extensions.block;
21+
22+
import org.spongepowered.asm.mixin.Mixin;
23+
import org.spongepowered.asm.mixin.gen.Invoker;
24+
25+
import net.minecraft.block.BlockState;
26+
import net.minecraft.block.FireBlock;
27+
28+
@Mixin(FireBlock.class)
29+
public interface FireBlockAccessor {
30+
@Invoker
31+
int invokeGetBurnChance(BlockState state);
32+
@Invoker
33+
int invokeGetSpreadChance(BlockState state);
34+
}
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
/*
2+
* Minecraft Forge, Patchwork Project
3+
* Copyright (c) 2016-2020, 2019-2020
4+
*
5+
* This library is free software; you can redistribute it and/or
6+
* modify it under the terms of the GNU Lesser General Public
7+
* License as published by the Free Software Foundation version 2.1
8+
* of the License.
9+
*
10+
* This library is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
* Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public
16+
* License along with this library; if not, write to the Free Software
17+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18+
*/
19+
20+
package net.patchworkmc.mixin.extensions.block;
21+
22+
import java.util.HashSet;
23+
import java.util.Map;
24+
import java.util.Set;
25+
26+
import org.spongepowered.asm.mixin.Final;
27+
import org.spongepowered.asm.mixin.Mixin;
28+
import org.spongepowered.asm.mixin.Shadow;
29+
import org.spongepowered.asm.mixin.Unique;
30+
import net.minecraftforge.common.extensions.IForgeBlock;
31+
32+
import net.minecraft.block.Block;
33+
import net.minecraft.block.BlockState;
34+
import net.minecraft.entity.Entity;
35+
import net.minecraft.tag.BlockTags;
36+
import net.minecraft.tag.Tag;
37+
import net.minecraft.util.Identifier;
38+
import net.minecraft.util.math.BlockPos;
39+
import net.minecraft.world.CollisionView;
40+
41+
@Mixin(Block.class)
42+
public class MixinBlock implements IForgeBlock {
43+
@Shadow
44+
@Final
45+
private float slipperiness;
46+
@Shadow
47+
@Final
48+
private int harvestLevel;
49+
50+
@Unique
51+
private Set<Identifier> cachedTags;
52+
@Unique
53+
private int tagVersion;
54+
55+
@Override
56+
public float getSlipperiness(BlockState state, CollisionView world, BlockPos pos, Entity entity) {
57+
return slipperiness;
58+
}
59+
60+
@Override
61+
public int getHarvestLevel(BlockState state) {
62+
return -1; // TODO implement getHarvestLevel, really sucks for vanilla blocks so i'm putting it off
63+
}
64+
65+
@Override
66+
public Set<Identifier> getTags() {
67+
if (cachedTags == null || tagVersion != BlockTagsAccessor.getLatestVersion()) {
68+
this.cachedTags = new HashSet<>();
69+
70+
for (final Map.Entry<Identifier, Tag<Block>> entry : BlockTags.getContainer().getEntries().entrySet()) {
71+
if (entry.getValue().contains((Block) (Object) this)) {
72+
cachedTags.add(entry.getKey());
73+
}
74+
}
75+
76+
this.tagVersion = BlockTagsAccessor.getLatestVersion();
77+
}
78+
79+
return this.cachedTags;
80+
}
81+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
/*
2+
* Minecraft Forge, Patchwork Project
3+
* Copyright (c) 2016-2020, 2019-2020
4+
*
5+
* This library is free software; you can redistribute it and/or
6+
* modify it under the terms of the GNU Lesser General Public
7+
* License as published by the Free Software Foundation version 2.1
8+
* of the License.
9+
*
10+
* This library is distributed in the hope that it will be useful,
11+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
12+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13+
* Lesser General Public License for more details.
14+
*
15+
* You should have received a copy of the GNU Lesser General Public
16+
* License along with this library; if not, write to the Free Software
17+
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18+
*/
19+
20+
package net.patchworkmc.mixin.extensions.block;
21+
22+
import org.spongepowered.asm.mixin.Mixin;
23+
import net.minecraftforge.common.extensions.IForgeBlockState;
24+
25+
import net.minecraft.block.BlockState;
26+
27+
@Mixin(BlockState.class)
28+
public class MixinBlockState implements IForgeBlockState { }
22.2 KB
Loading
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{
2+
"schemaVersion": 1,
3+
"id": "patchwork-extensions-block",
4+
"version": "${version}",
5+
"icon": "assets/patchwork-enum-hacks/icon.png",
6+
"name": "Patchwork Extensions Block",
7+
"description": "Implementation of Forge's block extensions",
8+
"authors": [
9+
"PatchworkMC"
10+
],
11+
"license": "LGPL-2.1-only",
12+
"environment": "*",
13+
"depends": {
14+
"fabricloader": ">=0.4.0"
15+
},
16+
"mixins": [
17+
"patchwork-extensions-block.mixins.json"
18+
],
19+
"custom": {
20+
"modmenu:api": true,
21+
"modmenu:parent": "patchwork"
22+
}
23+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
{
2+
"required": true,
3+
"package": "net.patchworkmc.mixin.extensions.block",
4+
"compatibilityLevel": "JAVA_8",
5+
"mixins": [
6+
"MixinBlock",
7+
"MixinBlockState",
8+
"BlockTagsAccessor",
9+
"FireBlockAccessor"
10+
],
11+
"injectors": {
12+
"defaultRequire": 1
13+
}
14+
}

0 commit comments

Comments
 (0)