-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactored entity package and created new CameraTargetEntity
- Loading branch information
Showing
13 changed files
with
228 additions
and
152 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
62 changes: 62 additions & 0 deletions
62
src/main/java/io/fabricatedatelier/mayor/entity/custom/CameraTargetEntity.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 |
---|---|---|
@@ -0,0 +1,62 @@ | ||
package io.fabricatedatelier.mayor.entity.custom; | ||
|
||
import io.fabricatedatelier.mayor.init.Entities; | ||
import io.fabricatedatelier.mayor.util.NbtKeys; | ||
import net.minecraft.entity.Entity; | ||
import net.minecraft.entity.EntityType; | ||
import net.minecraft.entity.data.DataTracker; | ||
import net.minecraft.entity.data.TrackedData; | ||
import net.minecraft.entity.data.TrackedDataHandlerRegistry; | ||
import net.minecraft.nbt.NbtCompound; | ||
import net.minecraft.server.network.ServerPlayerEntity; | ||
import net.minecraft.world.World; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.Optional; | ||
import java.util.UUID; | ||
|
||
public class CameraTargetEntity extends Entity { | ||
private static final TrackedData<Optional<UUID>> USER = DataTracker.registerData(CameraTargetEntity.class, TrackedDataHandlerRegistry.OPTIONAL_UUID); | ||
|
||
public CameraTargetEntity(EntityType<?> type, World world) { | ||
super(type, world); | ||
} | ||
|
||
public CameraTargetEntity(World world, @Nullable ServerPlayerEntity player) { | ||
this(Entities.CAMERA_TARGET, world); | ||
if (player == null) { | ||
setUser(null); | ||
} else { | ||
setUser(player.getUuid()); | ||
} | ||
} | ||
|
||
public Optional<UUID> getUser() { | ||
return this.dataTracker.get(USER); | ||
} | ||
|
||
public void setUser(@Nullable UUID user) { | ||
this.dataTracker.set(USER, Optional.ofNullable(user)); | ||
} | ||
|
||
@Override | ||
protected void initDataTracker(DataTracker.Builder builder) { | ||
builder.add(USER, Optional.empty()); | ||
} | ||
|
||
@Override | ||
protected void readCustomDataFromNbt(NbtCompound nbt) { | ||
if (nbt.contains(NbtKeys.USER_UUID)) { | ||
setUser(nbt.getUuid(NbtKeys.USER_UUID)); | ||
} else { | ||
setUser(null); | ||
} | ||
} | ||
|
||
@Override | ||
protected void writeCustomDataToNbt(NbtCompound nbt) { | ||
getUser().ifPresentOrElse(userUUID -> { | ||
nbt.putUuid(NbtKeys.USER_UUID, userUUID); | ||
}, () -> nbt.remove(NbtKeys.USER_UUID)); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...datelier/mayor/entity/access/Builder.java → ...mayor/entity/villager/access/Builder.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
4 changes: 2 additions & 2 deletions
4
...r/mayor/entity/task/BuilderBuildTask.java → ...ntity/villager/task/BuilderBuildTask.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
4 changes: 2 additions & 2 deletions
4
...mayor/entity/task/BuilderCollectTask.java → ...ity/villager/task/BuilderCollectTask.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
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
2 changes: 1 addition & 1 deletion
2
...er/mayor/entity/task/BuilderWorkTask.java → ...entity/villager/task/BuilderWorkTask.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
150 changes: 12 additions & 138 deletions
150
src/main/java/io/fabricatedatelier/mayor/init/Entities.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,154 +1,28 @@ | ||
package io.fabricatedatelier.mayor.init; | ||
|
||
import com.google.common.collect.ImmutableSet; | ||
import com.mojang.datafixers.util.Pair; | ||
import io.fabricatedatelier.mayor.Mayor; | ||
import net.fabricmc.fabric.api.event.player.UseEntityCallback; | ||
import net.fabricmc.fabric.api.event.player.UseItemCallback; | ||
import net.fabricmc.fabric.api.object.builder.v1.trade.TradeOfferHelper; | ||
import net.fabricmc.fabric.api.object.builder.v1.world.poi.PointOfInterestHelper; | ||
import net.fabricmc.fabric.mixin.content.registry.VillagerEntityAccessor; | ||
import net.minecraft.block.Block; | ||
import net.minecraft.client.render.entity.feature.VillagerClothingFeatureRenderer; | ||
import io.fabricatedatelier.mayor.entity.custom.CameraTargetEntity; | ||
import net.minecraft.entity.Entity; | ||
import net.minecraft.entity.ai.brain.Activity; | ||
import net.minecraft.entity.ai.brain.task.FindPointOfInterestTask; | ||
import net.minecraft.entity.passive.VillagerEntity; | ||
import net.minecraft.entity.player.PlayerEntity; | ||
import net.minecraft.item.Item; | ||
import net.minecraft.item.ItemStack; | ||
import net.minecraft.item.Items; | ||
import net.minecraft.entity.EntityType; | ||
import net.minecraft.entity.SpawnGroup; | ||
import net.minecraft.registry.Registries; | ||
import net.minecraft.registry.Registry; | ||
import net.minecraft.registry.RegistryKey; | ||
import net.minecraft.registry.RegistryKeys; | ||
import net.minecraft.registry.entry.RegistryEntry; | ||
import net.minecraft.server.world.ServerWorld; | ||
import net.minecraft.sound.SoundEvent; | ||
import net.minecraft.sound.SoundEvents; | ||
import net.minecraft.util.ActionResult; | ||
import net.minecraft.util.Hand; | ||
import net.minecraft.util.Identifier; | ||
import net.minecraft.util.TypedActionResult; | ||
import net.minecraft.util.hit.EntityHitResult; | ||
import net.minecraft.util.math.BlockPos; | ||
import net.minecraft.util.math.random.Random; | ||
import net.minecraft.village.*; | ||
import net.minecraft.world.World; | ||
import net.minecraft.world.poi.PointOfInterestStorage; | ||
import net.minecraft.world.poi.PointOfInterestType; | ||
import net.minecraft.world.poi.PointOfInterestTypes; | ||
import org.jetbrains.annotations.Nullable; | ||
|
||
import java.util.Iterator; | ||
import java.util.Set; | ||
import java.util.function.Predicate; | ||
import java.util.stream.Collectors; | ||
|
||
public class Entities { | ||
public static final EntityType<CameraTargetEntity> CAMERA_TARGET = register("camera_target", | ||
EntityType.Builder.<CameraTargetEntity>create(CameraTargetEntity::new, SpawnGroup.MISC) | ||
.dimensions(0.5f, 0.5f) | ||
.spawnableFarFromPlayer() | ||
.makeFireImmune() | ||
.disableSummon() | ||
.build()); | ||
|
||
public static final RegistryKey<PointOfInterestType> BUILDER_POI_KEY = RegistryKey.of(RegistryKeys.POINT_OF_INTEREST_TYPE, Mayor.identifierOf("builder")); | ||
|
||
public static final PointOfInterestType BUILDER_POI = PointOfInterestHelper.register(Mayor.identifierOf("builder"), 1, 1, Blocks.CAMERA_DEBUG); | ||
|
||
public static final VillagerProfession BUILDER = register("builder", entry -> entry.value().equals(BUILDER_POI), entry -> entry.value().equals(BUILDER_POI), ImmutableSet.of(), ImmutableSet.of(), SoundEvents.ENTITY_VILLAGER_WORK_MASON); | ||
|
||
private static VillagerProfession register(String id, Predicate<RegistryEntry<PointOfInterestType>> heldWorkstation, Predicate<RegistryEntry<PointOfInterestType>> acquirableWorkstation, ImmutableSet<Item> gatherableItems, ImmutableSet<Block> secondaryJobSites, @Nullable SoundEvent workSound) { | ||
return Registry.register(Registries.VILLAGER_PROFESSION, Mayor.identifierOf(id), new VillagerProfession(id, heldWorkstation, acquirableWorkstation, gatherableItems, secondaryJobSites, workSound)); | ||
private static <E extends Entity, T extends EntityType<E>> T register(String name, T entityType) { | ||
return Registry.register(Registries.ENTITY_TYPE, Mayor.identifierOf(name), entityType); | ||
} | ||
|
||
public static final Activity BUILDING = Registry.register(Registries.ACTIVITY, Mayor.identifierOf("building"), new Activity("building")); | ||
|
||
// VillagerClothingFeatureRenderer | ||
// public static final RegistryKey<PointOfInterestType> BUILDER_POI_KEY = RegistryKey.of(RegistryKeys.POINT_OF_INTEREST_TYPE, Identifier.ofVanilla("builder")); | ||
// | ||
// public static final PointOfInterestType BUILDER_POI = PointOfInterestHelper.register( Identifier.ofVanilla("builder"), 1, 1, Blocks.CAMERA_DEBUG); | ||
// | ||
// public static final VillagerProfession BUILDER = register("builder", entry -> entry.value().equals(BUILDER_POI), entry -> entry.value().equals(BUILDER_POI), ImmutableSet.of(), ImmutableSet.of(), SoundEvents.ENTITY_VILLAGER_WORK_MASON); | ||
// | ||
// private static VillagerProfession register(String id, Predicate<RegistryEntry<PointOfInterestType>> heldWorkstation, Predicate<RegistryEntry<PointOfInterestType>> acquirableWorkstation, ImmutableSet<Item> gatherableItems, ImmutableSet<Block> secondaryJobSites, @Nullable SoundEvent workSound) { | ||
// return Registry.register(Registries.VILLAGER_PROFESSION, Identifier.ofVanilla(id), new VillagerProfession(id, heldWorkstation, acquirableWorkstation, gatherableItems, secondaryJobSites, workSound)); | ||
// } | ||
|
||
|
||
public static void initialize() { | ||
// static initialisation | ||
|
||
// Iterator<VillagerProfession> iterator = Registries.VILLAGER_PROFESSION.stream().iterator(); | ||
// while (iterator.hasNext()) { | ||
// VillagerProfession villagerProfession = iterator.next(); | ||
//// System.out.println(villagerProfession.acquirableWorkstation().test(Registries.POINT_OF_INTEREST_TYPE.getEntry(BUILDER_POI))+ " : "+villagerProfession.id()); | ||
// } | ||
|
||
TradeOfferHelper.registerVillagerOffers(BUILDER, 1, factories -> { | ||
factories.add(new SimpleTradeFactory(new TradeOffer(new TradedItem(net.minecraft.item.Items.DIAMOND, 5), new ItemStack(Items.GLOW_ITEM_FRAME), 3, 4, 0.15F))); | ||
factories.add(new SimpleTradeFactory(new TradeOffer(new TradedItem(Items.SADDLE, 5), new ItemStack(Items.DANDELION), 3, 4, 0.15F))); | ||
}); | ||
TradeOfferHelper.registerVillagerOffers(BUILDER, 2, factories -> { | ||
factories.add(new SimpleTradeFactory(new TradeOffer(new TradedItem(net.minecraft.item.Items.DIAMOND, 5), new ItemStack(Items.GLOW_ITEM_FRAME), 3, 4, 0.15F))); | ||
factories.add(new SimpleTradeFactory(new TradeOffer(new TradedItem(Items.SADDLE, 5), new ItemStack(Items.DANDELION), 3, 4, 0.15F))); | ||
}); | ||
// public PointOfInterestStorage getPointOfInterestStorage() { | ||
// return this.getChunkManager().getPointOfInterestStorage(); | ||
// } | ||
|
||
// FindPointOfInterestTask | ||
// System.out.println(Registries.VILLAGER_PROFESSION.getId(BUILDER)); | ||
|
||
// UseEntityCallback.EVENT.register((player, world, hand, entity, hitResult) -> { | ||
// if(entity instanceof VillagerEntity villagerEntity){ | ||
// System.out.println(villagerEntity.getVillagerData().getProfession()); | ||
// if(!world.isClient()){ | ||
// villagerEntity.setVillagerData(new VillagerData(villagerEntity.getVillagerData().getType(),BUILDER,2)); | ||
// | ||
// System.out.println(villagerEntity.getVillagerData().getProfession()); | ||
// } | ||
// } | ||
// return ActionResult.PASS; | ||
// }); | ||
// | ||
// UseItemCallback.EVENT.register((player, world, hand) -> { | ||
// if (world instanceof ServerWorld serverWorld) { | ||
// System.out.println(serverWorld.getPointOfInterestStorage() + " : " + PointOfInterestTypes.isPointOfInterest(player.getSteppingBlockState()) + " : " + player.getSteppingBlockState()); | ||
// | ||
//// Set<Pair<RegistryEntry<PointOfInterestType>, BlockPos>> set = (Set<Pair<RegistryEntry<PointOfInterestType>, BlockPos>>)serverWorld.getPointOfInterestStorage().getSortedTypesAndPositions( | ||
//// poiPredicate, predicate2, player.getBlockPos(), 48, PointOfInterestStorage.OccupationStatus.HAS_SPACE | ||
//// ) | ||
//// .limit(5L) | ||
//// .collect(Collectors.toSet()); | ||
// } | ||
// return TypedActionResult.pass(player.getMainHandStack()); | ||
// }); | ||
|
||
|
||
// TradeOfferHelper. | ||
|
||
// VillagerEntity.POINTS_OF_INTEREST.forEach((a,b)->{ | ||
// System.out.println(b); | ||
// }); | ||
// VillagerEntityAccessor.fabric_setGatherableItems(); | ||
// System.out.println(VillagerEntity.POINTS_OF_INTEREST); | ||
|
||
// Iterator<PointOfInterestType> iterator = Registries.POINT_OF_INTEREST_TYPE.stream().iterator(); | ||
// while (iterator.hasNext()) { | ||
//// System.out.println(iterator.next()); | ||
// } | ||
|
||
// System.out.println(PointOfInterestTypes.isPointOfInterest(Blocks.CAMERA_DEBUG.getDefaultState())+ " : "+PointOfInterestTypes.getTypeForState(Blocks.CAMERA_DEBUG.getDefaultState())); | ||
} | ||
|
||
private static class SimpleTradeFactory implements TradeOffers.Factory { | ||
private final TradeOffer offer; | ||
|
||
SimpleTradeFactory(TradeOffer offer) { | ||
this.offer = offer; | ||
} | ||
|
||
@Override | ||
public TradeOffer create(Entity entity, Random random) { | ||
// ALWAYS supply a copy of the offer. | ||
return this.offer.copy(); | ||
} | ||
} | ||
|
||
} |
Oops, something went wrong.