Skip to content

Commit

Permalink
添加粽子
Browse files Browse the repository at this point in the history
  • Loading branch information
Gu-ZT committed Jun 7, 2024
1 parent cef1ca9 commit c1d4750
Show file tree
Hide file tree
Showing 20 changed files with 114 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,17 @@

import dev.dubhe.chinesefestivals.festivals.IFestival;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Vector;

public class Feature implements IFeature {
private final String id;
protected final List<IFestival> enableTimes;

public Feature(String id, IFestival... enableTimes) {
this.id = id;
this.enableTimes = new Vector<>(List.of(enableTimes));
this.enableTimes = Collections.synchronizedList(new ArrayList<>(List.of(enableTimes)));
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,21 @@
import dev.dubhe.chinesefestivals.features.impl.*;
import dev.dubhe.chinesefestivals.festivals.IFestival;

import java.util.ArrayList;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Vector;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.BiFunction;
import java.util.function.Supplier;

public class Features {
public static final Gson GSON = new GsonBuilder()
.setPrettyPrinting()
.registerTypeAdapter(IFeature.class, new FeatureParser())
.registerTypeAdapter(IFestival.class, new FeatureParser.FestivalParser())
.create();
public static final Map<String, BiFunction<String, IFestival[], IFeature>> FEATURE_GENERATORS = new ConcurrentHashMap<>();
.setPrettyPrinting()
.registerTypeAdapter(IFeature.class, new FeatureParser())
.registerTypeAdapter(IFestival.class, new FeatureParser.FestivalParser())
.create();
public static final Map<String, BiFunction<String, IFestival[], IFeature>> FEATURE_GENERATORS = Collections.synchronizedMap(new HashMap<>());
public static final Supplier<IFeature> COUPLETS = new FeatureGetter("couplets", Couplets::new);
public static final Supplier<IFeature> JIAO_ZI = new FeatureGetter("jiao_zi", JiaoZi::new);
public static final Supplier<IFeature> FIREWORKS = new FeatureGetter("fireworks", Fireworks::new);
Expand All @@ -32,7 +33,8 @@ public class Features {
public static final Supplier<IFeature> TANG_YUAN = new FeatureGetter("tang_yuan", TangYuan::new);
public static final Supplier<IFeature> QING_TUAN = new FeatureGetter("qing_tuan", QingTuan::new);
public static final Supplier<IFeature> THREE_D_FOOD = new FeatureGetter("3d_food", ThreeDFood::new);
public static final List<Supplier<IFeature>> FEATURES = new Vector<>() {{
public static final Supplier<IFeature> ZONG_ZI = new FeatureGetter("zong_zi", ZongZi::new);
public static final List<Supplier<IFeature>> FEATURES = Collections.synchronizedList(new ArrayList<>() {{
add(COUPLETS);
add(JIAO_ZI);
add(FIREWORKS);
Expand All @@ -45,7 +47,8 @@ public class Features {
add(TANG_YUAN);
add(QING_TUAN);
add(THREE_D_FOOD);
}};
add(ZONG_ZI);
}});

public static void refresh() {
for (Supplier<IFeature> feature : FEATURES) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,10 @@
import dev.dubhe.chinesefestivals.festivals.IFestival;
import dev.dubhe.chinesefestivals.util.BitMap;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Supplier;

public class Fireworks extends Feature {
Expand All @@ -27,7 +28,7 @@ public double[][] getFireworkParticle() {

@Override
public Map<String, Supplier<String>> getTranslationReplace() {
Map<String, Supplier<String>> map = new ConcurrentHashMap<>();
Map<String, Supplier<String>> map = Collections.synchronizedMap(new HashMap<>());
map.put("item.minecraft.firework_star.shape.creeper", () -> "item.firework_star.shape.dragon");
return map;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
import net.minecraft.world.item.Item;
import net.minecraft.world.item.Items;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Supplier;

public class FlowerCake extends Feature {
Expand All @@ -26,14 +27,14 @@ public FlowerCake(String id, IFestival... enableTimes) {

@Override
public Map<Item, Supplier<Item>> getItemReplace() {
Map<Item, Supplier<Item>> map = new ConcurrentHashMap<>();
Map<Item, Supplier<Item>> map = Collections.synchronizedMap(new HashMap<>());
map.put(Items.COOKIE, FLOWER_CAKE);
return map;
}

@Override
public Map<String, Supplier<String>> getTranslationReplace() {
Map<String, Supplier<String>> map = new ConcurrentHashMap<>();
Map<String, Supplier<String>> map = Collections.synchronizedMap(new HashMap<>());
map.put("item.minecraft.cookie", () -> "item.chinesefestivals.flower_cake");
return map;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
import net.minecraft.world.level.block.CampfireBlock;
import net.minecraft.world.level.block.state.BlockState;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Supplier;

public class Hotpots extends Feature {
Expand Down Expand Up @@ -47,15 +48,15 @@ public ModelResourceLocation getBlockReplace(BlockState blockState) {

@Override
public Map<Item, Supplier<Item>> getItemReplace() {
Map<Item, Supplier<Item>> map = new ConcurrentHashMap<>();
Map<Item, Supplier<Item>> map = Collections.synchronizedMap(new HashMap<>());
map.put(Items.CAMPFIRE, HOTPOT_S_ITEM);
map.put(Items.SOUL_CAMPFIRE, HOTPOT_N_ITEM);
return map;
}

@Override
public Map<String, Supplier<String>> getTranslationReplace() {
Map<String, Supplier<String>> map = new ConcurrentHashMap<>();
Map<String, Supplier<String>> map = Collections.synchronizedMap(new HashMap<>());
map.put("item.minecraft.campfire", () -> "item.chinesefestivals.hotpot_s");
map.put("item.minecraft.soul_campfire", () -> "item.chinesefestivals.hotpot_n");
map.put("item.minecraft.rabbit_stew", () -> "item.chinesefestivals.dumplings");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
import net.minecraft.world.item.Item;
import net.minecraft.world.item.Items;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Supplier;

public class JiaoZi extends Feature {
Expand All @@ -26,14 +27,14 @@ public JiaoZi(String id, IFestival... enableTimes) {

@Override
public Map<Item, Supplier<Item>> getItemReplace() {
Map<Item, Supplier<Item>> map = new ConcurrentHashMap<>();
Map<Item, Supplier<Item>> map = Collections.synchronizedMap(new HashMap<>());
map.put(Items.RABBIT_STEW, DUMPLINGS);
return map;
}

@Override
public Map<String, Supplier<String>> getTranslationReplace() {
Map<String, Supplier<String>> map = new ConcurrentHashMap<>();
Map<String, Supplier<String>> map = Collections.synchronizedMap(new HashMap<>());
map.put("item.minecraft.rabbit_stew", () -> "item.chinesefestivals.jiao_zi");
return map;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
import net.minecraft.world.item.Item;
import net.minecraft.world.item.Items;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Supplier;

public class LabaCongee extends Feature {
Expand All @@ -26,14 +27,14 @@ public LabaCongee(String id, IFestival... enableTimes) {

@Override
public Map<Item, Supplier<Item>> getItemReplace() {
Map<Item, Supplier<Item>> map = new ConcurrentHashMap<>();
Map<Item, Supplier<Item>> map = Collections.synchronizedMap(new HashMap<>());
map.put(Items.MUSHROOM_STEW, LABA_CONGEE);
return map;
}

@Override
public Map<String, Supplier<String>> getTranslationReplace() {
Map<String, Supplier<String>> map = new ConcurrentHashMap<>();
Map<String, Supplier<String>> map = Collections.synchronizedMap(new HashMap<>());
map.put("item.minecraft.mushroom_stew", () -> "item.chinesefestivals.laba_congee");
return map;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@
import net.minecraft.world.level.block.Blocks;
import net.minecraft.world.level.block.CakeBlock;
import net.minecraft.world.level.block.state.BlockState;
import org.jetbrains.annotations.NotNull;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Supplier;

public class Mooncakes extends Feature {
Expand All @@ -29,7 +31,7 @@ public class Mooncakes extends Feature {
public static final ModelResourceLocation MOONCAKES_5 = IFeature.registerBlockModel(new BlockModelData("mooncakes_slice5"));
public static final ModelResourceLocation MOONCAKES_6 = IFeature.registerBlockModel(new BlockModelData("mooncakes_slice6"));

public Mooncakes(String id, IFestival... enableTimes) {
public Mooncakes(String id, IFestival @NotNull ... enableTimes) {
super(id, Festivals.MOON_FESTIVAL);
if (enableTimes.length > 0) {
super.enableTimes.clear();
Expand All @@ -39,14 +41,14 @@ public Mooncakes(String id, IFestival... enableTimes) {

@Override
public Map<Item, Supplier<Item>> getItemReplace() {
Map<Item, Supplier<Item>> map = new ConcurrentHashMap<>();
Map<Item, Supplier<Item>> map = Collections.synchronizedMap(new HashMap<>());
map.put(Items.CAKE, MOONCAKES_ITEM);
map.put(Items.PUMPKIN_PIE, MOONCAKE_ITEM);
return map;
}

@Override
public ModelResourceLocation getBlockReplace(BlockState blockState) {
public ModelResourceLocation getBlockReplace(@NotNull BlockState blockState) {
if (blockState.is(Blocks.CAKE)) {
return switch (blockState.getValue(CakeBlock.BITES)) {
case 1 -> MOONCAKES_1;
Expand All @@ -63,7 +65,7 @@ public ModelResourceLocation getBlockReplace(BlockState blockState) {

@Override
public Map<String, Supplier<String>> getTranslationReplace() {
Map<String, Supplier<String>> map = new ConcurrentHashMap<>();
Map<String, Supplier<String>> map = Collections.synchronizedMap(new HashMap<>());
map.put("block.minecraft.cake", () -> "block.chinesefestivals.mooncakes");
map.put("item.minecraft.pumpkin_pie", () -> "item.chinesefestivals.mooncake");
return map;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,10 @@
import net.minecraft.world.item.Items;
import org.jetbrains.annotations.NotNull;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Supplier;

public class QingTuan extends Feature {
Expand All @@ -27,14 +28,14 @@ public QingTuan(String id, IFestival @NotNull ... enableTimes) {

@Override
public Map<Item, Supplier<Item>> getItemReplace() {
Map<Item, Supplier<Item>> map = new ConcurrentHashMap<>();
Map<Item, Supplier<Item>> map = Collections.synchronizedMap(new HashMap<>());
map.put(Items.BAKED_POTATO, QING_TUAN);
return map;
}

@Override
public Map<String, Supplier<String>> getTranslationReplace() {
Map<String, Supplier<String>> map = new ConcurrentHashMap<>();
Map<String, Supplier<String>> map = Collections.synchronizedMap(new HashMap<>());
map.put("item.minecraft.baked_potato", () -> "item.chinesefestivals.qing_tuan");
return map;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
import net.minecraft.world.item.Item;
import net.minecraft.world.item.Items;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Supplier;

public class TangYuan extends Feature {
Expand All @@ -27,14 +28,14 @@ public TangYuan(String id, IFestival ... enableTimes) {

@Override
public Map<Item, Supplier<Item>> getItemReplace() {
Map<Item, Supplier<Item>> map = new ConcurrentHashMap<>();
Map<Item, Supplier<Item>> map = Collections.synchronizedMap(new HashMap<>());
map.put(Items.BEETROOT_SOUP, SWEET_DUMPLINGS);
return map;
}

@Override
public Map<String, Supplier<String>> getTranslationReplace() {
Map<String, Supplier<String>> map = new ConcurrentHashMap<>();
Map<String, Supplier<String>> map = Collections.synchronizedMap(new HashMap<>());
map.put("item.minecraft.beetroot_soup", () -> "item.chinesefestivals.tang_yuan");
return map;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,10 @@
import net.minecraft.world.item.Items;
import org.jetbrains.annotations.NotNull;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
import java.util.function.Supplier;

public class ThreeDFood extends Feature {
Expand All @@ -32,7 +33,7 @@ public ThreeDFood(String id, IFestival @NotNull ... enableTimes) {

@Override
public Map<Item, Supplier<Item>> get3DFoodReplace() {
Map<Item, Supplier<Item>> map = new ConcurrentHashMap<>();
Map<Item, Supplier<Item>> map = Collections.synchronizedMap(new HashMap<>());
map.put(Items.APPLE, APPLE_3D);
map.put(Items.COOKIE, COOKIE_3D);
return map;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package dev.dubhe.chinesefestivals.features.impl;

import dev.dubhe.chinesefestivals.features.Feature;
import dev.dubhe.chinesefestivals.features.IFeature;
import dev.dubhe.chinesefestivals.festivals.Festivals;
import dev.dubhe.chinesefestivals.festivals.IFestival;
import net.minecraft.world.food.Foods;
import net.minecraft.world.item.Item;
import net.minecraft.world.item.Items;
import org.jetbrains.annotations.NotNull;

import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.function.Supplier;

public class ZongZi extends Feature {
public static final Supplier<Item> ZONG_ZI = IFeature.createItem("zong_zi", new Item.Properties().food(Foods.PUFFERFISH), Item::new);

public ZongZi(String id, IFestival @NotNull ... enableTimes) {
super(id, Festivals.DRAGON_BOAT_FESTIVAL);
if (enableTimes.length > 0) {
super.enableTimes.clear();
super.enableTimes.addAll(List.of(enableTimes));
}
}

@Override
public Map<Item, Supplier<Item>> getItemReplace() {
return new HashMap<>() {{
this.put(Items.PUMPKIN_PIE, ZongZi.ZONG_ZI);
}};
}

@Override
public Map<String, Supplier<String>> getTranslationReplace() {
Map<String, Supplier<String>> map = Collections.synchronizedMap(new HashMap<>());
map.put("item.minecraft.pumpkin_pie", () -> "item.chinesefestivals.zong_zi");
return map;
}
}
Loading

0 comments on commit c1d4750

Please sign in to comment.