Skip to content

Commit

Permalink
Merge pull request #134 from CafeteriaGuild/1.20
Browse files Browse the repository at this point in the history
1.20
  • Loading branch information
Luligabi1 authored Aug 10, 2023
2 parents 6068902 + e60063a commit 9a7d805
Show file tree
Hide file tree
Showing 112 changed files with 1,101 additions and 602 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,4 @@ public void setDmlRefInReiScreen(boolean flag) {
dmlRefIsInREIScreen = flag;
}


@Inject(at = @At(value = "INVOKE", target = "Lnet/minecraft/entity/LivingEntity;playEquipSound(Lnet/minecraft/item/ItemStack;)V"), method = "onEquipStack", cancellable = true)
public void onEquip(EquipmentSlot slot, ItemStack oldStack, ItemStack newStack, CallbackInfo ci) {
if (isDmlRefIsInReiScreen()) {
ci.cancel();
}
}

}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package dev.nathanpb.dml.mixin;

/*
* Copyright (C) 2020 Nathan P. Bombana, IterationFunk
*
Expand All @@ -17,25 +19,16 @@
* along with Deep Mob Learning: Refabricated. If not, see <https://www.gnu.org/licenses/>.
*/

package dev.nathanpb.dml.entity

import com.mojang.authlib.GameProfile
import dev.nathanpb.dml.MOD_ID
import net.minecraft.network.encryption.PlayerPublicKey
import net.minecraft.server.network.ServerPlayerEntity
import net.minecraft.server.world.ServerWorld
import java.util.*
import it.unimi.dsi.fastutil.objects.ObjectArrayList;
import net.minecraft.item.ItemStack;
import net.minecraft.loot.LootTable;
import net.minecraft.loot.context.LootContext;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Invoker;

class FakePlayerEntity(world: ServerWorld, publicKey: PlayerPublicKey?) : ServerPlayerEntity(
world.server,
world,
GameProfile(UUID, "${MOD_ID}_fake_player"),
publicKey
) {
companion object {
val UUID: UUID = java.util.UUID.randomUUID()
}
@Mixin(LootTable.class)
public interface LootTableInvoker {

override fun isSpectator() = true
override fun isCreative() = true
@Invoker("generateLoot")
ObjectArrayList<ItemStack> invokeGenerateLoot(LootContext context);
}
Original file line number Diff line number Diff line change
Expand Up @@ -51,18 +51,18 @@ public void explode(
double z,
float power,
boolean createFire,
Explosion.DestructionType destructionType,
World.ExplosionSourceType explosionSource,
CallbackInfoReturnable<Explosion> ci
) {
if (power > 0F) {
World world = (World) (Object) this;
BlockPos pos = new BlockPos(Math.floor(x), Math.floor(y), Math.floor(z));
BlockPos pos = new BlockPos((int) Math.floor(x), (int) Math.floor(y), (int) Math.floor(z));
ActionResult result = VanillaEvents.INSTANCE.getWorldExplosionEvent()
.invoker()
.invoke(world, entity, damageSource, behavior, pos, power, createFire, destructionType);
.invoke(world, entity, damageSource, behavior, pos, power, createFire, explosionSource);

if (result == ActionResult.FAIL) {
Explosion explosion = new Explosion(world, entity, damageSource, behavior, x, y, z, power, createFire, Explosion.DestructionType.NONE);
Explosion explosion = new Explosion(world, entity, damageSource, behavior, x, y, z, power, createFire, Explosion.DestructionType.KEEP);
ci.setReturnValue(explosion);
ci.cancel();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package dev.nathanpb.dml.mixin;

import net.minecraft.item.ItemStack;
import net.minecraft.recipe.ShapelessRecipe;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Accessor;

@Mixin(ShapelessRecipe.class)
public interface ShapelessRecipeAccessor {

@Final
@Accessor("output")
ItemStack getOutput();

}
2 changes: 1 addition & 1 deletion base/src/main/java/dev/nathanpb/dml/mixin/SlotMixin.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ public void onTake(int amount, CallbackInfoReturnable<ItemStack> ci) {

if ((Object) this instanceof CraftingResultSlot dis) {
PlayerEntity player = ((ICraftingResultSlotMixin)dis).dmlRefGetPlayer();
if (!player.world.isClient) {
if (!player.getWorld().isClient) {
TrialKeyData oldData = TrialKeyDataKt.getTrialKeyData(stack);
if (oldData != null && oldData.getAffixes().isEmpty()) {
TrialKeyData newData = new TrialKeyData(stack);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package dev.nathanpb.dml.mixin;

import net.minecraft.item.SmithingTemplateItem;
import net.minecraft.util.Identifier;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.gen.Invoker;

import java.util.List;

@Mixin(SmithingTemplateItem.class)
public interface SmithingTemplateItemAccessor {

@Invoker("getArmorTrimEmptyBaseSlotTextures")
static List<Identifier> dml_getArmorTrimEmptyBaseSlotTextures() {
throw new AssertionError();
}

@Invoker("getNetheriteUpgradeEmptyAdditionsSlotTextures")
static List<Identifier> dml_getNetheriteUpgradeEmptyAdditionsSlotTextures() {
throw new AssertionError();
}
}
9 changes: 9 additions & 0 deletions base/src/main/kotlin/dev/nathanpb/dml/DeepMobLearning.kt
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,9 @@ import dev.nathanpb.dml.command.DMLCommand
import dev.nathanpb.dml.entity.registerEntityRenderer
import dev.nathanpb.dml.entity.registerEntityTypes
import dev.nathanpb.dml.event.VanillaEvents
import dev.nathanpb.dml.item.ITEM_DML
import dev.nathanpb.dml.item.registerItems
import dev.nathanpb.dml.itemgroup.registerItemGroup
import dev.nathanpb.dml.listener.CrushingRecipeListener
import dev.nathanpb.dml.listener.DataCollectListener
import dev.nathanpb.dml.recipe.registerRecipeSerializers
Expand All @@ -40,7 +42,13 @@ import net.fabricmc.fabric.api.command.v2.CommandRegistrationCallback
import net.fabricmc.fabric.api.entity.event.v1.ServerEntityCombatEvents
import net.fabricmc.fabric.api.event.player.AttackBlockCallback
import net.fabricmc.fabric.api.event.player.UseBlockCallback
import net.fabricmc.fabric.api.itemgroup.v1.FabricItemGroup
import net.fabricmc.loader.api.FabricLoader
import net.minecraft.item.ItemGroup
import net.minecraft.item.ItemStack
import net.minecraft.registry.Registries
import net.minecraft.registry.Registry
import net.minecraft.text.Text
import net.minecraft.util.Identifier
import org.slf4j.LoggerFactory
import java.io.File
Expand Down Expand Up @@ -86,6 +94,7 @@ val config: ModConfig by lazy {
fun init() {
registerItems()
registerBlocks()
registerItemGroup()
registerBlockEntityTypes()
registerRecipeSerializers()
registerRecipeTypes()
Expand Down
7 changes: 7 additions & 0 deletions base/src/main/kotlin/dev/nathanpb/dml/ModConfig.kt
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ class Trial {

var trialKeyConsume = true
var trialKeyReturnIfSucceed = true


var faultyGlitchUpgradeOdds = .0
var basicGlitchUpgradeOdds = .0
var advancedGlitchUpgradeOdds = .15
var superiorGlitchUpgradeOdds = .65
var selfAwareGlitchUpgradeOdds = 1.0
}

class TrialAffix {
Expand Down
15 changes: 12 additions & 3 deletions base/src/main/kotlin/dev/nathanpb/dml/block/BlockCafeteria.kt
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,11 @@ import net.minecraft.world.BlockView
import net.minecraft.world.World

class BlockCafeteria : HorizontalFacingBlock(
FabricBlockSettings.of(Material.STONE)
FabricBlockSettings.create()
.hardness(1F)
.resistance(.5F)
.nonOpaque()
.mapColor(MapColor.YELLOW)
) {
init {
defaultState = stateManager.defaultState.with(Properties.HORIZONTAL_FACING, Direction.NORTH)
Expand All @@ -63,8 +64,16 @@ class BlockCafeteria : HorizontalFacingBlock(
builder?.add(Properties.HORIZONTAL_FACING)
}

override fun getPlacementState(ctx: ItemPlacementContext?): BlockState? {
return defaultState.with(FACING, ctx?.playerFacing?.opposite)
override fun getPlacementState(ctx: ItemPlacementContext): BlockState {
var blockState = defaultState

for(direction in ctx.placementDirections) {
if(direction.axis.isHorizontal) {
blockState = blockState.with(FACING, direction.opposite)
if(blockState.canPlaceAt(ctx.world, ctx.blockPos)) return blockState
}
}
return blockState.with(FACING, Direction.NORTH)
}


Expand Down
14 changes: 11 additions & 3 deletions base/src/main/kotlin/dev/nathanpb/dml/block/BlockLootFabricator.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ import net.minecraft.world.World
import net.minecraft.world.WorldAccess

class BlockLootFabricator : HorizontalFacingBlock (
FabricBlockSettings.of(Material.STONE)
FabricBlockSettings.create()
.hardness(4F)
.resistance(3000F)
), InventoryProvider, BlockEntityProvider {
Expand Down Expand Up @@ -83,8 +83,16 @@ class BlockLootFabricator : HorizontalFacingBlock (
builder?.add(Properties.HORIZONTAL_FACING)
}

override fun getPlacementState(ctx: ItemPlacementContext?): BlockState? {
return defaultState.with(FACING, ctx?.playerFacing?.opposite)
override fun getPlacementState(ctx: ItemPlacementContext): BlockState {
var blockState = defaultState

for(direction in ctx.placementDirections) {
if(direction.axis.isHorizontal) {
blockState = blockState.with(FACING, direction.opposite)
if(blockState.canPlaceAt(ctx.world, ctx.blockPos)) return blockState
}
}
return blockState.with(FACING, Direction.NORTH)
}

override fun createBlockEntity(pos: BlockPos, state: BlockState): BlockEntity = BlockEntityLootFabricator(pos, state)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ import net.minecraft.world.BlockView
import net.minecraft.world.World

class BlockTrialKeystone : Block(
FabricBlockSettings.of(Material.STONE)
FabricBlockSettings.create()
.hardness(4F)
.resistance(3000F)
), BlockEntityProvider {
Expand Down
49 changes: 39 additions & 10 deletions base/src/main/kotlin/dev/nathanpb/dml/block/Blocks.kt
Original file line number Diff line number Diff line change
Expand Up @@ -20,23 +20,52 @@
package dev.nathanpb.dml.block

import dev.nathanpb.dml.identifier
import dev.nathanpb.dml.item.settings
import dev.nathanpb.dml.item.ITEM_GLITCH_INGOT
import dev.nathanpb.dml.item.ITEM_PHYSICALLY_CONDENSED_MATRIX_FRAGMENT
import dev.nathanpb.dml.item.ITEM_PRISTINE_MATTER_OVERWORLD
import dev.nathanpb.dml.item.ITEM_TRIAL_KEY
import dev.nathanpb.dml.itemgroup.ITEMS
import dev.nathanpb.dml.itemgroup.ITEM_GROUP_KEY
import dev.nathanpb.dml.utils.RarityTuple
import net.fabricmc.fabric.api.item.v1.FabricItemSettings
import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents
import net.fabricmc.fabric.api.`object`.builder.v1.block.FabricBlockSettings
import net.minecraft.block.AbstractBlock
import net.minecraft.block.Blocks
import net.minecraft.block.SkullBlock
import net.minecraft.block.WallSkullBlock
import net.minecraft.block.enums.Instrument
import net.minecraft.block.piston.PistonBehavior
import net.minecraft.item.BlockItem
import net.minecraft.item.ItemStack
import net.minecraft.registry.Registries
import net.minecraft.registry.Registry
import net.minecraft.util.Rarity
import net.minecraft.util.registry.Registry

val BLOCK_TRIAL_KEYSTONE = BlockTrialKeystone()
val BLOCK_LOOT_FABRICATOR = BlockLootFabricator()
/*val SYSTEM_GLITCH_HEAD = SkullBlock(SkullBlock.Type.CREEPER, FabricBlockSettings.create().instrument(Instrument.CREEPER).strength(1.0f).pistonBehavior(PistonBehavior.DESTROY))
val SYSTEM_GLITCH_WALL_HEAD = WallSkullBlock(SkullBlock.Type.CREEPER, FabricBlockSettings.create().strength(1.0f).dropsLike(SYSTEM_GLITCH_HEAD).pistonBehavior(PistonBehavior.DESTROY))*/
val BLOCK_CAFETERIA = BlockCafeteria()

fun registerBlocks() {
hashMapOf(
BLOCK_TRIAL_KEYSTONE to "trial_keystone",
BLOCK_LOOT_FABRICATOR to "loot_fabricator",
BLOCK_CAFETERIA to "cafeteria"
).forEach { (block, id) ->
val identifier = identifier(id)
Registry.register(Registry.BLOCK, identifier, block)
Registry.register(Registry.ITEM, identifier, BlockItem(block, settings().rarity(if(block == BLOCK_CAFETERIA) Rarity.EPIC else Rarity.UNCOMMON))) // This is a bad way to do it, but it's fine for now
linkedMapOf(
BLOCK_TRIAL_KEYSTONE to RarityTuple("trial_keystone", Rarity.UNCOMMON),
BLOCK_LOOT_FABRICATOR to RarityTuple("loot_fabricator", Rarity.UNCOMMON),
/*SYSTEM_GLITCH_HEAD to RarityTuple("system_glitch_head", Rarity.EPIC),
SYSTEM_GLITCH_WALL_HEAD to RarityTuple("system_glitch_wall_head", Rarity.EPIC),*/
BLOCK_CAFETERIA to RarityTuple("cafeteria", Rarity.EPIC)
).forEach { (block, tuple) ->
val identifier = identifier(tuple.identifier)
Registry.register(Registries.BLOCK, identifier, block)
Registry.register(Registries.ITEM, identifier, BlockItem(block, FabricItemSettings().rarity(tuple.rarity)))
}


ITEMS.add(0, ItemStack(BLOCK_CAFETERIA))

ItemGroupEvents.modifyEntriesEvent(ITEM_GROUP_KEY).register {
it.addAfter(ItemStack(ITEM_TRIAL_KEY), BLOCK_TRIAL_KEYSTONE)
it.addBefore(ItemStack(ITEM_PRISTINE_MATTER_OVERWORLD), BLOCK_LOOT_FABRICATOR)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ package dev.nathanpb.dml.blockEntity

import dev.nathanpb.dml.MOD_ID
import dev.nathanpb.dml.config
import dev.nathanpb.dml.entity.FakePlayerEntity
import dev.nathanpb.dml.enums.EntityCategory
import dev.nathanpb.dml.inventory.LootFabricatorInventory
import dev.nathanpb.dml.recipe.RECIPE_LOOT_FABRICATOR
Expand All @@ -30,24 +29,24 @@ import dev.nathanpb.dml.utils.items
import dev.nathanpb.dml.utils.setStacks
import dev.nathanpb.dml.utils.simulateLootDroppedStacks
import io.github.cottonmc.cotton.gui.PropertyDelegateHolder
import net.fabricmc.fabric.api.entity.FakePlayer
import net.minecraft.block.BlockState
import net.minecraft.block.InventoryProvider
import net.minecraft.block.entity.BlockEntity
import net.minecraft.block.entity.BlockEntityTicker
import net.minecraft.entity.damage.DamageSource
import net.minecraft.entity.damage.DamageSources
import net.minecraft.inventory.Inventories
import net.minecraft.inventory.SidedInventory
import net.minecraft.inventory.SimpleInventory
import net.minecraft.item.ItemStack
import net.minecraft.nbt.NbtCompound
import net.minecraft.recipe.RecipeInputProvider
import net.minecraft.recipe.RecipeMatcher
import net.minecraft.registry.Registries
import net.minecraft.screen.ArrayPropertyDelegate
import net.minecraft.server.world.ServerWorld
import net.minecraft.util.collection.DefaultedList
import net.minecraft.util.math.BlockPos
import net.minecraft.util.registry.Registry
import net.minecraft.world.WorldAccess
import net.minecraft.util.math.BlockPos import net.minecraft.world.WorldAccess

class BlockEntityLootFabricator(pos: BlockPos, state: BlockState) :
BlockEntity(BLOCKENTITY_LOOT_FABRICATOR, pos, state),
Expand Down Expand Up @@ -111,10 +110,10 @@ class BlockEntityLootFabricator(pos: BlockPos, state: BlockState) :
}

private fun generateLoot(world: ServerWorld, category: EntityCategory): List<ItemStack> {
val entityList = Registry.ENTITY_TYPE.iterateEntries(category.tagKey).filter{true}
val entityList = Registries.ENTITY_TYPE.iterateEntries(category.tagKey).filter{true}
return (0 until category.exchangeRatio).map {
entityList.random().value()
.simulateLootDroppedStacks(world, FakePlayerEntity(world, null), DamageSource.GENERIC)
.simulateLootDroppedStacks(world, FakePlayer.get(world), world.damageSources.generic())
}.flatten().let { stacks ->
SimpleInventory(stacks.size).also { tempInventory ->
stacks.forEach { tempInventory.addStack(it) }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,16 @@ import net.minecraft.block.Block
import net.minecraft.block.BlockState
import net.minecraft.block.entity.BlockEntity
import net.minecraft.block.entity.BlockEntityType
import net.minecraft.registry.Registries
import net.minecraft.registry.Registry
import net.minecraft.util.math.BlockPos
import net.minecraft.util.registry.Registry

lateinit var BLOCKENTITY_TRIAL_KEYSTONE: BlockEntityType<BlockEntityTrialKeystone>
lateinit var BLOCKENTITY_LOOT_FABRICATOR: BlockEntityType<BlockEntityLootFabricator>

private fun <E: BlockEntity, B: Block>register(block: B, builder: (BlockPos, BlockState)->E) = Registry.register(
Registry.BLOCK_ENTITY_TYPE,
Registry.BLOCK.getId(block),
Registries.BLOCK_ENTITY_TYPE,
Registries.BLOCK.getId(block),
BlockEntityType.Builder.create(builder, block).build(null)
)

Expand Down
Loading

0 comments on commit 9a7d805

Please sign in to comment.