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

Commit 3a15151

Browse files
authored
Merge pull request #64 from PatchworkMC/feature/iforgeblock
Skeleton implementation of IForgeBlock and IForgeBlockState
2 parents d5eb46a + 62e5330 commit 3a15151

File tree

12 files changed

+2168
-0
lines changed

12 files changed

+2168
-0
lines changed
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: 1070 additions & 0 deletions
Large diffs are not rendered by default.

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

Lines changed: 845 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
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.Accessor;
24+
25+
import net.minecraft.tag.BlockTags;
26+
27+
@Mixin(BlockTags.class)
28+
public interface BlockTagsAccessor {
29+
@Accessor
30+
static int getLatestVersion() {
31+
throw new UnsupportedOperationException();
32+
}
33+
}
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: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
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 javax.annotation.Nullable;
23+
24+
import org.spongepowered.asm.mixin.Mixin;
25+
import net.minecraftforge.common.extensions.IForgeBlock;
26+
27+
import net.minecraft.block.BedBlock;
28+
import net.minecraft.block.BlockState;
29+
import net.minecraft.entity.Entity;
30+
import net.minecraft.util.math.BlockPos;
31+
import net.minecraft.world.BlockView;
32+
33+
@Mixin(BedBlock.class)
34+
public abstract class MixinBedBlock implements IForgeBlock {
35+
@Override
36+
public boolean isBed(BlockState state, BlockView world, BlockPos pos, @Nullable Entity player) {
37+
return true;
38+
}
39+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
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+
47+
@Unique
48+
private Set<Identifier> cachedTags;
49+
@Unique
50+
private int tagVersion;
51+
52+
@Override
53+
public float getSlipperiness(BlockState state, CollisionView world, BlockPos pos, Entity entity) {
54+
return slipperiness;
55+
}
56+
57+
@Override
58+
public int getHarvestLevel(BlockState state) {
59+
throw new UnsupportedOperationException("Harvest levels not yet implemented"); // TODO implement getHarvestLevel, really sucks for vanilla blocks so i'm putting it off
60+
}
61+
62+
@Override
63+
public Set<Identifier> getTags() {
64+
if (cachedTags == null || tagVersion != BlockTagsAccessor.getLatestVersion()) {
65+
this.cachedTags = new HashSet<>();
66+
67+
for (final Map.Entry<Identifier, Tag<Block>> entry : BlockTags.getContainer().getEntries().entrySet()) {
68+
if (entry.getValue().contains((Block) (Object) this)) {
69+
cachedTags.add(entry.getKey());
70+
}
71+
}
72+
73+
this.tagVersion = BlockTagsAccessor.getLatestVersion();
74+
}
75+
76+
return this.cachedTags;
77+
}
78+
}
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+
}

0 commit comments

Comments
 (0)