-
Notifications
You must be signed in to change notification settings - Fork 93
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added BlockBuilder#copyPropertiesFrom(block)
- Loading branch information
1 parent
53d56c1
commit f6bb63a
Showing
2 changed files
with
42 additions
and
7 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
23 changes: 22 additions & 1 deletion
23
src/main/java/dev/latvian/mods/kubejs/block/KubeJSBlockProperties.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,12 +1,33 @@ | ||
package dev.latvian.mods.kubejs.block; | ||
|
||
import net.minecraft.world.level.block.Block; | ||
import net.minecraft.world.level.block.state.BlockBehaviour; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.lang.reflect.Modifier; | ||
|
||
public class KubeJSBlockProperties extends BlockBehaviour.Properties { | ||
public final BlockBuilder blockBuilder; | ||
|
||
public KubeJSBlockProperties(BlockBuilder blockBuilder) { | ||
public KubeJSBlockProperties(BlockBuilder blockBuilder, @Nullable Block copyPropertiesFrom) { | ||
super(); | ||
this.blockBuilder = blockBuilder; | ||
|
||
if (copyPropertiesFrom != null) { | ||
// incredibly cursed but alternative is ATing every field | ||
|
||
try { | ||
var from = copyPropertiesFrom.properties(); | ||
|
||
for (var field : BlockBehaviour.Properties.class.getDeclaredFields()) { | ||
if (!Modifier.isStatic(field.getModifiers()) && !Modifier.isFinal(field.getModifiers())) { | ||
field.setAccessible(true); | ||
field.set(this, field.get(from)); | ||
} | ||
} | ||
} catch (Exception ex) { | ||
ex.printStackTrace(); | ||
} | ||
} | ||
} | ||
} |