Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions gradle.properties
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ org.gradle.parallel=true

# Fabric Properties
# check these on https://fabricmc.net/develop
minecraft_version=1.21.8
yarn_mappings=1.21.8+build.1
minecraft_version=1.21.9
yarn_mappings=1.21.9+build.1
loader_version=0.17.2
loom_version=1.11-SNAPSHOT

# Mod Properties
mod_version=0.1.6+1.21.8
mod_version=0.1.6+1.21.9
maven_group=com.partatoes.littleguys
archives_base_name=little-guys

# Dependencies
fabric_version=0.131.0+1.21.8
fabric_version=0.133.14+1.21.9
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.partatoes.littleguys.block;

import com.partatoes.littleguys.LittleGuys;
import com.partatoes.littleguys.entity.custom.LittleGuyEntity;
import com.partatoes.littleguys.item.ModItems;
import com.partatoes.littleguys.item.custom.LittleGuySpawnEggItem;
import net.minecraft.block.DispenserBlock;
Expand All @@ -10,8 +11,6 @@
import net.minecraft.item.Item;
import net.minecraft.item.ItemStack;
import net.minecraft.item.SpawnEggItem;
import net.minecraft.registry.Registries;
import net.minecraft.registry.RegistryWrapper;
import net.minecraft.util.math.BlockPointer;
import net.minecraft.util.math.Direction;
import net.minecraft.world.event.GameEvent;
Expand All @@ -21,9 +20,20 @@ public class ModDispenserBehavior {
@Override
public ItemStack dispenseSilently(BlockPointer pointer, ItemStack stack) {
Direction direction = pointer.state().get(DispenserBlock.FACING);
EntityType<?> entityType = ((SpawnEggItem)stack.getItem()).getEntityType(pointer.world().getRegistryManager(), stack);
EntityType<?> entityType = ((SpawnEggItem)stack.getItem()).getEntityType(stack);
try {
entityType.spawnFromItemStack(pointer.world(), stack, null, pointer.pos().offset(direction), SpawnReason.DISPENSER, direction != Direction.UP, false);
if (entityType != null) {
var entity = entityType.spawnFromItemStack(pointer.world(), stack, null, pointer.pos().offset(direction), SpawnReason.DISPENSER, direction != Direction.UP, false);
if (entity != null) {
if (entity instanceof LittleGuyEntity littleGuyEntity) {
if (stack.getItem() instanceof LittleGuySpawnEggItem eggItem) {
littleGuyEntity.setColor(eggItem.color);
littleGuyEntity.setIsNeutral(false);
}
}
}
}

} catch (Exception exception) {
LittleGuys.LOGGER.error("Error while dispensing spawn egg from dispenser at {} {}", (Object)pointer.pos(), (Object)exception);
return ItemStack.EMPTY;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,7 @@ public boolean isNeutral() {
return this.dataTracker.get(IS_NEUTRAL);
}

private void setIsNeutral(Boolean isNeutral) {
public void setIsNeutral(Boolean isNeutral) {
this.dataTracker.set(IS_NEUTRAL, isNeutral);
}

Expand All @@ -101,7 +101,7 @@ public void onDeath(DamageSource damageSource) {
drop = ModItems.LITTLEGUY_COLORS.getOrDefault(this.getColor(), ModItems.LITTLEGUY_ITEM);
}

World w = this.getWorld();
World w = this.getEntityWorld();
if (w instanceof ServerWorld serverWorld) {
this.dropItem(serverWorld, drop);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ public BoardLittleHorseGoal(LittleGuyEntity entity) {

@Override
public boolean canStart() {
List<LittleHorseEntity> littleHorsesList = this.mob.getWorld().getNonSpectatingEntities(LittleHorseEntity.class, this.mob.getBoundingBox().expand(5.0));
List<LittleHorseEntity> littleHorsesList = this.mob.getEntityWorld().getNonSpectatingEntities(LittleHorseEntity.class, this.mob.getBoundingBox().expand(5.0));
boolean ret = false;
for (LittleHorseEntity horse : littleHorsesList) {
Entity entity = horse.getControllingPassenger();
Expand All @@ -29,11 +29,6 @@ public boolean canStart() {
return ret && !this.mob.hasVehicle();
}

@Override
public boolean canStop() {
return true;
}

@Override
public void stop() {
this.target = null;
Expand Down
22 changes: 10 additions & 12 deletions src/main/java/com/partatoes/littleguys/item/ModItems.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,12 @@

import com.google.common.collect.BiMap;
import com.google.common.collect.HashBiMap;
import com.google.common.collect.Maps;
import com.partatoes.littleguys.LittleGuys;
import com.partatoes.littleguys.entity.ModEntities;
import com.partatoes.littleguys.entity.custom.LittleGuyEntity;
import com.partatoes.littleguys.item.custom.LittleGuySpawnEggItem;
import net.fabricmc.fabric.api.itemgroup.v1.FabricItemGroupEntries;
import net.fabricmc.fabric.api.itemgroup.v1.ItemGroupEvents;
import net.minecraft.component.DataComponentTypes;
import net.minecraft.component.type.DyedColorComponent;
import net.minecraft.entity.EntityType;
import net.minecraft.item.Item;
import net.minecraft.item.ItemGroups;
import net.minecraft.item.SpawnEggItem;
Expand All @@ -22,9 +19,6 @@
import net.minecraft.util.Identifier;
import org.jetbrains.annotations.NotNull;

import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.stream.Collectors;
import java.util.stream.Stream;

Expand All @@ -33,22 +27,22 @@ public class ModItems {
public static final Identifier LITTLEGUY_ITEM_ID = Identifier.of(LittleGuys.MOD_ID, "littleguy_item");
public static final Item LITTLEGUY_ITEM = registerItem(
LITTLEGUY_ITEM_ID,
new SpawnEggItem(ModEntities.LITTLEGUY_ENTITY,
createItemSettings(LITTLEGUY_ITEM_ID)));
new SpawnEggItem(
createSpawnEggItemSettings(LITTLEGUY_ITEM_ID, ModEntities.LITTLEGUY_ENTITY)));

public static final Identifier LITTLEHORSE_ITEM_ID = Identifier.of(LittleGuys.MOD_ID, "littlehorse_item");
public static final Item LITTLEHORSE_ITEM = registerItem(
LITTLEHORSE_ITEM_ID,
new SpawnEggItem(ModEntities.LITTLEHORSE_ENTITY,
createItemSettings(LITTLEHORSE_ITEM_ID)));
new SpawnEggItem(
createSpawnEggItemSettings(LITTLEHORSE_ITEM_ID, ModEntities.LITTLEHORSE_ENTITY)));

public static final Identifier SOULSAND_PILE_ID = Identifier.of(LittleGuys.MOD_ID, "soulsand_pile");
public static final Item SOULSAND_PILE_ITEM = registerItem(SOULSAND_PILE_ID, new Item(createItemSettings(SOULSAND_PILE_ID)));

public static final BiMap<DyeColor, Item> LITTLEGUY_COLORS = Stream.of(DyeColor.values())
.collect(Collectors.toMap(
(color) -> color,
(color) -> registerItem(createLittleGuyColorId((DyeColor) color), new LittleGuySpawnEggItem(ModEntities.COLOR_LITTLEGUY_BIMAP.get(color), color, createItemSettings(createLittleGuyColorId(color)))),
(color) -> registerItem(createLittleGuyColorId(color), new LittleGuySpawnEggItem(color, createSpawnEggItemSettings(createLittleGuyColorId(color), ModEntities.LITTLEGUY_ENTITY))),
(a, b) -> a,
HashBiMap::create));

Expand All @@ -69,6 +63,10 @@ private static Item.Settings createItemSettings(Identifier id) {
return new Item.Settings().registryKey(RegistryKey.of(RegistryKeys.ITEM, id));
}

private static Item.Settings createSpawnEggItemSettings(Identifier id, EntityType<?> et) {
return new Item.Settings().registryKey(RegistryKey.of(RegistryKeys.ITEM, id)).spawnEgg(et);
}

private static void addItemsToIngredientTabItemGroup(FabricItemGroupEntries entries) {
entries.add(SOULSAND_PILE_ITEM);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
import net.minecraft.block.entity.Spawner;
import net.minecraft.entity.EntityType;
import net.minecraft.entity.SpawnReason;
import net.minecraft.entity.mob.MobEntity;
import net.minecraft.entity.player.PlayerEntity;
import net.minecraft.item.ItemStack;
import net.minecraft.item.ItemUsageContext;
Expand All @@ -29,9 +28,9 @@
import java.util.Objects;

public class LittleGuySpawnEggItem extends SpawnEggItem {
private final DyeColor color;
public LittleGuySpawnEggItem(EntityType<? extends MobEntity> type, DyeColor color, Settings settings) {
super(type, settings);
public final DyeColor color;
public LittleGuySpawnEggItem(DyeColor color, Settings settings) {
super(settings);
this.color = color;
}

Expand All @@ -49,18 +48,21 @@ public ActionResult useOnBlock(ItemUsageContext context) {
BlockEntity blockEntity = world.getBlockEntity(blockPos);
if (blockEntity instanceof Spawner) {
Spawner spawner = (Spawner)(blockEntity);
entityType = this.getEntityType(world.getRegistryManager(),itemStack);
entityType = this.getEntityType(itemStack);
spawner.setEntityType(entityType, world.getRandom());
world.updateListeners(blockPos, blockState, blockState, Block.NOTIFY_ALL);
world.emitGameEvent(context.getPlayer(), GameEvent.BLOCK_CHANGE, blockPos);
itemStack.decrement(1);
return ActionResult.CONSUME;
}
BlockPos blockPos2 = blockState.getCollisionShape(world, blockPos).isEmpty() ? blockPos : blockPos.offset(direction);
entityType = this.getEntityType(world.getRegistryManager(), itemStack);
if (entityType.spawnFromItemStack((ServerWorld)world, itemStack, context.getPlayer(), blockPos2, SpawnReason.SPAWN_ITEM_USE, true, !Objects.equals(blockPos, blockPos2) && direction == Direction.UP) != null) {
entityType = this.getEntityType(itemStack);
LittleGuyEntity entity = (LittleGuyEntity) entityType.spawnFromItemStack((ServerWorld) world, itemStack, context.getPlayer(), blockPos2, SpawnReason.SPAWN_ITEM_USE, true, !Objects.equals(blockPos, blockPos2) && direction == Direction.UP);
if (entity != null) {
itemStack.decrement(1);
world.emitGameEvent(context.getPlayer(), GameEvent.ENTITY_PLACE, blockPos);
entity.setColor(this.color);
entity.setIsNeutral(false);
}
return ActionResult.CONSUME;
}
Expand All @@ -82,7 +84,7 @@ public ActionResult use(World world, PlayerEntity user, Hand hand) {
if (world.canEntityModifyAt(user, blockPos) && user.canPlaceOn(blockPos, blockHitResult.getSide(), itemStack)) {
return ActionResult.FAIL;
}
EntityType<?> entityType = this.getEntityType(world.getRegistryManager(), itemStack);
EntityType<?> entityType = this.getEntityType(itemStack);
LittleGuyEntity entity = (LittleGuyEntity) entityType.spawnFromItemStack((ServerWorld)world, itemStack, user, blockPos, SpawnReason.SPAWN_ITEM_USE, false, false);

if (entity == null) {
Expand All @@ -92,7 +94,7 @@ public ActionResult use(World world, PlayerEntity user, Hand hand) {
}
itemStack.decrementUnlessCreative(1, user);
user.incrementStat(Stats.USED.getOrCreateStat(this));
world.emitGameEvent(user, GameEvent.ENTITY_PLACE, (entity).getPos());
world.emitGameEvent(user, GameEvent.ENTITY_PLACE, (entity).getEntityPos());
return ActionResult.CONSUME;
}
}